Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41756e3

Browse files
miss-islingtontomasr8ambv
authored
[3.11] gh-62519: Make pgettext search plurals when translation is not found (GH-107118) (GH-107133)
(cherry picked from commit b3c34e5) Co-authored-by: Tomas R <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
1 parent 012bc13 commit 41756e3

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Lib/gettext.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,12 @@ def pgettext(self, context, message):
444444
missing = object()
445445
tmsg = self._catalog.get(ctxt_msg_id, missing)
446446
if tmsg is missing:
447-
if self._fallback:
448-
return self._fallback.pgettext(context, message)
449-
return message
450-
return tmsg
447+
tmsg = self._catalog.get((ctxt_msg_id, self.plural(1)), missing)
448+
if tmsg is not missing:
449+
return tmsg
450+
if self._fallback:
451+
return self._fallback.pgettext(context, message)
452+
return message
451453

452454
def npgettext(self, context, msgid1, msgid2, n):
453455
ctxt_msg_id = self.CONTEXT % (context, msgid1)

Lib/test/test_gettext.py

+4
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ def test_plural_context_forms1(self):
329329
x = gettext.npgettext('With context',
330330
'There is %s file', 'There are %s files', 2)
331331
eq(x, 'Hay %s ficheros (context)')
332+
x = gettext.pgettext('With context', 'There is %s file')
333+
eq(x, 'Hay %s fichero (context)')
332334

333335
def test_plural_forms2(self):
334336
eq = self.assertEqual
@@ -349,6 +351,8 @@ def test_plural_context_forms2(self):
349351
x = t.npgettext('With context',
350352
'There is %s file', 'There are %s files', 2)
351353
eq(x, 'Hay %s ficheros (context)')
354+
x = gettext.pgettext('With context', 'There is %s file')
355+
eq(x, 'Hay %s fichero (context)')
352356

353357
# Examples from http://www.gnu.org/software/gettext/manual/gettext.html
354358

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make :func:`gettext.pgettext` search plural definitions when
2+
translation is not found.

0 commit comments

Comments
 (0)