From 5ed70829a2a78b38f8fddf3543a34f9f22ea110e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 18 Nov 2018 11:41:40 +0100 Subject: [PATCH] msgmerge must produce output that is stable under msgcat. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reported by Ludovic Courtès in . * gettext-tools/src/write-po.c (message_print_obsolete): Preserve the 'no-wrap' and '*-format' flags. * gettext-tools/tests/msgmerge-27: New file. * gettext-tools/tests/msgmerge-28: New file. * gettext-tools/tests/Makefile.am (TESTS): Add them. * gettext-tools/tests/msgmerge-19: Update expected result. --- gettext-tools/src/write-po.c | 54 +++++++- gettext-tools/tests/Makefile.am | 3 +- gettext-tools/tests/msgmerge-19 | 3 +- gettext-tools/tests/msgmerge-27 | 229 ++++++++++++++++++++++++++++++++ gettext-tools/tests/msgmerge-28 | 225 +++++++++++++++++++++++++++++++ 5 files changed, 507 insertions(+), 7 deletions(-) create mode 100755 gettext-tools/tests/msgmerge-27 create mode 100755 gettext-tools/tests/msgmerge-28 diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index cb9b99bd6..a1d3b955c 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -1402,7 +1402,8 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ static void message_print_obsolete (const message_ty *mp, ostream_t stream, - const char *charset, size_t page_width, bool blank_line) + const char *charset, size_t page_width, bool blank_line, + bool debug) { int extra_indent; @@ -1428,13 +1429,56 @@ message_print_obsolete (const message_ty *mp, ostream_t stream, /* Print the file position comments (normally empty). */ message_print_comment_filepos (mp, stream, uniforum, page_width); - /* Print flag information in special comment. */ - if (mp->is_fuzzy) + /* Print flag information in special comment. + Preserve only + - the fuzzy flag, because it is important for the translator when the + message becomes active again, + - the no-wrap flag, because we use mp->do_wrap below for the wrapping, + therefore further processing through 'msgcat' needs to use the same + value of do_wrap, + - the *-format flags, because the wrapping depends on these flags (see + 'Don't break inside format directives' comment), therefore further + processing through 'msgcat' needs to use the same values of is_format. + This is a trimmed-down variant of message_print_comment_flags. */ + if (mp->is_fuzzy + || has_significant_format_p (mp->is_format) + || mp->do_wrap == no) { + bool first_flag = true; + size_t i; + ostream_write_str (stream, "#,"); if (mp->is_fuzzy) - ostream_write_str (stream, " fuzzy"); + { + ostream_write_str (stream, " fuzzy"); + first_flag = false; + } + + for (i = 0; i < NFORMATS; i++) + if (significant_format_p (mp->is_format[i])) + { + if (!first_flag) + ostream_write_str (stream, ","); + + ostream_write_str (stream, " "); + ostream_write_str (stream, + make_format_description_string (mp->is_format[i], + format_language[i], + debug)); + first_flag = false; + } + + if (mp->do_wrap == no) + { + if (!first_flag) + ostream_write_str (stream, ","); + + ostream_write_str (stream, " "); + ostream_write_str (stream, + make_c_width_description_string (mp->do_wrap)); + first_flag = false; + } ostream_write_str (stream, "\n"); } @@ -1604,7 +1648,7 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream, if (mlp->item[j]->obsolete) { message_print_obsolete (mlp->item[j], stream, charset, page_width, - blank_line); + blank_line, debug); blank_line = true; } diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 485bd98ee..542bbed61 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -60,7 +60,8 @@ TESTS = gettext-1 gettext-2 \ msgmerge-7 msgmerge-8 msgmerge-9 msgmerge-10 msgmerge-11 msgmerge-12 \ msgmerge-13 msgmerge-14 msgmerge-15 msgmerge-16 msgmerge-17 \ msgmerge-18 msgmerge-19 msgmerge-20 msgmerge-21 msgmerge-22 \ - msgmerge-23 msgmerge-24 msgmerge-25 msgmerge-26 \ + msgmerge-23 msgmerge-24 msgmerge-25 msgmerge-26 msgmerge-27 \ + msgmerge-28 \ msgmerge-compendium-1 msgmerge-compendium-2 msgmerge-compendium-3 \ msgmerge-compendium-4 msgmerge-compendium-5 msgmerge-compendium-6 \ msgmerge-properties-1 msgmerge-properties-2 \ diff --git a/gettext-tools/tests/msgmerge-19 b/gettext-tools/tests/msgmerge-19 index 9f54dc1f4..4b3119ead 100755 --- a/gettext-tools/tests/msgmerge-19 +++ b/gettext-tools/tests/msgmerge-19 @@ -193,11 +193,12 @@ msgstr "zu viele Argumente" msgid "Missing arguments." msgstr "Argumente fehlen" -#, fuzzy +#, fuzzy, c-format #~| msgid "%s: invalid option -- %c\n" #~ msgid "%s: illegal option -- %c\n" #~ msgstr "%s: ungültige Option -- %c\n" +#, c-format #~ msgid "%s: invalid option -- %c\n" #~ msgstr "%s: ungültige Option -- %c\n" EOF diff --git a/gettext-tools/tests/msgmerge-27 b/gettext-tools/tests/msgmerge-27 new file mode 100755 index 000000000..e8076ee2c --- /dev/null +++ b/gettext-tools/tests/msgmerge-27 @@ -0,0 +1,229 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test that the msgmerge output is stable under an 'msgcat' invocation. +# Also test what happens with the 'no-wrap' flag during msgmerge. + +cat <<\EOF > mm-test27.po +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "This is a long paragraph that gets wrapped into several lines because it is so long." +msgstr "Dies ist ein langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil er so lang ist." + +#, no-wrap +msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "Dies ist ein langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist." + +msgid "This is another long paragraph that gets wrapped into several lines because it is so long." +msgstr "Dies ist ein weiterer langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil er so lang ist." + +#, no-wrap +msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "Dies ist ein weiterer langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist." +EOF + +cat <<\EOF > mm-test27-1.pot +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "This is a long paragraph that gets wrapped into several lines because it is so long." +msgstr "" + +#, no-wrap +msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "" +EOF + +: ${MSGMERGE=msgmerge} +${MSGMERGE} -q -o mm-test27.tmp.po mm-test27.po mm-test27-1.pot || Exit 1 +LC_ALL=C tr -d '\r' < mm-test27.tmp.po > mm-test27.new.po || Exit 1 + +: ${MSGCAT=msgcat} +${MSGCAT} mm-test27.new.po > mm-test27.tmp.po || Exit 1 +LC_ALL=C tr -d '\r' < mm-test27.tmp.po > mm-test27.cat.po || Exit 1 + +: ${DIFF=diff} +${DIFF} mm-test27.new.po mm-test27.cat.po || Exit 1 + +cat <<\EOF > mm-test27-1.ok +msgid "" +msgstr "" +"Report-Msgid-Bugs-To: \n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "" +"This is a long paragraph that gets wrapped into several lines because it is " +"so long." +msgstr "" +"Dies ist ein langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil " +"er so lang ist." + +#, no-wrap +msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "Dies ist ein langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist." + +#~ msgid "" +#~ "This is another long paragraph that gets wrapped into several lines " +#~ "because it is so long." +#~ msgstr "" +#~ "Dies ist ein weiterer langer Abschnitt, der in mehrere Zeilen umgebrochen " +#~ "wird, weil er so lang ist." + +#, no-wrap +#~ msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +#~ msgstr "Dies ist ein weiterer langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist." +EOF + +: ${DIFF=diff} +${DIFF} mm-test27-1.ok mm-test27.new.po || Exit 1 + +# Now test what happens with the 'no-wrap' flag when merging with a POT file +# where the 'no-wrap' flag is set. + +cat <<\EOF > mm-test27-2.pot +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#, no-wrap +msgid "This is a long paragraph that gets wrapped into several lines because it is so long." +msgstr "" + +#, no-wrap +msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "" + +#, no-wrap +msgid "This is another long paragraph that gets wrapped into several lines because it is so long." +msgstr "" + +#, no-wrap +msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "" +EOF + +: ${MSGMERGE=msgmerge} +${MSGMERGE} -q -o mm-test27.tmp.po mm-test27.new.po mm-test27-2.pot || Exit 1 +LC_ALL=C tr -d '\r' < mm-test27.tmp.po > mm-test27-2.po || Exit 1 + +cat <<\EOF > mm-test27-2.ok +msgid "" +msgstr "" +"Report-Msgid-Bugs-To: \n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#, no-wrap +msgid "This is a long paragraph that gets wrapped into several lines because it is so long." +msgstr "Dies ist ein langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil er so lang ist." + +#, no-wrap +msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "Dies ist ein langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist." + +#, no-wrap +msgid "This is another long paragraph that gets wrapped into several lines because it is so long." +msgstr "Dies ist ein weiterer langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil er so lang ist." + +#, no-wrap +msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "Dies ist ein weiterer langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, weil er als 'no-wrap' markiert ist." +EOF + +: ${DIFF=diff} +${DIFF} mm-test27-2.ok mm-test27-2.po || Exit 1 + +# Now test what happens with the 'no-wrap' flag when merging with a POT file +# where the 'no-wrap' flag is absent. + +cat <<\EOF > mm-test27-3.pot +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "This is a long paragraph that gets wrapped into several lines because it is so long." +msgstr "" + +msgid "This is a long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "" + +msgid "This is another long paragraph that gets wrapped into several lines because it is so long." +msgstr "" + +msgid "This is another long paragraph that does not get wrapped into several lines because it is marked as 'no-wrap'." +msgstr "" +EOF + +: ${MSGMERGE=msgmerge} +${MSGMERGE} -q -o mm-test27.tmp.po mm-test27.new.po mm-test27-3.pot || Exit 1 +LC_ALL=C tr -d '\r' < mm-test27.tmp.po > mm-test27-3.po || Exit 1 + +cat <<\EOF > mm-test27-3.ok +msgid "" +msgstr "" +"Report-Msgid-Bugs-To: \n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "" +"This is a long paragraph that gets wrapped into several lines because it is " +"so long." +msgstr "" +"Dies ist ein langer Abschnitt, der in mehrere Zeilen umgebrochen wird, weil " +"er so lang ist." + +msgid "" +"This is a long paragraph that does not get wrapped into several lines " +"because it is marked as 'no-wrap'." +msgstr "" +"Dies ist ein langer Abschnitt, der nicht in mehrere Zeilen umgebrochen wird, " +"weil er als 'no-wrap' markiert ist." + +msgid "" +"This is another long paragraph that gets wrapped into several lines because " +"it is so long." +msgstr "" +"Dies ist ein weiterer langer Abschnitt, der in mehrere Zeilen umgebrochen " +"wird, weil er so lang ist." + +msgid "" +"This is another long paragraph that does not get wrapped into several lines " +"because it is marked as 'no-wrap'." +msgstr "" +"Dies ist ein weiterer langer Abschnitt, der nicht in mehrere Zeilen " +"umgebrochen wird, weil er als 'no-wrap' markiert ist." +EOF + +: ${DIFF=diff} +${DIFF} mm-test27-3.ok mm-test27-3.po || Exit 1 + +Exit 0 diff --git a/gettext-tools/tests/msgmerge-28 b/gettext-tools/tests/msgmerge-28 new file mode 100755 index 000000000..ec3faaf5b --- /dev/null +++ b/gettext-tools/tests/msgmerge-28 @@ -0,0 +1,225 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test that the msgmerge output is stable under an 'msgcat' invocation. +# Also test what happens with the 'c-format' flag during msgmerge. + +cat <<\EOF > mm-test28.po +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "warning: bad context for singular argument of keyword '%.*s'" +msgstr "Warnung: schlechter Kontext für das Singular-Argument des Schlüsselwortes »%.*s«" + +#, c-format +msgid "warning: broken context for singular argument of keyword '%.*s'" +msgstr "Warnung: missratener Kontext für das Singular-Argument des Schlüsselworts »%.*s«" + +msgid "warning: abstruse context for plural argument of keyword '%.*s'" +msgstr "Warnung: abstruser Kontext für das Plural-Argument des Schlüsselwortes »%.*s«" + +#, c-format +msgid "warning: missing context for plural argument of keyword '%.*s'" +msgstr "Warnung: fehlender Kontext für das Plural-Argument des Schlüsselwortes »%.*s«" +EOF + +cat <<\EOF > mm-test28-1.pot +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "warning: bad context for singular argument of keyword '%.*s'" +msgstr "" + +#, c-format +msgid "warning: broken context for singular argument of keyword '%.*s'" +msgstr "" +EOF + +: ${MSGMERGE=msgmerge} +${MSGMERGE} -q -o mm-test28.tmp.po mm-test28.po mm-test28-1.pot || Exit 1 +LC_ALL=C tr -d '\r' < mm-test28.tmp.po > mm-test28.new.po || Exit 1 + +: ${MSGCAT=msgcat} +${MSGCAT} mm-test28.new.po > mm-test28.tmp.po || Exit 1 +LC_ALL=C tr -d '\r' < mm-test28.tmp.po > mm-test28.cat.po || Exit 1 + +: ${DIFF=diff} +${DIFF} mm-test28.new.po mm-test28.cat.po || Exit 1 + +cat <<\EOF > mm-test28-1.ok +msgid "" +msgstr "" +"Report-Msgid-Bugs-To: \n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "warning: bad context for singular argument of keyword '%.*s'" +msgstr "" +"Warnung: schlechter Kontext für das Singular-Argument des Schlüsselwortes »%." +"*s«" + +#, c-format +msgid "warning: broken context for singular argument of keyword '%.*s'" +msgstr "" +"Warnung: missratener Kontext für das Singular-Argument des Schlüsselworts " +"»%.*s«" + +#~ msgid "warning: abstruse context for plural argument of keyword '%.*s'" +#~ msgstr "" +#~ "Warnung: abstruser Kontext für das Plural-Argument des Schlüsselwortes »%." +#~ "*s«" + +#, c-format +#~ msgid "warning: missing context for plural argument of keyword '%.*s'" +#~ msgstr "" +#~ "Warnung: fehlender Kontext für das Plural-Argument des Schlüsselwortes " +#~ "»%.*s«" +EOF + +: ${DIFF=diff} +${DIFF} mm-test28-1.ok mm-test28.new.po || Exit 1 + +# Now test what happens with the 'c-format' flag when merging with a POT file +# where the 'c-format' flag is set. + +cat <<\EOF > mm-test28-2.pot +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#, c-format +msgid "warning: bad context for singular argument of keyword '%.*s'" +msgstr "" + +#, c-format +msgid "warning: broken context for singular argument of keyword '%.*s'" +msgstr "" + +#, c-format +msgid "warning: abstruse context for plural argument of keyword '%.*s'" +msgstr "" + +#, c-format +msgid "warning: missing context for plural argument of keyword '%.*s'" +msgstr "" +EOF + +: ${MSGMERGE=msgmerge} +${MSGMERGE} -q -o mm-test28.tmp.po mm-test28.new.po mm-test28-2.pot || Exit 1 +LC_ALL=C tr -d '\r' < mm-test28.tmp.po > mm-test28-2.po || Exit 1 + +cat <<\EOF > mm-test28-2.ok +msgid "" +msgstr "" +"Report-Msgid-Bugs-To: \n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#, c-format +msgid "warning: bad context for singular argument of keyword '%.*s'" +msgstr "" +"Warnung: schlechter Kontext für das Singular-Argument des Schlüsselwortes " +"»%.*s«" + +#, c-format +msgid "warning: broken context for singular argument of keyword '%.*s'" +msgstr "" +"Warnung: missratener Kontext für das Singular-Argument des Schlüsselworts " +"»%.*s«" + +#, c-format +msgid "warning: abstruse context for plural argument of keyword '%.*s'" +msgstr "" +"Warnung: abstruser Kontext für das Plural-Argument des Schlüsselwortes »%.*s«" + +#, c-format +msgid "warning: missing context for plural argument of keyword '%.*s'" +msgstr "" +"Warnung: fehlender Kontext für das Plural-Argument des Schlüsselwortes »%.*s«" +EOF + +: ${DIFF=diff} +${DIFF} mm-test28-2.ok mm-test28-2.po || Exit 1 + +# Now test what happens with the 'c-format' flag when merging with a POT file +# where the 'c-format' flag is absent. + +cat <<\EOF > mm-test28-3.pot +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "warning: bad context for singular argument of keyword '%.*s'" +msgstr "" + +msgid "warning: broken context for singular argument of keyword '%.*s'" +msgstr "" + +msgid "warning: abstruse context for plural argument of keyword '%.*s'" +msgstr "" + +msgid "warning: missing context for plural argument of keyword '%.*s'" +msgstr "" +EOF + +: ${MSGMERGE=msgmerge} +${MSGMERGE} -q -o mm-test28.tmp.po mm-test28.new.po mm-test28-3.pot || Exit 1 +LC_ALL=C tr -d '\r' < mm-test28.tmp.po > mm-test28-3.po || Exit 1 + +cat <<\EOF > mm-test28-3.ok +msgid "" +msgstr "" +"Report-Msgid-Bugs-To: \n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "warning: bad context for singular argument of keyword '%.*s'" +msgstr "" +"Warnung: schlechter Kontext für das Singular-Argument des Schlüsselwortes »%." +"*s«" + +msgid "warning: broken context for singular argument of keyword '%.*s'" +msgstr "" +"Warnung: missratener Kontext für das Singular-Argument des Schlüsselworts »%." +"*s«" + +msgid "warning: abstruse context for plural argument of keyword '%.*s'" +msgstr "" +"Warnung: abstruser Kontext für das Plural-Argument des Schlüsselwortes »%.*s«" + +msgid "warning: missing context for plural argument of keyword '%.*s'" +msgstr "" +"Warnung: fehlender Kontext für das Plural-Argument des Schlüsselwortes »%.*s«" +EOF + +: ${DIFF=diff} +${DIFF} mm-test28-3.ok mm-test28-3.po || Exit 1 + +Exit 0 -- 2.47.2