[3.11] bpo-18319: gettext() can retrieve a message even if a plural form exists (GH-19869) (GH-107107)

(cherry picked from commit 54632528ee)

Co-authored-by: Gilles Bassière <gbassiere@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-08-16 02:15:01 -07:00 committed by GitHub
parent 26137e2cf7
commit c1c3f0bfec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

@ -422,10 +422,12 @@ class GNUTranslations(NullTranslations):
missing = object()
tmsg = self._catalog.get(message, missing)
if tmsg is missing:
if self._fallback:
return self._fallback.gettext(message)
return message
return tmsg
tmsg = self._catalog.get((message, self.plural(1)), missing)
if tmsg is not missing:
return tmsg
if self._fallback:
return self._fallback.gettext(message)
return message
def ngettext(self, msgid1, msgid2, n):
try:

View file

@ -320,6 +320,8 @@ class PluralFormsTestCase(GettextBaseTest):
eq(x, 'Hay %s fichero')
x = gettext.ngettext('There is %s file', 'There are %s files', 2)
eq(x, 'Hay %s ficheros')
x = gettext.gettext('There is %s file')
eq(x, 'Hay %s fichero')
def test_plural_context_forms1(self):
eq = self.assertEqual
@ -340,6 +342,8 @@ class PluralFormsTestCase(GettextBaseTest):
eq(x, 'Hay %s fichero')
x = t.ngettext('There is %s file', 'There are %s files', 2)
eq(x, 'Hay %s ficheros')
x = t.gettext('There is %s file')
eq(x, 'Hay %s fichero')
def test_plural_context_forms2(self):
eq = self.assertEqual

View file

@ -0,0 +1,2 @@
Ensure ``gettext(msg)`` retrieve translations even if a plural form exists. In
other words: ``gettext(msg) == ngettext(msg, '', 1)``.