]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-62519: Make pgettext search plurals when translation is not found (GH-10711...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 25 Jul 2023 18:49:28 +0000 (11:49 -0700)
committerGitHub <noreply@github.com>
Tue, 25 Jul 2023 18:49:28 +0000 (21:49 +0300)
(cherry picked from commit b3c34e55c053846beb35f5e4253ef237b3494bd0)

Co-authored-by: Tomas R <tomas.roun8@gmail.com>
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Lib/gettext.py
Lib/test/test_gettext.py
Misc/NEWS.d/next/Library/2023-07-23-12-26-23.gh-issue-62519.w8-81X.rst [new file with mode: 0644]

index 6c5ec4e517f63728232e7d4ddefb5a7fb72fa4c7..57f1a449c28a43e56cb0a3e0b0899a0440a37004 100644 (file)
@@ -444,10 +444,12 @@ class GNUTranslations(NullTranslations):
         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)
index 1608d1b18e98fb6e64d815145da3b2a3b79f1c5a..7f7b51c19f35c77a302e0e5de0ea7e758dd21dc1 100644 (file)
@@ -329,6 +329,8 @@ class PluralFormsTestCase(GettextBaseTest):
         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
@@ -349,6 +351,8 @@ class PluralFormsTestCase(GettextBaseTest):
         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
 
diff --git a/Misc/NEWS.d/next/Library/2023-07-23-12-26-23.gh-issue-62519.w8-81X.rst b/Misc/NEWS.d/next/Library/2023-07-23-12-26-23.gh-issue-62519.w8-81X.rst
new file mode 100644 (file)
index 0000000..96e2a3d
--- /dev/null
@@ -0,0 +1,2 @@
+Make :func:`gettext.pgettext` search plural definitions when
+translation is not found.