Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ambv merged 4 commits intopython:mainfromgbassiere:fix-issue-18319
Jul 23, 2023

Conversation

@gbassiere
Copy link
Contributor

@gbassieregbassiere commentedMay 2, 2020
edited by bedevere-bot
Loading

Let's say you have this in your code:

gettext('egg')

and elsewhere this :

ngettext('egg', 'eggs', n)

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:

catalog['egg']

whereas a pluralized 'egg' is stored as:

catalog[('egg', 0)]catalog[('eggs', 1)]

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 modifygettext() so that is looks forcatalog[('egg', 0)] ifcatalog['egg'] didn't match.

https://bugs.python.org/issue18319

fdemmer and m-aciek reacted with thumbs up emoji
@the-knights-who-say-ni

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 thePSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find abugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@gbassiere

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 followthe steps outlined in the CPython devguide to rectify this issue.

You cancheck yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

returnmessage
try:
# if `message` has plural forms
tmsg=self._catalog[(message,self.plural(1))]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
tmsg=self._catalog[(message,self.plural(1))]
returnself._catalog[(message,self.plural(1))]

ifself._fallback:
returnself._fallback.gettext(message)
returnmessage
try:
Copy link
Contributor

@taleinattaleinatOct 18, 2020
edited
Loading

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 existingif tmsg is missing: ... block:

iftmsgismissing:tmsg=self._catalog.get((message,self.plural(1)),missing)

@ThiefMaster
Copy link

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
Copy link
Contributor

Should this logic be also added topgettext() ?

tomasr8 reacted with thumbs up emoji

@ambvambv merged commit5463252 intopython:mainJul 23, 2023
@ambvambv added needs backport to 3.11only security fixes needs backport to 3.12only security fixes labelsJul 23, 2023
@miss-islington
Copy link
Contributor

Thanks@gbassiere for the PR, and@ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks@gbassiere for the PR, and@ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-107107 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelJul 23, 2023
@bedevere-bot
Copy link

GH-107108 is a backport of this pull request to the3.12 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.12only security fixes labelJul 23, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJul 23, 2023
…sts (pythonGH-19869)(cherry picked from commit5463252)Co-authored-by: Gilles Bassière <gbassiere@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJul 23, 2023
…sts (pythonGH-19869)(cherry picked from commit5463252)Co-authored-by: Gilles Bassière <gbassiere@gmail.com>
ambv pushed a commit that referenced this pull requestJul 23, 2023
…orm exists (GH-19869) (#107108)(cherry picked from commit5463252)Co-authored-by: Gilles Bassière <gbassiere@gmail.com>
jtcave pushed a commit to jtcave/cpython that referenced this pull requestJul 23, 2023
mementum pushed a commit to mementum/cpython that referenced this pull requestJul 23, 2023
serhiy-storchaka pushed a commit that referenced this pull requestAug 16, 2023
…orm exists (GH-19869) (GH-107107)(cherry picked from commit5463252)Co-authored-by: Gilles Bassière <gbassiere@gmail.com>
m-aciek added a commit to m-aciek/attributivegettext that referenced this pull requestFeb 16, 2024
Afterpython/cpython#19869 PR merged gettext() can lookup plural() which is not set when constructor argument (file handler) is unspecified
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@taleinattaleinattaleinat left review comments

+1 more reviewer

@remilapeyreremilapeyreremilapeyre approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

10 participants

@gbassiere@the-knights-who-say-ni@ThiefMaster@akulakov@miss-islington@bedevere-bot@taleinat@remilapeyre@ambv@ezio-melotti

[8]ページ先頭

©2009-2025 Movatter.jp