diff options
| author | Ad Timmering <awtimmering@gmail.com> | 2021-11-09 21:32:58 +0900 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-11-11 09:12:05 +0100 |
| commit | 4bfe8c0eec835b8eaffcda7dc1e3b203751a790a (patch) | |
| tree | 75db6fbed9cb554a2827134064c50c7cc709f71a /tests | |
| parent | 0b95a96ee10d3e12aef01d449467bcf4641286b4 (diff) | |
Fixed #6106 -- Prevented makemessages from changing .po files when up to date.
Co-authored-by: Daniyal Abbasi <abbasi.daniyal98@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/i18n/test_extraction.py | 34 | ||||
| -rw-r--r-- | tests/i18n/unchanged/__init__.py | 4 | ||||
| -rw-r--r-- | tests/i18n/unchanged/locale/de/LC_MESSAGES/django.po.tmp | 26 | ||||
| -rw-r--r-- | tests/i18n/unchanged/models.py.tmp | 3 |
4 files changed, 67 insertions, 0 deletions
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index 124d35313f..98932fdcbb 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -804,3 +804,37 @@ class NoSettingsExtractionTests(AdminScriptTestCase): out, err = self.run_django_admin(['makemessages', '-l', 'en', '-v', '0']) self.assertNoOutput(err) self.assertNoOutput(out) + + +class UnchangedPoExtractionTests(ExtractorTests): + work_subdir = 'unchanged' + + def setUp(self): + super().setUp() + po_file = Path(self.PO_FILE) + po_file_tmp = Path(self.PO_FILE + '.tmp') + if os.name == 'nt': + # msgmerge outputs Windows style paths on Windows. + po_contents = po_file_tmp.read_text().replace( + '#: __init__.py', + '#: .\\__init__.py', + ) + po_file.write_text(po_contents) + else: + po_file_tmp.rename(po_file) + self.original_po_contents = po_file.read_text() + + def test_po_remains_unchanged(self): + """PO files are unchanged unless there are new changes.""" + _, po_contents = self._run_makemessages() + self.assertEqual(po_contents, self.original_po_contents) + + def test_po_changed_with_new_strings(self): + """PO files are updated when new changes are detected.""" + Path('models.py.tmp').rename('models.py') + _, po_contents = self._run_makemessages() + self.assertNotEqual(po_contents, self.original_po_contents) + self.assertMsgId( + 'This is a hitherto undiscovered translatable string.', + po_contents, + ) diff --git a/tests/i18n/unchanged/__init__.py b/tests/i18n/unchanged/__init__.py new file mode 100644 index 0000000000..0ff42ffd6c --- /dev/null +++ b/tests/i18n/unchanged/__init__.py @@ -0,0 +1,4 @@ +from django.utils.translation import gettext as _ + +string1 = _('This is a translatable string.') +string2 = _('This is another translatable string.') diff --git a/tests/i18n/unchanged/locale/de/LC_MESSAGES/django.po.tmp b/tests/i18n/unchanged/locale/de/LC_MESSAGES/django.po.tmp new file mode 100644 index 0000000000..d5cad72f7a --- /dev/null +++ b/tests/i18n/unchanged/locale/de/LC_MESSAGES/django.po.tmp @@ -0,0 +1,26 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-04-25 15:39-0500\n" +"PO-Revision-Date: 2014-05-25 15:39-0500\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: __init__.py:3 +msgid "This is a translatable string." +msgstr "And this has been translated." + +#: __init__.py:4 +msgid "This is another translatable string." +msgstr "And this also has been translated." diff --git a/tests/i18n/unchanged/models.py.tmp b/tests/i18n/unchanged/models.py.tmp new file mode 100644 index 0000000000..c6324495d4 --- /dev/null +++ b/tests/i18n/unchanged/models.py.tmp @@ -0,0 +1,3 @@ +from django.utils.translation import gettext as _ + +string3 = _('This is a hitherto undiscovered translatable string.') |
