From: Guido Flohr Date: Thu, 10 Apr 2014 08:40:52 +0000 (+0900) Subject: msgattrib: Add --empty option X-Git-Tag: v0.19~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2832f5c072ad569ddda09262a526018ba8fda265;p=thirdparty%2Fgettext.git msgattrib: Add --empty option --- diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 79b5e1762..76d0071d9 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -1,3 +1,8 @@ +2014-05-10 Guido Flohr + + msgattrib: Add --empty option to clear msgstr + * msgattrib.texi: Document --empty option. + 2014-05-05 Daiki Ueno * gettext.texi (Translations under Version Control): New section. diff --git a/gettext-tools/doc/msgattrib.texi b/gettext-tools/doc/msgattrib.texi index 998b8b062..f89514179 100644 --- a/gettext-tools/doc/msgattrib.texi +++ b/gettext-tools/doc/msgattrib.texi @@ -137,6 +137,17 @@ mark, keep ``previous msgid'' of translated messages. @opindex --clear-previous@r{, @code{msgattrib} option} Remove the ``previous msgid'' (@samp{#|}) comments from all messages. +@item --empty +@opindex --empty@r{, @code{msgattrib} option} +When removing +@ifhtml +‘fuzzy’ +@end ifhtml +@ifnothtml +`fuzzy' +@end ifnothtml +mark, also set msgstr empty. + @item --only-file=@var{file} @opindex --only-file@r{, @code{msgattrib} option} Limit the attribute changes to entries that are listed in @var{file}. diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 6832740f2..ddf70f374 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,12 @@ +2014-05-10 Guido Flohr + + msgattrib: Add --empty option to clear msgstr + * msgattrib.c (REMOVE_TRANSLATION): New enum value. + (long_options): Add --empty. + (main): Set REMOVE_TRANSLATION flag when --empty is given. + (usage): Show help of --empty. + (process_message_list): Handle REMOVE_TRANSLATION flag. + 2014-05-09 Daiki Ueno vala: Interpret string literals lazily diff --git a/gettext-tools/src/msgattrib.c b/gettext-tools/src/msgattrib.c index 01b6f97f6..326f28cac 100644 --- a/gettext-tools/src/msgattrib.c +++ b/gettext-tools/src/msgattrib.c @@ -73,7 +73,8 @@ enum SET_OBSOLETE = 1 << 2, RESET_OBSOLETE = 1 << 3, REMOVE_PREV = 1 << 4, - ADD_PREV = 1 << 5 + ADD_PREV = 1 << 5, + REMOVE_TRANSLATION = 1 << 6 }; static int to_change; @@ -84,6 +85,7 @@ static const struct option long_options[] = { "clear-fuzzy", no_argument, NULL, CHAR_MAX + 8 }, { "clear-obsolete", no_argument, NULL, CHAR_MAX + 10 }, { "clear-previous", no_argument, NULL, CHAR_MAX + 18 }, + { "empty", no_argument, NULL, CHAR_MAX + 23 }, { "color", optional_argument, NULL, CHAR_MAX + 19 }, { "directory", required_argument, NULL, 'D' }, { "escape", no_argument, NULL, 'E' }, @@ -336,6 +338,10 @@ main (int argc, char **argv) message_print_style_filepos (filepos_comment_none); break; + case CHAR_MAX + 23: /* --empty */ + to_change |= REMOVE_TRANSLATION; + break; + default: usage (EXIT_FAILURE); /* NOTREACHED */ @@ -472,6 +478,8 @@ Attribute manipulation:\n")); printf (_("\ --clear-previous remove the \"previous msgid\" from all messages\n")); printf (_("\ + --empty when removing 'fuzzy', also set msgstr empty\n")); + printf (_("\ --only-file=FILE.po manipulate only entries listed in FILE.po\n")); printf (_("\ --ignore-file=FILE.po manipulate only entries not listed in FILE.po\n")); @@ -615,7 +623,25 @@ process_message_list (message_list_ty *mlp, } if (to_change & RESET_FUZZY) - mp->is_fuzzy = false; + { + if ((to_change & REMOVE_TRANSLATION) + && mp->is_fuzzy && !mp->obsolete) + { + unsigned long int nplurals = 0; + char *msgstr; + size_t pos; + + for (pos = 0; pos < mp->msgstr_len; ++pos) + if (!mp->msgstr[pos]) + ++nplurals; + free ((char *) mp->msgstr); + msgstr = XNMALLOC (nplurals, char); + memset (msgstr, '\0', nplurals); + mp->msgstr = msgstr; + mp->msgstr_len = nplurals; + } + mp->is_fuzzy = false; + } /* Always keep the header entry non-obsolete. */ if ((to_change & SET_OBSOLETE) && !is_header (mp)) mp->obsolete = true; diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index 41ab8517f..dd47ea61d 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,9 @@ +2014-05-10 Guido Flohr + + msgattrib: Add --empty option to clear msgstr + * msgattrib-19: New test. + * Makefile.am (TESTS): Add new test. + 2014-05-09 Daiki Ueno vala: Interpret string literals lazily diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 077f32157..7f23f1bc5 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -25,7 +25,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \ msgattrib-1 msgattrib-2 msgattrib-3 msgattrib-4 msgattrib-5 \ msgattrib-6 msgattrib-7 msgattrib-8 msgattrib-9 msgattrib-10 \ msgattrib-11 msgattrib-12 msgattrib-13 msgattrib-14 msgattrib-15 \ - msgattrib-16 msgattrib-17 msgattrib-18 \ + msgattrib-16 msgattrib-17 msgattrib-18 msgattrib-19 \ 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 \ diff --git a/gettext-tools/tests/msgattrib-19 b/gettext-tools/tests/msgattrib-19 new file mode 100755 index 000000000..6c4d60625 --- /dev/null +++ b/gettext-tools/tests/msgattrib-19 @@ -0,0 +1,89 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test --empty option. + +cat <<\EOF > ma-test19.po +# HEADER. +# +msgid "" +msgstr "" +"Project-Id-Version: Bonnie Tyler\n" +"Content-Type: text/plain; charset=ISO-8859-1\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: married-men:4 +#, fuzzy +msgid "The world is full of married men" +msgstr "So viele verheiratete Männer" + +#: married-men:5 +msgid "with wives who never understand" +msgstr "und ihre Frauen verstehen sie nicht" + +#: married-men:6 +msgid "They're looking for someone to share" +msgstr "" + +#, fuzzy, c-format +msgid "One file deleted." +msgid_plural "%u files deleted." +msgstr[0] "Ein Fehler." +msgstr[1] "%u Fehler." + +#~ msgid "You fly on the wings of romance" +#~ msgstr "Die Flügel der frischen Liebe heben dich zum Himmel" + +#, fuzzy +#~ msgid "In the eyes of the world" +#~ msgstr "Für die anderen" +EOF + +: ${MSGATTRIB=msgattrib} +${MSGATTRIB} --clear-fuzzy --empty -o ma-test19.tmp ma-test19.po \ + || exit 1 +LC_ALL=C tr -d '\r' < ma-test19.tmp > ma-test19.out || exit 1 + +cat <<\EOF > ma-test19.ok +# HEADER. +# +msgid "" +msgstr "" +"Project-Id-Version: Bonnie Tyler\n" +"Content-Type: text/plain; charset=ISO-8859-1\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: married-men:4 +msgid "The world is full of married men" +msgstr "" + +#: married-men:5 +msgid "with wives who never understand" +msgstr "und ihre Frauen verstehen sie nicht" + +#: married-men:6 +msgid "They're looking for someone to share" +msgstr "" + +#, c-format +msgid "One file deleted." +msgid_plural "%u files deleted." +msgstr[0] "" +msgstr[1] "" + +#~ msgid "You fly on the wings of romance" +#~ msgstr "Die Flügel der frischen Liebe heben dich zum Himmel" + +#~ msgid "In the eyes of the world" +#~ msgstr "Für die anderen" +EOF + +: ${DIFF=diff} +${DIFF} ma-test19.ok ma-test19.out +result=$? + +cp ma-test19.ok ma-test19.out /tmp + +exit $result