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.
This commit is contained in:
Bruno Haible 2025-06-30 13:50:51 +02:00
parent c97fababab
commit 8d373b0656
6 changed files with 105 additions and 7 deletions

View 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);

View 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>

View 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>

View 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, &dcatr->is_fuzzy, dcatr->is_format, &dcatr->range,
&dcatr->do_wrap, NULL);
parse_comment_special (s, &tmp_fuzzy, tmp_format, &tmp_range, &tmp_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;
}

View 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 \

73
gettext-tools/tests/msgcat-24 Executable file
View File

@ -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