]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msgexec: Implement plural support
authorStanislav Brabec <sbrabec@suse.cz>
Thu, 15 May 2014 03:00:01 +0000 (12:00 +0900)
committerDaiki Ueno <ueno@gnu.org>
Thu, 15 May 2014 05:46:32 +0000 (14:46 +0900)
* msgexec.c (process_string): Set or unset MSGEXEC_MSGID_PLURAL.
(process_message): Set or unset MSGEXEC_PLURAL_FORM.

gettext-tools/doc/ChangeLog
gettext-tools/doc/msgexec.texi
gettext-tools/src/ChangeLog
gettext-tools/src/msgexec.c

index 76d0071d9bcc5882d09777b5edc0744fce95442f..740b6f61f32e168231cea025c60e12d290067a63 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-15  Stanislav Brabec  <sbrabec@suse.cz>  (tiny change)
+
+       * msgexec.texi: Document the environment variable
+       MSGEXEC_MSGID_PLURAL and MSGEXEC_PLURAL_FORM.
+
 2014-05-10  Guido Flohr  <guido@imperia.net>
 
        msgattrib: Add --empty option to clear msgstr
index 7177a0bf38f5f18a7fe7096ab5858c1a89fcbce1..5ef640c866f3d101cb17931c3e9027ca1bf96a02 100644 (file)
@@ -19,13 +19,18 @@ by a null byte.  The output of @samp{msgexec 0} is suitable as input for
 
 @vindex MSGEXEC_MSGCTXT@r{, environment variable}
 @vindex MSGEXEC_MSGID@r{, environment variable}
+@vindex MSGEXEC_MSGID_PLURAL@r{, environment variable}
 @vindex MSGEXEC_LOCATION@r{, environment variable}
+@vindex MSGEXEC_PLURAL_FORM@r{, environment variable}
 During each @var{command} invocation, the environment variable
 @code{MSGEXEC_MSGID} is bound to the message's msgid, and the environment
 variable @code{MSGEXEC_LOCATION} is bound to the location in the PO file
 of the message.  If the message has a context, the environment variable
 @code{MSGEXEC_MSGCTXT} is bound to the message's msgctxt, otherwise it is
-unbound.
+unbound.  If the message has a plural form, environment variable
+@code{MSGEXEC_MSGID_PLURAL} is bound to the message's msgid_plural and
+@code{MSGEXEC_PLURAL_FORM} is bound to the order number of the plural
+actually processed (starting with 0), otherwise both are unbound.
 
 @cindex catalog encoding and @code{msgexec} output
 Note: It is your responsibility to ensure that the @var{command} can cope
index 039d764356102141beb1d85b3f03d5fa1f780e7f..bc262cb482e2f006f4645412ad46dbfdf4551426 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-15  Stanislav Brabec  <sbrabec@suse.cz>  (tiny change)
+
+       msgexec: Implement plural support
+       * msgexec.c (process_string): Set or unset MSGEXEC_MSGID_PLURAL.
+       (process_message): Set or unset MSGEXEC_PLURAL_FORM.
+
 2014-05-14  Daiki Ueno  <ueno@gnu.org>
 
        msgfmt: Report error on accelerator mismatch
index c46ca7f7221ab90ce97a7369ead6a9f55f0326e2..48563762ec9bac6593748f9de3cf906e1bde5fdd 100644 (file)
@@ -370,6 +370,10 @@ process_string (const message_ty *mp, const char *str, size_t len)
       else
         unsetenv ("MSGEXEC_MSGCTXT");
       xsetenv ("MSGEXEC_MSGID", mp->msgid, 1);
+      if (mp->msgid_plural != NULL)
+        xsetenv ("MSGEXEC_MSGID_PLURAL", mp->msgid_plural, 1);
+      else
+        unsetenv ("MSGEXEC_MSGID_PLURAL");
       location = xasprintf ("%s:%ld", mp->pos.file_name,
                             (long) mp->pos.line_number);
       xsetenv ("MSGEXEC_LOCATION", location, 1);
@@ -409,12 +413,22 @@ process_message (const message_ty *mp)
   const char *msgstr = mp->msgstr;
   size_t msgstr_len = mp->msgstr_len;
   const char *p;
+  size_t k;
 
   /* Process each NUL delimited substring separately.  */
-  for (p = msgstr; p < msgstr + msgstr_len; )
+  for (p = msgstr, k = 0; p < msgstr + msgstr_len; k++)
     {
       size_t length = strlen (p);
 
+      if (mp->msgid_plural != NULL)
+        {
+          char *plural_form_string = xasprintf ("%lu", k);
+
+          xsetenv ("MSGEXEC_PLURAL_FORM", plural_form_string, 1);
+          free (plural_form_string);
+        }
+      else
+        unsetenv ("MSGEXEC_PLURAL_FORM");
       process_string (mp, p, length);
 
       p += length + 1;