[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Add gettext headers
From: |
Bruno Haible |
Subject: |
Re: Add gettext headers |
Date: |
Fri, 14 Nov 2008 12:29:13 +0100 |
User-agent: |
KMail/1.5.4 |
[CCing bug-gnu-gettext, since this is the appropriate mailing list.]
Hi,
Claude Paroz wrote:
> In the GNOME Translation project (http://l10n.gnome.org), I'd like to
> add a supplemental header in generated po files, something like
> "X-DamnedLies-Source: http://l10n.gnome.org/POT/eog.HEAD/eog.HEAD.pot"
>
> This would simplify the update of the file (msgmerge) with a local
> script without requiring a complete source checkout for the translator.
>
> Is this possible with a gettext tool, or do we have to manipulate the po
> file programmatically ?
Not much is missing for 'msgfilter' to do it.
With gettext 0.17 you can do it like this:
$ cat > add-damnedlies-source <<\EOF
#!/bin/sh
cat; echo "X-DamnedLies-Source: $1"
EOF
$ chmod a+x add-damnedlies-source
$ cat > msgfilter-header-only <<\EOF
#!/bin/sh
# Usage: msgfilter-header-only xx.po filter argument...
cat "$1" > tmp0.po
shift
msgfilter --keep-header "$@" < tmp0.po > tmp1.po
msgfilter "$@" < tmp0.po > tmp2.po
diff -c3 tmp1.po tmp2.po > tmp3.diff
patch tmp0.po < tmp3.diff
cat tmp0.po
rm -f tmp0.po tmp1.po tmp2.po tmp3.diff tmp0.po.orig tmp0.po~
"tmp0.po${SIMPLE_BACKUP_SUFFIX}" tmp0.po.rej
EOF
$ chmod a+x msgfilter-header-only
$ ./msgfilter-header-only xx.po ./add-damnedlies-source
http://l10n.gnome.org/POT/eog.HEAD/eog.HEAD.pot
With gettext 0.18, where I'm adding the appended patch, you will be able
to do it like this:
$ cat > add-damnedlies-source <<\EOF
#!/bin/sh
if test -z "${MSGFILTER_MSGCTXT+set}${MSGFILTER_MSGID}"; then
# header entry
cat; echo "X-DamnedLies-Source: $1"
else
cat
fi
EOF
$ chmod a+x add-damnedlies-source
$ msgfilter ./add-damnedlies-source
http://l10n.gnome.org/POT/eog.HEAD/eog.HEAD.pot < xx.po
Bruno
2008-11-14 Bruno Haible <address@hidden>
* msgfilter.c: Include xvasprintf.h, xsetenv.h.
(process_message): Set the environment variables MSGFILTER_MSGCTXT,
MSGFILTER_MSGID, MSGFILTER_LOCATION.
* msgfilter.texi: Document the environment variables MSGFILTER_MSGCTXT,
MSGFILTER_MSGID, MSGFILTER_LOCATION.
*** msgfilter.c 10 Jun 2008 19:01:46 -0000 1.41
--- msgfilter.c 14 Nov 2008 11:05:48 -0000
***************
*** 43,48 ****
--- 43,49 ----
#include "closeout.h"
#include "dir-list.h"
#include "error.h"
+ #include "xvasprintf.h"
#include "error-progname.h"
#include "progname.h"
#include "relocatable.h"
***************
*** 61,66 ****
--- 62,68 ----
#include "findprog.h"
#include "pipe.h"
#include "wait-process.h"
+ #include "xsetenv.h"
#include "filters.h"
#include "msgl-iconv.h"
#include "po-charset.h"
***************
*** 758,763 ****
--- 760,766 ----
{
const char *msgstr = mp->msgstr;
size_t msgstr_len = mp->msgstr_len;
+ char *location;
size_t nsubstrings;
char **substrings;
size_t total_len;
***************
*** 770,775 ****
--- 773,789 ----
if (is_header (mp) && keep_header)
return;
+ /* Set environment variables for the subprocess. */
+ if (mp->msgctxt != NULL)
+ xsetenv ("MSGFILTER_MSGCTXT", mp->msgctxt, 1);
+ else
+ unsetenv ("MSGFILTER_MSGCTXT");
+ xsetenv ("MSGFILTER_MSGID", mp->msgid, 1);
+ location = xasprintf ("%s:%ld", mp->pos.file_name,
+ (long) mp->pos.line_number);
+ xsetenv ("MSGFILTER_LOCATION", location, 1);
+ free (location);
+
/* Count NUL delimited substrings. */
for (p = msgstr, nsubstrings = 0;
p < msgstr + msgstr_len;
*** msgfilter.texi 12 Jan 2008 23:03:27 -0000 1.8
--- msgfilter.texi 14 Nov 2008 11:07:41 -0000
***************
*** 8,13 ****
--- 8,23 ----
The @code{msgfilter} program applies a filter to all translations of a
translation catalog.
+ @vindex address@hidden, environment variable}
+ @vindex address@hidden, environment variable}
+ @vindex address@hidden, environment variable}
+ During each @var{filter} invocation, the environment variable
+ @code{MSGFILTER_MSGID} is bound to the message's msgid, and the environment
+ variable @code{MSGFILTER_LOCATION} is bound to the location in the PO file
+ of the message. If the message has a context, the environment variable
+ @code{MSGFILTER_MSGCTXT} is bound to the message's msgctxt, otherwise it is
+ unbound.
+
@subsection Input file location
@table @samp
- Re: Add gettext headers,
Bruno Haible <=