diff options
author | Stanislav Brabec <sbrabec@suse.cz> | 2014-05-15 12:00:01 +0900 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2014-05-15 14:46:32 +0900 |
commit | 78713eea7ed18a037d9748390e8128b38a8ecaf5 (patch) | |
tree | 99ab64aaf080d3965778206bd89f051fe5aa09ca | |
parent | 04ba4c730c81ac7bf26584cdad55b346e6308d1e (diff) | |
download | external_gettext-78713eea7ed18a037d9748390e8128b38a8ecaf5.zip external_gettext-78713eea7ed18a037d9748390e8128b38a8ecaf5.tar.gz external_gettext-78713eea7ed18a037d9748390e8128b38a8ecaf5.tar.bz2 |
msgexec: Implement plural support
* msgexec.c (process_string): Set or unset MSGEXEC_MSGID_PLURAL.
(process_message): Set or unset MSGEXEC_PLURAL_FORM.
-rw-r--r-- | gettext-tools/doc/ChangeLog | 5 | ||||
-rw-r--r-- | gettext-tools/doc/msgexec.texi | 7 | ||||
-rw-r--r-- | gettext-tools/src/ChangeLog | 6 | ||||
-rw-r--r-- | gettext-tools/src/msgexec.c | 16 |
4 files changed, 32 insertions, 2 deletions
diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 76d0071..740b6f6 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -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 diff --git a/gettext-tools/doc/msgexec.texi b/gettext-tools/doc/msgexec.texi index 7177a0b..5ef640c 100644 --- a/gettext-tools/doc/msgexec.texi +++ b/gettext-tools/doc/msgexec.texi @@ -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 diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 039d764..bc262cb 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -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 diff --git a/gettext-tools/src/msgexec.c b/gettext-tools/src/msgexec.c index c46ca7f..4856376 100644 --- a/gettext-tools/src/msgexec.c +++ b/gettext-tools/src/msgexec.c @@ -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; |