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

Skip to content

Make pgettext search plurals when translation is not found #1085

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 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions babel/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,12 @@ def pgettext(self, context: str, message: str) -> str | object:
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 lpgettext(self, context: str, message: str) -> str | bytes | object:
"""Equivalent to ``pgettext()``, but the translation is returned in the
Expand Down
8 changes: 8 additions & 0 deletions tests/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def test_pgettext(self):
self.assertEqualTypeToo('Voh', self.translations.gettext('foo'))
self.assertEqualTypeToo('VohCTX', self.translations.pgettext('foo',
'foo'))
self.assertEqualTypeToo('VohCTX1', self.translations.pgettext('foo',
'foo1'))

def test_pgettext_fallback(self):
fallback = self.translations._fallback
self.translations._fallback = support.NullTranslations()
assert self.translations.pgettext('foo', 'bar') == 'bar'
self.translations._fallback = fallback

def test_upgettext(self):
self.assertEqualTypeToo('Voh', self.translations.ugettext('foo'))
Expand Down
0