Skip to content
Open
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
2 changes: 2 additions & 0 deletions babel/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ def upgettext(self, context: str, message: str) -> str:
ctxt_message_id = self.CONTEXT_ENCODING % (context, message)
missing = object()
tmsg = self._catalog.get(ctxt_message_id, missing)
if tmsg is missing:
tmsg = self._catalog.get((ctxt_message_id, self.plural(1)), missing)
if tmsg is missing:
if self._fallback:
return self._fallback.upgettext(context, message)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_support_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ def test_upgettext(translations):
assert_equal_type_too('VohCTX', translations.upgettext('foo', 'foo'))


@pytest.mark.parametrize('use_fallback', [False, True])
def test_upgettext_plural_entry(translations, use_fallback):
if use_fallback:
primary = support.Translations()
primary.add_fallback(translations)
translations = primary

expected = translations.pgettext('foo', 'foo1')
assert_equal_type_too('VohCTX1', expected)
assert_equal_type_too(expected, translations.upgettext('foo', 'foo1'))


@pytest.mark.parametrize('method', ['udpgettext', 'dupgettext'])
def test_upgettext_plural_entry_in_domain(translations, method):
expected = translations.dpgettext('messages1', 'foo', 'foo1')
assert_equal_type_too('VohCTXD1', expected)
assert_equal_type_too(expected, getattr(translations, method)('messages1', 'foo', 'foo1'))


@pytest.mark.skipif(SKIP_LGETTEXT, reason='lgettext is deprecated')
def test_lpgettext(translations):
assert_equal_type_too(b'Voh', translations.lgettext('foo'))
Expand Down