mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-18319: gettext() can retrieve a message even if a plural form exists (#19869)
This commit is contained in:
parent
a2a0e51400
commit
54632528ee
3 changed files with 12 additions and 4 deletions
|
@ -422,10 +422,12 @@ class GNUTranslations(NullTranslations):
|
||||||
missing = object()
|
missing = object()
|
||||||
tmsg = self._catalog.get(message, missing)
|
tmsg = self._catalog.get(message, missing)
|
||||||
if tmsg is missing:
|
if tmsg is missing:
|
||||||
if self._fallback:
|
tmsg = self._catalog.get((message, self.plural(1)), missing)
|
||||||
return self._fallback.gettext(message)
|
if tmsg is not missing:
|
||||||
return message
|
return tmsg
|
||||||
return tmsg
|
if self._fallback:
|
||||||
|
return self._fallback.gettext(message)
|
||||||
|
return message
|
||||||
|
|
||||||
def ngettext(self, msgid1, msgid2, n):
|
def ngettext(self, msgid1, msgid2, n):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -320,6 +320,8 @@ class PluralFormsTestCase(GettextBaseTest):
|
||||||
eq(x, 'Hay %s fichero')
|
eq(x, 'Hay %s fichero')
|
||||||
x = gettext.ngettext('There is %s file', 'There are %s files', 2)
|
x = gettext.ngettext('There is %s file', 'There are %s files', 2)
|
||||||
eq(x, 'Hay %s ficheros')
|
eq(x, 'Hay %s ficheros')
|
||||||
|
x = gettext.gettext('There is %s file')
|
||||||
|
eq(x, 'Hay %s fichero')
|
||||||
|
|
||||||
def test_plural_context_forms1(self):
|
def test_plural_context_forms1(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
|
@ -338,6 +340,8 @@ class PluralFormsTestCase(GettextBaseTest):
|
||||||
eq(x, 'Hay %s fichero')
|
eq(x, 'Hay %s fichero')
|
||||||
x = t.ngettext('There is %s file', 'There are %s files', 2)
|
x = t.ngettext('There is %s file', 'There are %s files', 2)
|
||||||
eq(x, 'Hay %s ficheros')
|
eq(x, 'Hay %s ficheros')
|
||||||
|
x = t.gettext('There is %s file')
|
||||||
|
eq(x, 'Hay %s fichero')
|
||||||
|
|
||||||
def test_plural_context_forms2(self):
|
def test_plural_context_forms2(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Ensure `gettext(msg)` retrieve translations even if a plural form exists. In
|
||||||
|
other words: `gettext(msg) == ngettext(msg, '', 1)`.
|
Loading…
Add table
Add a link
Reference in a new issue