From: Bruno Haible Date: Mon, 30 Jun 2025 11:50:51 +0000 (+0200) Subject: Support reading PO files with '#=' lines. X-Git-Tag: v0.26~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d373b065696573050776bc4bf5b6fbc660d3665;p=thirdparty%2Fgettext.git Support reading PO files with '#=' lines. * 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. --- diff --git a/gettext-tools/src/read-catalog-abstract.c b/gettext-tools/src/read-catalog-abstract.c index e42b6b8f8..d14c7db1d 100644 --- a/gettext-tools/src/read-catalog-abstract.c +++ b/gettext-tools/src/read-catalog-abstract.c @@ -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); diff --git a/gettext-tools/src/read-catalog-special.c b/gettext-tools/src/read-catalog-special.c index 487d453bb..47bbc05b1 100644 --- a/gettext-tools/src/read-catalog-special.c +++ b/gettext-tools/src/read-catalog-special.c @@ -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 diff --git a/gettext-tools/src/read-catalog-special.h b/gettext-tools/src/read-catalog-special.h index 51cb7d71e..28c93c714 100644 --- a/gettext-tools/src/read-catalog-special.h +++ b/gettext-tools/src/read-catalog-special.h @@ -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 diff --git a/gettext-tools/src/read-catalog.c b/gettext-tools/src/read-catalog.c index 1fd37910d..8f3e67b69 100644 --- a/gettext-tools/src/read-catalog.c +++ b/gettext-tools/src/read-catalog.c @@ -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; } diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index b4ba7e246..54127ba9d 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -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 index 000000000..96610de4f --- /dev/null +++ b/gettext-tools/tests/msgcat-24 @@ -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