From: Stanislav Brabec Date: Thu, 15 May 2014 03:00:53 +0000 (+0900) Subject: msgfilter: Implement plural support X-Git-Tag: v0.19~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=448119dd0f9e736a964af7ca24a8992a551e1a65;p=thirdparty%2Fgettext.git msgfilter: Implement plural support * msgfilter.c (process_message): Set or unset MSGFILTER_MSGID_PLURAL and MSGFILTER_PLURAL_FORM. --- diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 740b6f61f..5f236dd91 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -1,3 +1,8 @@ +2014-05-15 Stanislav Brabec (tiny change) + + * msgfilter.texi: Document the environment variable + MSGFILTER_MSGID_PLURAL and MSGFILTER_PLURAL_FORM. + 2014-05-15 Stanislav Brabec (tiny change) * msgexec.texi: Document the environment variable diff --git a/gettext-tools/doc/msgfilter.texi b/gettext-tools/doc/msgfilter.texi index c26189e97..22fbab759 100644 --- a/gettext-tools/doc/msgfilter.texi +++ b/gettext-tools/doc/msgfilter.texi @@ -10,13 +10,18 @@ translation catalog. @vindex MSGFILTER_MSGCTXT@r{, environment variable} @vindex MSGFILTER_MSGID@r{, environment variable} +@vindex MSGFILTER_MSGID_PLURAL@r{, environment variable} @vindex MSGFILTER_LOCATION@r{, environment variable} +@vindex MSGFILTER_PLURAL_FORM@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. +unbound. If the message has a plural form, environment variable +@code{MSGFILTER_MSGID_PLURAL} is bound to the message's msgid_plural and +@code{MSGFILTER_PLURAL_FORM} is bound to the order number of the plural +actually processed (starting with 0), otherwise both are unbound. @subsection Input file location diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index bc262cb48..418599664 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,9 @@ +2014-05-15 Stanislav Brabec (tiny change) + + msgfilter: Implement plural support + * msgfilter.c (process_message): Set or unset + MSGFILTER_MSGID_PLURAL and MSGFILTER_PLURAL_FORM. + 2014-05-15 Stanislav Brabec (tiny change) msgexec: Implement plural support diff --git a/gettext-tools/src/msgfilter.c b/gettext-tools/src/msgfilter.c index bbfb05e1b..df6551f4a 100644 --- a/gettext-tools/src/msgfilter.c +++ b/gettext-tools/src/msgfilter.c @@ -663,6 +663,10 @@ process_message (message_ty *mp) else unsetenv ("MSGFILTER_MSGCTXT"); xsetenv ("MSGFILTER_MSGID", mp->msgid, 1); + if (mp->msgid_plural != NULL) + xsetenv ("MSGFILTER_MSGID_PLURAL", mp->msgid_plural, 1); + else + unsetenv ("MSGFILTER_MSGID_PLURAL"); location = xasprintf ("%s:%ld", mp->pos.file_name, (long) mp->pos.line_number); xsetenv ("MSGFILTER_LOCATION", location, 1); @@ -680,6 +684,15 @@ process_message (message_ty *mp) char *result; size_t length; + if (mp->msgid_plural != NULL) + { + char *plural_form_string = xasprintf ("%lu", k); + + xsetenv ("MSGFILTER_PLURAL_FORM", plural_form_string, 1); + free (plural_form_string); + } + else + unsetenv ("MSGFILTER_PLURAL_FORM"); process_string (p, strlen (p), &result, &length); result = (char *) xrealloc (result, length + 1); result[length] = '\0';