]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Produce PO files with the right number of plural forms.
authorBruno Haible <bruno@clisp.org>
Tue, 14 Sep 2004 17:34:01 +0000 (17:34 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:55 +0000 (12:11 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/Makefile.am
gettext-tools/src/msginit.c
gettext-tools/src/msgmerge.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am

index 780bf77c30407ad6f552437768a90cceb9c4d0c7..5b308285109ea06b60b0b57bbe6614d1302db6ec 100644 (file)
@@ -1,3 +1,12 @@
+2004-09-11  Bruno Haible  <bruno@clisp.org>
+
+       * 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 <jens@peino.de>.
+
 2004-09-06  Bruno Haible  <bruno@clisp.org>
 
        * format.h (formatstring_error_logger_t): New type.
index 36f129ac87e2992b8a5a7d38b6b757bc0da02c57..ab4ae0a7ad9fd60b1c5011dd88769ce3c170e449 100644 (file)
@@ -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
index 0bb1def04f3722e3fc85570750eb5d51b6f85441..45e5c648cc308dd83d3445e1ece9b36475d55a87 100644 (file)
@@ -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;
+}
index 3e9f464c644b424fb4a7e19f81a6840a702e46aa..23ae64b124a47d5c932cc415f4b691c4a874bad5 100644 (file)
@@ -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++;
            }
index c6b1264686bc4aa97f72be0d1a4e03c00d2d81cd..db69d239eef3be943c1ca02e7ee4f4b9152c3203 100644 (file)
@@ -1,3 +1,11 @@
+2004-09-11  Bruno Haible  <bruno@clisp.org>
+
+       * 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 <jens@peino.de>.
+
 2004-09-08  Bruno Haible  <bruno@clisp.org>
 
        Make lang-java work again on platforms with Java version < 1.4.
index 51e14f72cc08459284f2da39753cfcf61be988bc..1a74b3f602904bb4bb26aa74dcbdc5767ed12419 100644 (file)
@@ -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" \