[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gettext] [PATCH] msgexec, msgfilter: Implement plural support
From: |
Stanislav Brabec |
Subject: |
[bug-gettext] [PATCH] msgexec, msgfilter: Implement plural support |
Date: |
Wed, 14 May 2014 23:32:27 +0200 |
Add new variables that allow proper processing of plurals:
msgexec: MSGEXEC_MSGID_PLURAL, MSGEXEC_PLURAL_FORM
msgfilter: MSGFILTER_MSGID_PLURAL, MSGFILTER_PLURAL_FORM
Without these new variables, command has no chance to discriminate between
plural forms, as all have exactly the same environment.
Signed-off-by: Stanislav Brabec <address@hidden>
---
gettext-tools/doc/msgexec.texi | 5 ++++-
gettext-tools/doc/msgfilter.texi | 5 ++++-
gettext-tools/src/msgexec.c | 14 ++++++++++++++
gettext-tools/src/msgfilter.c | 14 ++++++++++++++
4 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/gettext-tools/doc/msgexec.texi b/gettext-tools/doc/msgexec.texi
index 7177a0b..5fd8013 100644
--- a/gettext-tools/doc/msgexec.texi
+++ b/gettext-tools/doc/msgexec.texi
@@ -25,7 +25,10 @@ During each @var{command} invocation, the environment
variable
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
address@hidden is bound to the message's msgid_plural and
address@hidden 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/doc/msgfilter.texi b/gettext-tools/doc/msgfilter.texi
index c26189e..c72ea33 100644
--- a/gettext-tools/doc/msgfilter.texi
+++ b/gettext-tools/doc/msgfilter.texi
@@ -16,7 +16,10 @@ During each @var{filter} invocation, the environment variable
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
address@hidden is bound to the message's msgid_plural and
address@hidden 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/msgexec.c b/gettext-tools/src/msgexec.c
index 3784b4c..70474e3 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);
@@ -408,6 +412,7 @@ process_message (const message_ty *mp)
{
const char *msgstr = mp->msgstr;
size_t msgstr_len = mp->msgstr_len;
+ unsigned int i = 0;
const char *p;
/* Process each NUL delimited substring separately. */
@@ -415,6 +420,15 @@ process_message (const message_ty *mp)
{
size_t length = strlen (p);
+ if (mp->msgid_plural != NULL)
+ {
+ char *plural_form_string;
+ plural_form_string = xasprintf ("%u", i++);
+ 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;
diff --git a/gettext-tools/src/msgfilter.c b/gettext-tools/src/msgfilter.c
index 73b2d6b..9bd91f7 100644
--- a/gettext-tools/src/msgfilter.c
+++ b/gettext-tools/src/msgfilter.c
@@ -638,6 +638,7 @@ process_message (message_ty *mp)
char **substrings;
size_t total_len;
char *total_str;
+ unsigned int i = 0;
const char *p;
char *q;
size_t k;
@@ -663,6 +664,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 +685,15 @@ process_message (message_ty *mp)
char *result;
size_t length;
+ if (mp->msgid_plural != NULL)
+ {
+ char *plural_form_string;
+ plural_form_string = xasprintf ("%u", i++);
+ 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';
--
1.8.4.5
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: address@hidden
Lihovarská 1060/12 tel: +49 911 7405384547
190 00 Praha 9 fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
- [bug-gettext] [PATCH] msgexec, msgfilter: Implement plural support,
Stanislav Brabec <=