Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
bpo-18319: gettext() can retrieve a message even if a plural form exists#19869
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
gbassiere commented May 2, 2020 • edited by bedevere-bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-bot
Uh oh!
There was an error while loading. Please reload this page.
the-knights-who-say-ni commented May 2, 2020
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). Recognized GitHub usernameWe couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames: This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
Lib/gettext.py Outdated
| returnmessage | ||
| try: | ||
| # if `message` has plural forms | ||
| tmsg=self._catalog[(message, self.plural(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.
| tmsg=self._catalog[(message, self.plural(1))] | |
| returnself._catalog[(message, self.plural(1))] |
Lib/gettext.py Outdated
| ifself._fallback: | ||
| returnself._fallback.gettext(message) | ||
| returnmessage | ||
| try: |
taleinatOct 18, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
I suggest simply adding the following before the existing if tmsg is missing: ... block:
iftmsgismissing: tmsg=self._catalog.get((message, self.plural(1)), missing)ThiefMaster commented Jul 13, 2021
Just noticed this annoying bug as well (via babel). It's impossible to work around without starting to mess around with message contexts (and I should NOT need to add garbage to my code (and pot files) because of this), so it would be great if this fix could get merged.. |
akulakov commented Aug 6, 2021
Should this logic be also added to |
miss-islington commented Jul 23, 2023
Thanks @gbassiere for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
miss-islington commented Jul 23, 2023
Thanks @gbassiere for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
bedevere-bot commented Jul 23, 2023
GH-107107 is a backport of this pull request to the 3.11 branch. |
bedevere-bot commented Jul 23, 2023
GH-107108 is a backport of this pull request to the 3.12 branch. |
…sts (pythonGH-19869) (cherry picked from commit 5463252) Co-authored-by: Gilles Bassière <gbassiere@gmail.com>
…sts (pythonGH-19869) (cherry picked from commit 5463252) Co-authored-by: Gilles Bassière <gbassiere@gmail.com>
After python/cpython#19869 PR merged gettext() can lookup plural() which is not set when constructor argument (file handler) is unspecified
Let's say you have this in your code:
and elsewhere this :
GNU gettext tools extracts these as the same unique message and sensibly creates a pluralized entry in the PO file.
In the Python gettext module, when the MO file is parsed, a singular 'egg' will be stored as:
whereas a pluralized 'egg' is stored as:
As a consequence,
gettext('egg')fail to retrieve translations and you have to resort tongettext('egg', 'eggs', 1)which is odd.My suggestion is simply to modify
gettext()so that is looks forcatalog[('egg', 0)]ifcatalog['egg']didn't match.https://bugs.python.org/issue18319