]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msgfilter now sets the environment variables MSGFILTER_MSGCTXT,
authorBruno Haible <bruno@clisp.org>
Fri, 14 Nov 2008 11:10:35 +0000 (11:10 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:55 +0000 (12:15 +0200)
MSGFILTER_MSGID, MSGFILTER_LOCATION.

NEWS
gettext-tools/doc/ChangeLog
gettext-tools/doc/msgfilter.texi
gettext-tools/src/ChangeLog
gettext-tools/src/msgfilter.c

diff --git a/NEWS b/NEWS
index c59131ba37c90d0e9c6dd07d226d82a8c76e861d..1847c2f90d274f6a4524745158a6f809c495d3bf 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,9 @@ Version 0.18 - January 2008
 * msgcmp has a new option -N/--no-fuzzy-matching, like msgmerge has since
   version 0.12.
 
+* msgfilter now sets environment variables during the invocation of the
+  filter, indicating the msgid and location of the messge being processed.
+
 * Updated the meaning of 'gcc-internal-format' to match GCC 4.3.
 \f
 Version 0.17 - November 2007
index 36a6d66ba2e5ef3108e0ef8b7ca5e612c86a99b2..311ac16ffaf9fc79fd3757b9ac93c7df48542674 100644 (file)
@@ -1,3 +1,8 @@
+2008-11-14  Bruno Haible  <bruno@clisp.org>
+
+       * msgfilter.texi: Document the environment variables MSGFILTER_MSGCTXT,
+       MSGFILTER_MSGID, MSGFILTER_LOCATION.
+
 2008-10-10  Noritada Kobayashi  <noritadak@gmail.com>
 
        * gettext.texi (PO Mode): Update remaining obsolete key bindings used
index 13ea7d54c632ff6055f5ae69424a3641a8744638..736373d6b87ab63db5b23976ab13aa7d65b54848 100644 (file)
@@ -8,6 +8,16 @@ msgfilter [@var{option}] @var{filter} [@var{filter-option}]
 The @code{msgfilter} program applies a filter to all translations of a
 translation catalog.
 
+@vindex MSGFILTER_MSGCTXT@r{, environment variable}
+@vindex MSGFILTER_MSGID@r{, environment variable}
+@vindex MSGFILTER_LOCATION@r{, 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
index 3ccaabd41b5bddc059badf636ec3e09fbe59416f..4ac3abc6d39a7573edae1d72625ab3a375aefd33 100644 (file)
@@ -1,3 +1,9 @@
+2008-11-14  Bruno Haible  <bruno@clisp.org>
+
+       * msgfilter.c: Include xvasprintf.h, xsetenv.h.
+       (process_message): Set the environment variables MSGFILTER_MSGCTXT,
+       MSGFILTER_MSGID, MSGFILTER_LOCATION.
+
 2008-10-28  Bruno Haible  <bruno@clisp.org>
 
        * msgmerge.c (match_domain): Remove space between '#' and 'pragma' for
index 1177361f80801a146c4018e2dd821f6e7eb8f087..66e5ffb66ac47e476dc7c337ff6d611d432954fd 100644 (file)
@@ -43,6 +43,7 @@
 #include "closeout.h"
 #include "dir-list.h"
 #include "error.h"
+#include "xvasprintf.h"
 #include "error-progname.h"
 #include "progname.h"
 #include "relocatable.h"
@@ -61,6 +62,7 @@
 #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,6 +760,7 @@ process_message (message_ty *mp)
 {
   const char *msgstr = mp->msgstr;
   size_t msgstr_len = mp->msgstr_len;
+  char *location;
   size_t nsubstrings;
   char **substrings;
   size_t total_len;
@@ -770,6 +773,17 @@ process_message (message_ty *mp)
   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;