GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-18319: gettext() can retrieve a message even if a plural form exists by gbassiere · Pull Request #19869 · python/cpython

Conversation

@gbassiere

@gbassiere gbassiere commented May 2, 2020 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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 to ngettext('egg', 'eggs', 1) which is odd.

My suggestion is simply to modify gettext() so that is looks for catalog[('egg', 0)] if catalog['egg'] didn't match.

https://bugs.python.org/issue18319

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

fdemmer and m-aciek reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@gbassiere
Issue python#18319: gettext() can retrieve a message even if a plural…
9be6e67
… form exists
@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label May 2, 2020
@the-knights-who-say-ni

the-knights-who-say-ni commented May 2, 2020

Copy link
Copy Markdown

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 username

We couldn't find a bugs.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 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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added the awaiting review label May 2, 2020
@gbassiere
Add missing Misc/NEWS.d
26b8f1c
@the-knights-who-say-ni the-knights-who-say-ni added CLA signed and removed CLA not signed labels May 4, 2020
remilapeyre
remilapeyre approved these changes Jun 9, 2020
View reviewed changes
Comment thread Lib/gettext.py Outdated
return message
try:
# if `message` has plural forms
tmsg = self._catalog[(message, self.plural(1))]

@remilapeyre remilapeyre Jun 9, 2020

Copy link
Copy Markdown
Contributor

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting core review and removed awaiting review labels Jun 9, 2020
taleinat
taleinat reviewed Oct 18, 2020
View reviewed changes
Comment thread Lib/gettext.py Outdated
if self._fallback:
return self._fallback.gettext(message)
return message
try:

@taleinat taleinat Oct 18, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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:

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ThiefMaster

ThiefMaster commented Jul 13, 2021

Copy link
Copy Markdown

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..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@akulakov

akulakov commented Aug 6, 2021

Copy link
Copy Markdown
Contributor

Should this logic be also added to pgettext() ?

tomasr8 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jwilk jwilk mannequin mentioned this pull request Apr 10, 2022
gettext() cannot find translations with plural forms #62519
Closed
@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
ambv added 2 commits July 23, 2023 10:02
@ambv
Merge branch 'main' into fix-issue-18319
56e9467
@ambv
Code golf
e120d70
@ambv
ambv merged commit 5463252 into python:main Jul 23, 2023
@bedevere-bot bedevere-bot removed the awaiting core review label Jul 23, 2023
@ambv ambv added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jul 23, 2023
@miss-islington

miss-islington commented Jul 23, 2023

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Jul 23, 2023

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Jul 23, 2023

Copy link
Copy Markdown

GH-107107 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jul 23, 2023
@bedevere-bot

bedevere-bot commented Jul 23, 2023

Copy link
Copy Markdown

GH-107108 is a backport of this pull request to the 3.12 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Jul 23, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 23, 2023
@gbassiere @miss-islington
bpo-18319: gettext() can retrieve a message even if a plural form exi…
d6ee79f
…sts (pythonGH-19869)

(cherry picked from commit 5463252)

Co-authored-by: Gilles Bassière <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 23, 2023
@gbassiere @miss-islington
bpo-18319: gettext() can retrieve a message even if a plural form exi…
9b83253
…sts (pythonGH-19869)

(cherry picked from commit 5463252)

Co-authored-by: Gilles Bassière <[email protected]>
ambv pushed a commit that referenced this pull request Jul 23, 2023
@miss-islington @gbassiere
[3.12] bpo-18319: gettext() can retrieve a message even if a plural f…
bd72fb1
…orm exists (GH-19869) (#107108)

(cherry picked from commit 5463252)

Co-authored-by: Gilles Bassière <[email protected]>
jtcave pushed a commit to jtcave/cpython that referenced this pull request Jul 23, 2023
@gbassiere @jtcave
bpo-18319: gettext() can retrieve a message even if a plural form exi…
433de75
…sts (python#19869)
mementum pushed a commit to mementum/cpython that referenced this pull request Jul 23, 2023
@gbassiere @mementum
bpo-18319: gettext() can retrieve a message even if a plural form exi…
75ca15b
…sts (python#19869)
serhiy-storchaka pushed a commit that referenced this pull request Aug 16, 2023
@miss-islington @gbassiere
[3.11] bpo-18319: gettext() can retrieve a message even if a plural f…
c1c3f0b
…orm exists (GH-19869) (GH-107107)

(cherry picked from commit 5463252)

Co-authored-by: Gilles Bassière <[email protected]>
m-aciek added a commit to m-aciek/attributivegettext that referenced this pull request Feb 16, 2024
@m-aciek
Fix tests for Python 3.11+
e397ae7
After python/cpython#19869 PR merged gettext() can lookup plural() which is not set when constructor argument (file handler) is unspecified
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers
@taleinat taleinat taleinat left review comments
@remilapeyre remilapeyre remilapeyre approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@gbassiere @the-knights-who-say-ni @ThiefMaster @akulakov @miss-islington @bedevere-bot @taleinat @remilapeyre @ambv @ezio-melotti
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.