8000 gh-62519: Make pgettext search plurals when translation is not found by tomasr8 · Pull Request #107118 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-62519: Make pgettext search plurals when translation is not found #107118

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 3 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make pgettext search plurals when translation is not found
  • Loading branch information
tomasr8 committed Jul 23, 2023
commit 00a36671e36c366deb726a1905a1386f6b749552
10 changes: 6 additions & 4 deletions Lib/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,12 @@ def pgettext(self, context, message):
missing = object()
tmsg = self._catalog.get(ctxt_msg_id, missing)
if tmsg is missing:
if self._fallback:
return self._fallback.pgettext(context, message)
return message
return tmsg
tmsg = self._catalog.get((ctxt_msg_id, self.plural(1)), missing)
if tmsg is not missing:
return tmsg
if self._fallback:
return self._fallback.pgettext(context, message)
return message

def npgettext(self, context, msgid1, msgid2, n):
ctxt_msg_id = self.CONTEXT % (context, msgid1)
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def test_plural_context_forms1(self):
x = gettext.npgettext('With context',
'There is %s file', 'There are %s files', 2)
eq(x, 'Hay %s ficheros (context)')
x = gettext.pgettext('With context', 'There is %s file')
eq(x, 'Hay %s fichero (context)')

def test_plural_forms2(self):
eq = self.assertEqual
Expand All @@ -353,6 +355,8 @@ def test_plural_context_forms2(self):
x = t.npgettext('With context',
'There is %s file', 'There are %s files', 2)
eq(x, 'Hay %s ficheros (context)')
x = gettext.pgettext('With context', 'There is %s file')
eq(x, 'Hay %s fichero (context)')

# Examples from http://www.gnu.org/software/gettext/manual/gettext.html

Expand Down
0