https://github.com/python/cpython/commit/321bf595121f9327368af8bf5e850d9d145360c2 commit: 321bf595121f9327368af8bf5e850d9d145360c2 branch: main author: Tomas R. <tomas.ro...@gmail.com> committer: serhiy-storchaka <storch...@gmail.com> date: 2025-03-03T18:57:01+02:00 summary:
gh-130453: pygettext: Allow overriding default keywords when using `--keyword` (GH-130709) files: A Misc/NEWS.d/next/Tools-Demos/2025-02-28-23-24-03.gh-issue-130453.EK0Vk_.rst M Lib/test/test_tools/i18n_data/custom_keywords.pot M Lib/test/test_tools/i18n_data/custom_keywords.py M Lib/test/test_tools/test_i18n.py M Tools/i18n/pygettext.py diff --git a/Lib/test/test_tools/i18n_data/custom_keywords.pot b/Lib/test/test_tools/i18n_data/custom_keywords.pot index 48df2e7f579cc7..03a9cba3a20b16 100644 --- a/Lib/test/test_tools/i18n_data/custom_keywords.pot +++ b/Lib/test/test_tools/i18n_data/custom_keywords.pot @@ -15,31 +15,37 @@ msgstr "" "Generated-By: pygettext.py 1.5\n" -#: custom_keywords.py:9 custom_keywords.py:10 +#: custom_keywords.py:10 custom_keywords.py:11 msgid "bar" msgstr "" -#: custom_keywords.py:12 +#: custom_keywords.py:13 msgid "cat" msgid_plural "cats" msgstr[0] "" msgstr[1] "" -#: custom_keywords.py:13 +#: custom_keywords.py:14 msgid "dog" msgid_plural "dogs" msgstr[0] "" msgstr[1] "" -#: custom_keywords.py:15 +#: custom_keywords.py:16 msgctxt "context" msgid "bar" msgstr "" -#: custom_keywords.py:17 +#: custom_keywords.py:18 msgctxt "context" msgid "cat" msgid_plural "cats" msgstr[0] "" msgstr[1] "" +#: custom_keywords.py:34 +msgid "overridden" +msgid_plural "default" +msgstr[0] "" +msgstr[1] "" + diff --git a/Lib/test/test_tools/i18n_data/custom_keywords.py b/Lib/test/test_tools/i18n_data/custom_keywords.py index 01ea56c348cb55..ba0ffe77180478 100644 --- a/Lib/test/test_tools/i18n_data/custom_keywords.py +++ b/Lib/test/test_tools/i18n_data/custom_keywords.py @@ -4,6 +4,7 @@ pgettext as pfoo, npgettext as npfoo, gettext as bar, + gettext as _, ) foo('bar') @@ -28,3 +29,6 @@ # 'npfoo' requires at least 3 arguments npfoo('context') npfoo('context', 'cat') + +# --keyword should override the default keyword +_('overridden', 'default') diff --git a/Lib/test/test_tools/test_i18n.py b/Lib/test/test_tools/test_i18n.py index d73fcff4c9cb11..2ba086109d30ab 100644 --- a/Lib/test/test_tools/test_i18n.py +++ b/Lib/test/test_tools/test_i18n.py @@ -525,7 +525,7 @@ def extract_from_snapshots(): 'comments.py': ('--add-comments=i18n:',), 'custom_keywords.py': ('--keyword=foo', '--keyword=nfoo:1,2', '--keyword=pfoo:1c,2', - '--keyword=npfoo:1c,2,3'), + '--keyword=npfoo:1c,2,3', '--keyword=_:1,2'), } for filename, args in snapshots.items(): diff --git a/Misc/NEWS.d/next/Tools-Demos/2025-02-28-23-24-03.gh-issue-130453.EK0Vk_.rst b/Misc/NEWS.d/next/Tools-Demos/2025-02-28-23-24-03.gh-issue-130453.EK0Vk_.rst new file mode 100644 index 00000000000000..684fd9ab0c3455 --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2025-02-28-23-24-03.gh-issue-130453.EK0Vk_.rst @@ -0,0 +1 @@ +Make it possible to override default keywords in :program:`pygettext`. diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py index 0f5f32c7d6c18f..0ec257020918b1 100755 --- a/Tools/i18n/pygettext.py +++ b/Tools/i18n/pygettext.py @@ -729,12 +729,15 @@ class Options: # calculate all keywords try: - options.keywords = dict(parse_spec(spec) for spec in options.keywords) + custom_keywords = dict(parse_spec(spec) for spec in options.keywords) except ValueError as e: print(e, file=sys.stderr) sys.exit(1) + options.keywords = {} if not no_default_keywords: options.keywords |= DEFAULTKEYWORDS + # custom keywords override default keywords + options.keywords |= custom_keywords # initialize list of strings to exclude if options.excludefilename: _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com