From 00a36671e36c366deb726a1905a1386f6b749552 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sun, 23 Jul 2023 12:21:58 +0200 Subject: [PATCH 1/3] Make pgettext search plurals when translation is not found --- Lib/gettext.py | 10 ++++++---- Lib/test/test_gettext.py | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Lib/gettext.py b/Lib/gettext.py index cc938e40028c24..b72b15f82d4355 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -446,10 +446,12 @@ def pgettext(self, context, message): 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) diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index aa3520d2c142e4..8430fc234d00ee 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -331,6 +331,8 @@ def test_plural_context_forms1(self): 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 @@ -353,6 +355,8 @@ def test_plural_context_forms2(self): 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 From ee6d3b815b0f04076da2e39664508f4f0c0b6b5c Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sun, 23 Jul 2023 12:27:54 +0200 Subject: [PATCH 2/3] Add changelog --- .../next/Library/2023-07-23-12-26-23.gh-issue-62519.w8-81X.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-07-23-12-26-23.gh-issue-62519.w8-81X.rst 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 index 00000000000000..1959e235ddfaf6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-07-23-12-26-23.gh-issue-62519.w8-81X.rst @@ -0,0 +1,2 @@ +Make pgettext :func:`gettext.pgettext` search plural definitions when +translation is not found. From 4c9f6dad7df43f26dec1d1c91e8950f4cd1b857a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Sun, 23 Jul 2023 15:20:22 +0200 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2023-07-23-12-26-23.gh-issue-62519.w8-81X.rst --- .../next/Library/2023-07-23-12-26-23.gh-issue-62519.w8-81X.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 1959e235ddfaf6..96e2a3dcc24fb0 100644 --- 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 @@ -1,2 +1,2 @@ -Make pgettext :func:`gettext.pgettext` search plural definitions when +Make :func:`gettext.pgettext` search plural definitions when translation is not found.