-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-130453: pygettext: Extend support for specifying custom keywords #130463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
74b0235
Support custom keywords
tomasr8 619cad5
Add news entry
tomasr8 184232e
PEP8
tomasr8 4dd889b
Remove whitespace
tomasr8 6a46ce7
Remove trailing whitespace
tomasr8 bb50cfe
Simplify code
tomasr8 83a21e0
Revert making keywords a set
tomasr8 d861c84
Simplify 'parse_spec'
tomasr8 18d29cb
Use print+sys.exit for consistency
tomasr8 a3ef55b
Revert changes to parse_spec
tomasr8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # SOME DESCRIPTIVE TITLE. | ||
| # Copyright (C) YEAR ORGANIZATION | ||
| # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: PACKAGE VERSION\n" | ||
| "POT-Creation-Date: 2000-01-01 00:00+0000\n" | ||
| "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
| "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
| "Language-Team: LANGUAGE <[email protected]>\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Generated-By: pygettext.py 1.5\n" | ||
|
|
||
|
|
||
| #: custom_keywords.py:9 custom_keywords.py:10 | ||
| msgid "bar" | ||
| msgstr "" | ||
|
|
||
| #: custom_keywords.py:12 | ||
| msgid "cat" | ||
| msgid_plural "cats" | ||
| msgstr[0] "" | ||
| msgstr[1] "" | ||
|
|
||
| #: custom_keywords.py:13 | ||
| msgid "dog" | ||
| msgid_plural "dogs" | ||
| msgstr[0] "" | ||
| msgstr[1] "" | ||
|
|
||
| #: custom_keywords.py:15 | ||
| msgctxt "context" | ||
| msgid "bar" | ||
| msgstr "" | ||
|
|
||
| #: custom_keywords.py:17 | ||
| msgctxt "context" | ||
| msgid "cat" | ||
| msgid_plural "cats" | ||
| msgstr[0] "" | ||
| msgstr[1] "" | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from gettext import ( | ||
| gettext as foo, | ||
| ngettext as nfoo, | ||
| pgettext as pfoo, | ||
| npgettext as npfoo, | ||
| gettext as bar, | ||
| ) | ||
|
|
||
| foo('bar') | ||
| foo('bar', 'baz') | ||
|
|
||
| nfoo('cat', 'cats', 1) | ||
| nfoo('dog', 'dogs') | ||
|
|
||
| pfoo('context', 'bar') | ||
|
|
||
| npfoo('context', 'cat', 'cats', 1) | ||
|
|
||
| # This is an unknown keyword and should be ignored | ||
| bar('baz') | ||
|
|
||
| # 'nfoo' requires at least 2 arguments | ||
| nfoo('dog') | ||
|
|
||
| # 'pfoo' requires at least 2 arguments | ||
| pfoo('context') | ||
|
|
||
| # 'npfoo' requires at least 3 arguments | ||
| npfoo('context') | ||
| npfoo('context', 'cat') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Tools-Demos/2025-02-22-18-08-35.gh-issue-130453.njRXG8.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Extend support for specifying custom keywords in :program:`pygettext`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other errors cause
print()+sys.exit(1).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, though I believe
raise SystemExit(s)is functionally equivalent toprint(..., file=sys.stderr)+sys.exit(1)and since it's shorter and the intent is clearer, I thought I'd start using that instead.Though if you prefer to be consistent, I can change it to
print+sys.exit?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it just for consistency (also,
sys.exit()allows to set different return codes, but this is not used here).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 18d29cb to use
print+sys.exit