]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msgattrib: Add --empty option
authorGuido Flohr <guido@imperia.net>
Thu, 10 Apr 2014 08:40:52 +0000 (17:40 +0900)
committerDaiki Ueno <ueno@gnu.org>
Fri, 9 May 2014 23:32:38 +0000 (08:32 +0900)
gettext-tools/doc/ChangeLog
gettext-tools/doc/msgattrib.texi
gettext-tools/src/ChangeLog
gettext-tools/src/msgattrib.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am
gettext-tools/tests/msgattrib-19 [new file with mode: 0755]

index 79b5e17627ad2aaa2d7e776988b4488a383d8e48..76d0071d9bcc5882d09777b5edc0744fce95442f 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-10  Guido Flohr  <guido@imperia.net>
+
+       msgattrib: Add --empty option to clear msgstr
+       * msgattrib.texi: Document --empty option.
+
 2014-05-05  Daiki Ueno  <ueno@gnu.org>
 
        * gettext.texi (Translations under Version Control): New section.
index 998b8b0627b2f7f761c53ddfc3c94b0d54661b2e..f8951417948a1e4d63e080a14726c91e26376908 100644 (file)
@@ -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}.
index 6832740f2acc89752e561c5a5df754e6e0a575b4..ddf70f3744d7474c820b94c73e726694c954652e 100644 (file)
@@ -1,3 +1,12 @@
+2014-05-10  Guido Flohr  <guido@imperia.net>
+
+       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  <ueno@gnu.org>
 
        vala: Interpret string literals lazily
index 01b6f97f6ec93d272395c281d45936f12780e42b..326f28cacd5fde23dfd766de5e5a49f1ef2e27db 100644 (file)
@@ -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;
index 41ab8517f72c9ea00e38b51fc18ad4b25c4e2f1e..dd47ea61d299057aab861fe1d915956e33be0bb0 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-10  Guido Flohr  <guido@imperia.net>
+
+       msgattrib: Add --empty option to clear msgstr
+       * msgattrib-19: New test.
+       * Makefile.am (TESTS): Add new test.
+
 2014-05-09  Daiki Ueno  <ueno@gnu.org>
 
        vala: Interpret string literals lazily
index 077f3215770bd49e9bd81166a12ab032ff094adc..7f23f1bc5916fe8b6121da3c9935d70681d3ea61 100644 (file)
@@ -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 (executable)
index 0000000..6c4d606
--- /dev/null
@@ -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