]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Support reading PO files with '#=' lines.
authorBruno Haible <bruno@clisp.org>
Mon, 30 Jun 2025 11:50:51 +0000 (13:50 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 30 Jun 2025 11:50:51 +0000 (13:50 +0200)
* gettext-tools/src/read-catalog-abstract.c
(catalog_reader_seen_generic_comment): Treat '=' like ','.
* gettext-tools/src/read-catalog.c (default_comment_special): Allow several
calls to this method to make side effects on dcatr.
* gettext-tools/src/read-catalog-special.h: Update comment.
* gettext-tools/src/read-catalog-special.c: Likewise.
* gettext-tools/tests/msgcat-24: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.

gettext-tools/src/read-catalog-abstract.c
gettext-tools/src/read-catalog-special.c
gettext-tools/src/read-catalog-special.h
gettext-tools/src/read-catalog.c
gettext-tools/tests/Makefile.am
gettext-tools/tests/msgcat-24 [new file with mode: 0755]

index e42b6b8f8db5fb65f68c9e43b1972bb1cec76ee9..d14c7db1d5177ff7820a8e662b999742f94a9fa8 100644 (file)
@@ -581,7 +581,7 @@ catalog_reader_seen_generic_comment (abstract_catalog_reader_ty *catr,
          invoked.  */
       parse_comment_filepos (catr, s + 1);
     }
-  else if (*s == ',' || *s == '!')
+  else if (*s == ',' || *s == '=' || *s == '!')
     {
       /* Get all entries in the special comment line.  */
       catalog_reader_seen_comment_special (catr, s + 1);
index 487d453bb84d930b850ab9aa2a502594ca54f312..47bbc05b1846d0fc7223f58479140e61886f2a6a 100644 (file)
@@ -1,4 +1,4 @@
-/* Parsing of special comments (#, comments) in textual message catalogs.
+/* Parsing of special comments (#, and #= comments) in textual message catalogs.
    Copyright (C) 1995-2025 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
index 51cb7d71e2322d4ae224e588e4b40b5067e4448d..28c93c714af93906db0b4073d778b954840234bb 100644 (file)
@@ -1,4 +1,4 @@
-/* Parsing of special comments (#, comments) in textual message catalogs.
+/* Parsing of special comments (#, and #= comments) in textual message catalogs.
    Copyright (C) 1995-2025 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
index 1fd37910d50c581c557b0fe5de6be0f3be91c4d6..8f3e67b6984afd1d501bd05a9adba9ee33952e58 100644 (file)
@@ -295,14 +295,39 @@ default_comment_filepos (abstract_catalog_reader_ty *catr,
 }
 
 
-/* Test for '#, fuzzy' comments and warn.  */
+/* Test for '#, fuzzy' or '#= fuzzy' comments and warn.  */
 void
 default_comment_special (abstract_catalog_reader_ty *catr, const char *s)
 {
   default_catalog_reader_ty *dcatr = (default_catalog_reader_ty *) catr;
+  bool tmp_fuzzy;
+  enum is_format tmp_format[NFORMATS];
+  struct argument_range tmp_range;
+  enum is_wrap tmp_wrap;
+  size_t i;
+
+  parse_comment_special (s, &tmp_fuzzy, tmp_format, &tmp_range, &tmp_wrap,
+                         NULL);
 
-  parse_comment_special (s, &dcatr->is_fuzzy, dcatr->is_format, &dcatr->range,
-                         &dcatr->do_wrap, NULL);
+  if (tmp_fuzzy)
+    dcatr->is_fuzzy = true;
+  for (i = 0; i < NFORMATS; i++)
+    if (tmp_format[i] != undecided)
+      dcatr->is_format[i] = tmp_format[i];
+  if (has_range_p (tmp_range))
+    {
+      if (has_range_p (dcatr->range))
+        {
+          if (tmp_range.min < dcatr->range.min)
+            dcatr->range.min = tmp_range.min;
+          if (tmp_range.max > dcatr->range.max)
+            dcatr->range.max = tmp_range.max;
+        }
+      else
+        dcatr->range = tmp_range;
+    }
+  if (tmp_wrap != undecided)
+    dcatr->do_wrap = tmp_wrap;
 }
 
 
index b4ba7e246f0448672b6ed0cd10cf40c8d7071b7c..54127ba9d450713abb05f5e1f4775e8d9be9ca00 100644 (file)
@@ -34,7 +34,7 @@ TESTS = gettext-1 gettext-2 \
        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-21 \
-       msgcat-22 msgcat-23 \
+       msgcat-22 msgcat-23 msgcat-24 \
        msgcat-properties-1 msgcat-properties-2 \
        msgcat-stringtable-1 \
        msgcmp-1 msgcmp-2 msgcmp-3 msgcmp-4 \
diff --git a/gettext-tools/tests/msgcat-24 b/gettext-tools/tests/msgcat-24
new file mode 100755 (executable)
index 0000000..96610de
--- /dev/null
@@ -0,0 +1,73 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test processing of PO files with '#=' flags lines.
+
+cat <<\EOF > mcat-test24.in1
+#, fuzzy
+#= c-format, no-wrap
+msgid "%d marbles in box 1"
+msgstr "%d Murmeln in der Schachtel 1"
+
+#, fuzzy, c-format
+#= no-wrap
+msgid "%d marbles in box 2"
+msgstr "%d Murmeln in der Schachtel 2"
+
+#, fuzzy, no-wrap
+#= c-format
+msgid "%d marbles in box 3"
+msgstr "%d Murmeln in der Schachtel 3"
+
+#, c-format, no-wrap
+#= fuzzy
+msgid "%d marbles in box 4"
+msgstr "%d Murmeln in der Schachtel 4"
+
+#, no-wrap
+#= fuzzy, c-format
+msgid "%d marbles in box 5"
+msgstr "%d Murmeln in der Schachtel 5"
+
+#, c-format
+#= fuzzy, no-wrap
+msgid "%d marbles in box 6"
+msgstr "%d Murmeln in der Schachtel 6"
+EOF
+
+rm -f mcat-test24.tmp
+: ${MSGCAT=msgcat}
+${MSGCAT} -o mcat-test24.tmp mcat-test24.in1 || Exit 1
+LC_ALL=C tr -d '\r' < mcat-test24.tmp > mcat-test24.out || Exit 1
+
+cat << EOF > mcat-test24.ok
+#, fuzzy, c-format, no-wrap
+msgid "%d marbles in box 1"
+msgstr "%d Murmeln in der Schachtel 1"
+
+#, fuzzy, c-format, no-wrap
+msgid "%d marbles in box 2"
+msgstr "%d Murmeln in der Schachtel 2"
+
+#, fuzzy, c-format, no-wrap
+msgid "%d marbles in box 3"
+msgstr "%d Murmeln in der Schachtel 3"
+
+#, fuzzy, c-format, no-wrap
+msgid "%d marbles in box 4"
+msgstr "%d Murmeln in der Schachtel 4"
+
+#, fuzzy, c-format, no-wrap
+msgid "%d marbles in box 5"
+msgstr "%d Murmeln in der Schachtel 5"
+
+#, fuzzy, c-format, no-wrap
+msgid "%d marbles in box 6"
+msgstr "%d Murmeln in der Schachtel 6"
+EOF
+
+: ${DIFF=diff}
+${DIFF} mcat-test24.ok mcat-test24.out
+result=$?
+
+exit $result