Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
1 change: 1 addition & 0 deletions Lib/test/test_tools/msgfmt_data/fuzzy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
58 changes: 58 additions & 0 deletions Lib/test/test_tools/msgfmt_data/general.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
[
"",
"Project-Id-Version: PACKAGE VERSION\nPOT-Creation-Date: 2024-10-26 18:06+0200\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\nLast-Translator: FULL NAME <EMAIL@ADDRESS>\nLanguage-Team: LANGUAGE <[email protected]>\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n"
],
[
"\n newlines \n",
"\n translated \n"
],
[
"\"escapes\"",
"\"translated\""
],
[
"Multilinestring",
"Multilinetranslation"
],
[
[
"One email sent.",
0
],
"One email sent."
],
[
[
"One email sent.",
1
],
"%d emails sent."
],
[
[
"abc\u0004One email sent.",
0
],
"One email sent."
],
[
[
"abc\u0004One email sent.",
1
],
"%d emails sent."
],
[
"abc\u0004foo",
"bar"
],
[
"bar",
"baz"
],
[
"xyz\u0004foo",
"bar"
]
]
Binary file modified Lib/test/test_tools/msgfmt_data/general.mo
Binary file not shown.
10 changes: 10 additions & 0 deletions Lib/test/test_tools/test_msgfmt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for the Tools/i18n/msgfmt.py tool."""

import json
import sys
import unittest
from gettext import GNUTranslations
Expand Down Expand Up @@ -117,6 +118,15 @@ def update_catalog_snapshots():
for po_file in data_dir.glob('*.po'):
mo_file = po_file.with_suffix('.mo')
compile_messages(po_file, mo_file)
# Create a human-readable JSON file which is
# easier to review than the binary .mo file.
with open(mo_file, 'rb') as f:
translations = GNUTranslations(f)
catalog_file = po_file.with_suffix('.json')
with open(catalog_file, 'w') as f:
data = list(translations._catalog.items())
json.dump(data, f, indent=4)
f.write('\n')


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly reset ``msgctxt`` when compiling messages in :program:`msgfmt`.
1 change: 1 addition & 0 deletions Tools/i18n/msgfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def make(filename, outfile):
elif l.startswith('msgid') and not l.startswith('msgid_plural'):
if section == STR:
add(msgctxt, msgid, msgstr, fuzzy)
msgctxt = None
if not msgid:
# See whether there is an encoding declaration
p = HeaderParser()
Expand Down
Loading