]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Shell: Recognize printf_gettext, printf_ngettext invocations.
authorBruno Haible <bruno@clisp.org>
Wed, 25 Jun 2025 02:16:09 +0000 (04:16 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 25 Jun 2025 02:16:09 +0000 (04:16 +0200)
* gettext-tools/src/x-sh.c (init_keywords, init_flag_table_sh): Add knowledge
about printf_gettext and printf_ngettext.
(read_command): Recognize '-c' option of printf_gettext and printf_ngettext.
* gettext-tools/tests/xgettext-sh-1: Add test cases with printf_gettext and
printf_ngettext.
* gettext-tools/doc/xgettext.texi: Document it.

gettext-tools/doc/xgettext.texi
gettext-tools/src/x-sh.c
gettext-tools/tests/xgettext-sh-1

index c2363a3565d9d340e8f72f155d8b5217dee80fb2..72063c22644cfce36b4159609b03b0b0dc95a09d 100644 (file)
@@ -359,9 +359,11 @@ For Objective C: Like for C, and also @code{NSLocalizedString}, @code{_},
 @code{NSLocalizedStaticString}, @code{__}.
 
 @item
-For Shell scripts: @code{gettext}, @code{ngettext:1,2}, @code{eval_gettext},
-@code{eval_ngettext:1,2}, @code{eval_pgettext:1c,2},
-@code{eval_npgettext:1c,2,3}.
+For Shell scripts:
+@code{gettext}, @code{ngettext:1,2},
+@code{printf_gettext}, @code{printf_ngettext:1,2},
+@code{eval_gettext}, @code{eval_ngettext:1,2},
+@code{eval_pgettext:1c,2}, @code{eval_npgettext:1c,2,3}.
 
 @item
 For Python: @code{gettext}, @code{ugettext}, @code{dgettext:2},
index 86fc2083cdc247845fd62c16a143a1b9012a978f..9b7249fa7464d015fea6b75795a36cb931173d79 100644 (file)
@@ -124,6 +124,8 @@ init_keywords ()
          xgettext.texi!  */
       x_sh_keyword ("gettext");
       x_sh_keyword ("ngettext:1,2");
+      x_sh_keyword ("printf_gettext");
+      x_sh_keyword ("printf_ngettext:1,2");
       /* Note: There is also special handling for 'gettext' and 'ngettext'
          in read_command, below.  */
       x_sh_keyword ("eval_gettext");
@@ -150,6 +152,9 @@ init_flag_table_sh ()
   xgettext_record_flag ("eval_npgettext:2:sh-format");
   xgettext_record_flag ("eval_npgettext:3:sh-format");
   xgettext_record_flag ("printf:1:sh-printf-format");
+  xgettext_record_flag ("printf_gettext:1:sh-printf-format");
+  xgettext_record_flag ("printf_ngettext:1:sh-printf-format");
+  xgettext_record_flag ("printf_ngettext:2:sh-printf-format");
 }
 
 
@@ -1395,7 +1400,11 @@ read_command (int looking_for, flag_region_ty *outer_region)
                     ((argparser->keyword_len == 7
                       && memcmp (argparser->keyword, "gettext", 7) == 0)
                      || (argparser->keyword_len == 8
-                         && memcmp (argparser->keyword, "ngettext", 8) == 0));
+                         && memcmp (argparser->keyword, "ngettext", 8) == 0)
+                     || (argparser->keyword_len == 14
+                         && memcmp (argparser->keyword, "printf_gettext", 14) == 0)
+                     || (argparser->keyword_len == 15
+                         && memcmp (argparser->keyword, "printf_ngettext", 15) == 0));
                   bool accepts_expand =
                     ((argparser->keyword_len == 7
                       && memcmp (argparser->keyword, "gettext", 7) == 0)
index 1429d2fd738d93bb163c21031ee3f5b7bfe723da..2b0fa3adfa553b4a1809cf74494316ebcf61b061 100755 (executable)
@@ -499,6 +499,10 @@ echo `echo \`gettext $'depth_2_dollar_bash_0_\Eab'\``
 
 printf "`gettext 'User name: %s\nUser ID: %u'`"'\n' "$USER" `id -u`
 
+printf_gettext 'User name: %s\nUser id: %u\n' "$USER" `id -u`
+
+printf_ngettext 'Delete the file?' 'Delete %u files?' $n $n
+
 # Test string concatenation.
 
 gettext "concat_0_""part2"
@@ -1927,6 +1931,16 @@ msgstr ""
 msgid "User name: %s\\nUser ID: %u"
 msgstr ""
 
+#, sh-printf-format
+msgid "User name: %s\\nUser id: %u\\n"
+msgstr ""
+
+#, sh-printf-format
+msgid "Delete the file?"
+msgid_plural "Delete %u files?"
+msgstr[0] ""
+msgstr[1] ""
+
 msgid "concat_0_part2"
 msgstr ""