| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + [] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,58 @@ | |||
| 1 | + [ | ||
| 2 | + [ | ||
| 3 | + "", | ||
| 4 | + "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 <LL@li.org>\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n" | ||
| 5 | + ], | ||
| 6 | + [ | ||
| 7 | + "\n newlines \n", | ||
| 8 | + "\n translated \n" | ||
| 9 | + ], | ||
| 10 | + [ | ||
| 11 | + "\"escapes\"", | ||
| 12 | + "\"translated\"" | ||
| 13 | + ], | ||
| 14 | + [ | ||
| 15 | + "Multilinestring", | ||
| 16 | + "Multilinetranslation" | ||
| 17 | + ], | ||
| 18 | + [ | ||
| 19 | + "abc\u0004foo", | ||
| 20 | + "bar" | ||
| 21 | + ], | ||
| 22 | + [ | ||
| 23 | + "bar", | ||
| 24 | + "baz" | ||
| 25 | + ], | ||
| 26 | + [ | ||
| 27 | + "xyz\u0004foo", | ||
| 28 | + "bar" | ||
| 29 | + ], | ||
| 30 | + [ | ||
| 31 | + [ | ||
| 32 | + "One email sent.", | ||
| 33 | + 0 | ||
| 34 | + ], | ||
| 35 | + "One email sent." | ||
| 36 | + ], | ||
| 37 | + [ | ||
| 38 | + [ | ||
| 39 | + "One email sent.", | ||
| 40 | + 1 | ||
| 41 | + ], | ||
| 42 | + "%d emails sent." | ||
| 43 | + ], | ||
| 44 | + [ | ||
| 45 | + [ | ||
| 46 | + "abc\u0004One email sent.", | ||
| 47 | + 0 | ||
| 48 | + ], | ||
| 49 | + "One email sent." | ||
| 50 | + ], | ||
| 51 | + [ | ||
| 52 | + [ | ||
| 53 | + "abc\u0004One email sent.", | ||
| 54 | + 1 | ||
| 55 | + ], | ||
| 56 | + "%d emails sent." | ||
| 57 | + ] | ||
| 58 | + ] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | """Tests for the Tools/i18n/msgfmt.py tool.""" | |
| 2 | 2 | ||
| 3 | + import json | ||
| 3 | 4 | import sys | |
| 4 | 5 | import unittest | |
| 5 | 6 | from gettext import GNUTranslations | |
@@ -39,6 +40,28 @@ def test_compilation(self): | |||
| 39 | 40 | ||
| 40 | 41 | self.assertDictEqual(actual._catalog, expected._catalog) | |
| 41 | 42 | ||
| 43 | + def test_translations(self): | ||
| 44 | + with open(data_dir / 'general.mo', 'rb') as f: | ||
| 45 | + t = GNUTranslations(f) | ||
| 46 | + | ||
| 47 | + self.assertEqual(t.gettext('foo'), 'foo') | ||
| 48 | + self.assertEqual(t.gettext('bar'), 'baz') | ||
| 49 | + self.assertEqual(t.pgettext('abc', 'foo'), 'bar') | ||
| 50 | + self.assertEqual(t.pgettext('xyz', 'foo'), 'bar') | ||
| 51 | + self.assertEqual(t.gettext('Multilinestring'), 'Multilinetranslation') | ||
| 52 | + self.assertEqual(t.gettext('"escapes"'), '"translated"') | ||
| 53 | + self.assertEqual(t.gettext('\n newlines \n'), '\n translated \n') | ||
| 54 | + self.assertEqual(t.ngettext('One email sent.', '%d emails sent.', 1), | ||
| 55 | + 'One email sent.') | ||
| 56 | + self.assertEqual(t.ngettext('One email sent.', '%d emails sent.', 2), | ||
| 57 | + '%d emails sent.') | ||
| 58 | + self.assertEqual(t.npgettext('abc', 'One email sent.', | ||
| 59 | + '%d emails sent.', 1), | ||
| 60 | + 'One email sent.') | ||
| 61 | + self.assertEqual(t.npgettext('abc', 'One email sent.', | ||
| 62 | + '%d emails sent.', 2), | ||
| 63 | + '%d emails sent.') | ||
| 64 | + | ||
| 42 | 65 | def test_invalid_msgid_plural(self): | |
| 43 | 66 | with temp_cwd(): | |
| 44 | 67 | Path('invalid.po').write_text('''\ | |
@@ -117,6 +140,16 @@ def update_catalog_snapshots(): | |||
| 117 | 140 | for po_file in data_dir.glob('*.po'): | |
| 118 | 141 | mo_file = po_file.with_suffix('.mo') | |
| 119 | 142 | compile_messages(po_file, mo_file) | |
| 143 | + # Create a human-readable JSON file which is | ||
| 144 | + # easier to review than the binary .mo file. | ||
| 145 | + with open(mo_file, 'rb') as f: | ||
| 146 | + translations = GNUTranslations(f) | ||
| 147 | + catalog_file = po_file.with_suffix('.json') | ||
| 148 | + with open(catalog_file, 'w') as f: | ||
| 149 | + data = translations._catalog.items() | ||
| 150 | + data = sorted(data, key=lambda x: (isinstance(x[0], tuple), x[0])) | ||
| 151 | + json.dump(data, f, indent=4) | ||
| 152 | + f.write('\n') | ||
| 120 | 153 | ||
| 121 | 154 | ||
| 122 | 155 | if __name__ == '__main__': | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Correctly reset ``msgctxt`` when compiling messages in :program:`msgfmt`. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,6 +149,7 @@ def make(filename, outfile): | |||
| 149 | 149 | elif l.startswith('msgid') and not l.startswith('msgid_plural'): | |
| 150 | 150 | if section == STR: | |
| 151 | 151 | add(msgctxt, msgid, msgstr, fuzzy) | |
| 152 | + msgctxt = None | ||
| 152 | 153 | if not msgid: | |
| 153 | 154 | # See whether there is an encoding declaration | |
| 154 | 155 | p = HeaderParser() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments