]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msgcat: Signal error when the same msgid is used with and without msgid_plural.
authorBruno Haible <bruno@clisp.org>
Sun, 29 Sep 2019 18:20:36 +0000 (20:20 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 29 Sep 2019 18:20:36 +0000 (20:20 +0200)
Suggested by Mikko Rantalainen <mikko.rantalainen@peda.net>
in <https://lists.gnu.org/archive/html/bug-gettext/2019-09/msg00020.html>.

* gettext-tools/src/msgl-cat.c (catenate_msgdomain_list): Signal an error when
the same msgid is used with and without msgid_plural.
* gettext-tools/src/msgcat.c (main): Exit with failure code if there was an
error.
* gettext-tools/src/msgcomm.c (main): Likewise.
* gettext-tools/src/msguniq.c (main): Likewise.
* gettext-tools/tests/msgcat-21: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.

gettext-tools/src/msgcat.c
gettext-tools/src/msgcomm.c
gettext-tools/src/msgl-cat.c
gettext-tools/src/msguniq.c
gettext-tools/tests/Makefile.am
gettext-tools/tests/msgcat-21 [new file with mode: 0755]

index 17f6c665871fbcff7690e0492021daa3711df1d7..831d487394c2778cf984e9c07e3f5a263dbd77cc 100644 (file)
@@ -350,7 +350,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
   /* Write the PO file.  */
   msgdomain_list_print (result, output_file, output_syntax, force_po, false);
 
-  exit (EXIT_SUCCESS);
+  exit (error_message_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 
index dc97c4b6a0916ba847e2f7baaa7a79da5f9ba563..d1fecd8f7c1ca37f2505e745f42c5f72d42b4a66 100644 (file)
@@ -342,7 +342,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
   /* Write the PO file.  */
   msgdomain_list_print (result, output_file, output_syntax, force_po, false);
 
-  exit (EXIT_SUCCESS);
+  exit (error_message_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 
index ed3a197bbddc1a4d1fe57dfc01c223502e841388..2e806497cdef4d27f429d21bed7850131163a788 100644 (file)
@@ -297,7 +297,18 @@ catenate_msgdomain_list (string_list_ty *file_list,
               size_t i;
 
               tmp = message_list_search (total_mlp, mp->msgctxt, mp->msgid);
-              if (tmp == NULL)
+              if (tmp != NULL)
+                {
+                  if ((tmp->msgid_plural != NULL) != (mp->msgid_plural != NULL))
+                    {
+                      char *errormsg =
+                        xasprintf (_("msgid '%s' is used without plural and with plural."),
+                                   mp->msgid);
+                      multiline_error (xstrdup (""),
+                                       xasprintf ("%s\n", errormsg));
+                    }
+                }
+              else
                 {
                   tmp = message_alloc (mp->msgctxt, mp->msgid, mp->msgid_plural,
                                        NULL, 0, &mp->pos);
index fb28ecfc8775c0c5d557f47c9e809e2e92e5333a..0d2c27cce4e3d9eb0bddb904b672a260e9900e03 100644 (file)
@@ -310,7 +310,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\
   /* Write the PO file.  */
   msgdomain_list_print (result, output_file, output_syntax, force_po, false);
 
-  exit (EXIT_SUCCESS);
+  exit (error_message_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 
index 0b68a964ec1b887f78847adc8ecd4c94c6665f58..53d6af7544a908c5ce0b754a711092e78c4c7751 100644 (file)
@@ -32,7 +32,7 @@ TESTS = gettext-1 gettext-2 \
        msgattrib-properties-1 \
        msgcat-1 msgcat-2 msgcat-3 msgcat-4 msgcat-5 msgcat-6 msgcat-7 \
        msgcat-8 msgcat-9 msgcat-10 msgcat-11 msgcat-12 msgcat-13 msgcat-14 \
-       msgcat-15 msgcat-16 msgcat-17 msgcat-18 msgcat-19 msgcat-20 \
+       msgcat-15 msgcat-16 msgcat-17 msgcat-18 msgcat-19 msgcat-20 msgcat-21 \
        msgcat-properties-1 msgcat-properties-2 \
        msgcat-stringtable-1 \
        msgcmp-1 msgcmp-2 msgcmp-3 msgcmp-4 \
diff --git a/gettext-tools/tests/msgcat-21 b/gettext-tools/tests/msgcat-21
new file mode 100755 (executable)
index 0000000..7b9a437
--- /dev/null
@@ -0,0 +1,40 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Verify that msgcat complains when the same msgid occurs with and without
+# msgid_plural.
+
+cat <<\EOF > mcat-test21.in1
+msgid ""
+msgstr ""
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "File"
+msgstr "Soumettre"
+EOF
+
+cat <<\EOF > mcat-test21.in2
+msgid ""
+msgstr ""
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+msgid "File"
+msgid_plural "Files"
+msgstr[0] "fichier"
+msgstr[1] "fichiers"
+EOF
+
+rm -f mcat-test21.out1
+: ${MSGCAT=msgcat}
+${MSGCAT} -o mcat-test21.out1 mcat-test21.in1 mcat-test21.in2 2>/dev/null
+test $? = 1 || { Exit 1; }
+
+rm -f mcat-test21.out2
+: ${MSGCAT=msgcat}
+${MSGCAT} -o mcat-test21.out2 mcat-test21.in2 mcat-test21.in1 2>/dev/null
+test $? = 1 || { Exit 1; }
+
+Exit 0