From: Bruno Haible Date: Tue, 14 Sep 2004 17:34:01 +0000 (+0000) Subject: Produce PO files with the right number of plural forms. X-Git-Tag: v0.14.2~225 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eadb461974eae09086a93ca44dba4f988db27104;p=thirdparty%2Fgettext.git Produce PO files with the right number of plural forms. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 780bf77c3..5b3082851 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,12 @@ +2004-09-11 Bruno Haible + + * Makefile.am (msginit_SOURCES): Add plural-count.c. + * msginit.c (update_msgstr_plurals): New function. + (main): Call it. + * msgmerge.c (match_domain): Provide the appropriate number of plural + forms for messages that don't occur in the Def.po file. + Reported by Jens A. Tkotz . + 2004-09-06 Bruno Haible * format.h (formatstring_error_logger_t): New type. diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am index 36f129ac8..ab4ae0a7a 100644 --- a/gettext-tools/src/Makefile.am +++ b/gettext-tools/src/Makefile.am @@ -145,7 +145,7 @@ msgen_SOURCES = msgen.c msgexec_SOURCES = msgexec.c msgfilter_SOURCES = msgfilter.c msggrep_SOURCES = msggrep.c -msginit_SOURCES = msginit.c ../../gettext-runtime/intl/localealias.c +msginit_SOURCES = msginit.c plural-count.c ../../gettext-runtime/intl/localealias.c msguniq_SOURCES = msguniq.c hostname_SOURCES = hostname.c urlget_SOURCES = urlget.c diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index 0bb1def04..45e5c648c 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -91,6 +91,7 @@ #include "pathname.h" #include "xerror.h" #include "msgl-english.h" +#include "plural-count.h" #include "pipe.h" #include "wait-process.h" #include "getline.h" @@ -152,6 +153,7 @@ static const char *catalogname_for_locale (const char *locale); static const char *language_of_locale (const char *locale); static char *get_field (const char *header, const char *field); static msgdomain_list_ty *fill_header (msgdomain_list_ty *mdlp); +static msgdomain_list_ty *update_msgstr_plurals (msgdomain_list_ty *mdlp); int @@ -337,6 +339,8 @@ the output .po file through the --output-file option.\n"), /* Initialize translations. */ if (strcmp (language, "en") == 0) result = msgdomain_list_english (result); + else + result = update_msgstr_plurals (result); /* Write the modified message list out. */ msgdomain_list_print (result, output_file, true, false); @@ -1751,3 +1755,54 @@ fill_header (msgdomain_list_ty *mdlp) return mdlp; } + + +/* Update the msgstr plural entries according to the nplurals count. */ +static msgdomain_list_ty * +update_msgstr_plurals (msgdomain_list_ty *mdlp) +{ + size_t k; + + for (k = 0; k < mdlp->nitems; k++) + { + message_list_ty *mlp = mdlp->item[k]->messages; + message_ty *header_entry; + unsigned long int nplurals; + char *untranslated_plural_msgstr; + size_t j; + + header_entry = message_list_search (mlp, ""); + nplurals = get_plural_count (header_entry ? header_entry->msgstr : NULL); + untranslated_plural_msgstr = (char *) xmalloc (nplurals); + memset (untranslated_plural_msgstr, '\0', nplurals); + + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + bool is_untranslated; + const char *p; + const char *pend; + + if (mp->msgid_plural != NULL) + { + /* Test if mp is untranslated. (It most likely is.) */ + is_untranslated = true; + for (p = mp->msgstr, pend = p + mp->msgstr_len; p < pend; p++) + if (*p != '\0') + { + is_untranslated = false; + break; + } + if (is_untranslated) + { + /* Change mp->msgstr_len consecutive empty strings into + nplurals consecutive empty strings. */ + if (nplurals > mp->msgstr_len) + mp->msgstr = untranslated_plural_msgstr; + mp->msgstr_len = nplurals; + } + } + } + } + return mdlp; +} diff --git a/gettext-tools/src/msgmerge.c b/gettext-tools/src/msgmerge.c index 3e9f464c6..23ae64b12 100644 --- a/gettext-tools/src/msgmerge.c +++ b/gettext-tools/src/msgmerge.c @@ -909,8 +909,16 @@ match_domain (const char *fn1, const char *fn2, message_list_ty *resultmlp, struct statistics *stats, unsigned int *processed) { + message_ty *header_entry; + unsigned long int nplurals; + char *untranslated_plural_msgstr; size_t j; + header_entry = message_list_search (definitions->item[0], ""); + nplurals = get_plural_count (header_entry ? header_entry->msgstr : NULL); + untranslated_plural_msgstr = (char *) xmalloc (nplurals); + memset (untranslated_plural_msgstr, '\0', nplurals); + for (j = 0; j < refmlp->nitems; j++, (*processed)++) { message_ty *refmsg; @@ -981,6 +989,9 @@ this message is used but not defined...")); else { message_ty *mp; + bool is_untranslated; + const char *p; + const char *pend; if (verbosity_level > 1) po_gram_error_at_line (&refmsg->pos, _("\ @@ -988,6 +999,26 @@ this message is used but not defined in %s"), fn1); mp = message_copy (refmsg); + if (mp->msgid_plural != NULL) + { + /* Test if mp is untranslated. (It most likely is.) */ + is_untranslated = true; + for (p = mp->msgstr, pend = p + mp->msgstr_len; p < pend; p++) + if (*p != '\0') + { + is_untranslated = false; + break; + } + if (is_untranslated) + { + /* Change mp->msgstr_len consecutive empty strings into + nplurals consecutive empty strings. */ + if (nplurals > mp->msgstr_len) + mp->msgstr = untranslated_plural_msgstr; + mp->msgstr_len = nplurals; + } + } + message_list_append (resultmlp, mp); stats->missing++; } diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index c6b126468..db69d239e 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,11 @@ +2004-09-11 Bruno Haible + + * msginit-1: New file. + * msgmerge-17: New file. + * Makefile.am (TESTS): Add msginit-1, msgmerge-17. + (TESTS_ENVIRONMENT): Also define MSGINIT. + Reported by Jens A. Tkotz . + 2004-09-08 Bruno Haible Make lang-java work again on platforms with Java version < 1.4. diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 51e14f72c..1a74b3f60 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -43,9 +43,10 @@ TESTS = gettext-1 gettext-2 \ msgfmt-properties-1 \ msgfmt-qt-1 \ msggrep-1 msggrep-2 msggrep-3 msggrep-4 msggrep-5 msggrep-6 \ + msginit-1 \ msgmerge-1 msgmerge-2 msgmerge-3 msgmerge-4 msgmerge-5 msgmerge-6 \ msgmerge-7 msgmerge-8 msgmerge-9 msgmerge-10 msgmerge-11 msgmerge-12 \ - msgmerge-13 msgmerge-14 msgmerge-15 msgmerge-16 \ + msgmerge-13 msgmerge-14 msgmerge-15 msgmerge-16 msgmerge-17 \ msgmerge-compendium-1 msgmerge-compendium-2 msgmerge-compendium-3 \ msgmerge-compendium-4 \ msgmerge-properties-1 msgmerge-properties-2 \ @@ -131,6 +132,7 @@ TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) \ MSGFILTER="$(CHECKER) msgfilter" \ MSGFMT="$(CHECKER) msgfmt" \ MSGGREP="$(CHECKER) msggrep" \ + MSGINIT="$(CHECKER) msginit" \ MSGMERGE="$(CHECKER) msgmerge" \ MSGUNFMT="$(CHECKER) msgunfmt" \ MSGUNIQ="$(CHECKER) msguniq" \