From: Bruno Haible Date: Wed, 25 Jun 2025 02:16:09 +0000 (+0200) Subject: xgettext: Shell: Recognize printf_gettext, printf_ngettext invocations. X-Git-Tag: v0.26~59 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f0bdc7524e67d9747dd8b8f4b28ea79bb299ccd5;p=thirdparty%2Fgettext.git xgettext: Shell: Recognize printf_gettext, printf_ngettext invocations. * 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. --- diff --git a/gettext-tools/doc/xgettext.texi b/gettext-tools/doc/xgettext.texi index c2363a356..72063c226 100644 --- a/gettext-tools/doc/xgettext.texi +++ b/gettext-tools/doc/xgettext.texi @@ -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}, diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index 86fc2083c..9b7249fa7 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -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) diff --git a/gettext-tools/tests/xgettext-sh-1 b/gettext-tools/tests/xgettext-sh-1 index 1429d2fd7..2b0fa3adf 100755 --- a/gettext-tools/tests/xgettext-sh-1 +++ b/gettext-tools/tests/xgettext-sh-1 @@ -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 ""