Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-62519: Make pgettext search plurals when translation is not found#107118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ambv merged 3 commits intopython:mainfromtomasr8:pgettext-bugfix
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Make pgettext search plurals when translation is not found
  • Loading branch information
@tomasr8
tomasr8 committedJul 23, 2023
commit00a36671e36c366deb726a1905a1386f6b749552
10 changes: 6 additions & 4 deletionsLib/gettext.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
4 changes: 4 additions & 0 deletionsLib/test/test_gettext.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand All@@ -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

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp