diff options
author | Carlton Gibson <carlton.gibson@noumenal.es> | 2020-05-28 10:26:41 +0200 |
---|---|---|
committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2020-05-28 11:14:41 +0200 |
commit | 2331417b6b1b1faaa1c04964283a534c66713ba4 (patch) | |
tree | fb90c936c55dbb0713edb2b37883bb2d45c613ce | |
parent | 42de52affe20e399554d984cc7848bf8e0368b41 (diff) | |
download | django-issue/31570.tar.gz |
Fixed #31570 -- Corrected translation loading for apps providing only a subset of supported languages.issue/31570
Regression in e3e48b00127c09eafe6439d980a82fc5c591b673
Thanks to Shai Berger for report, reproduce and suggested fix.
23 files changed, 173 insertions, 3 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index eed4705f6e..8042f6fdc4 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -96,7 +96,7 @@ class TranslationCatalog: cat.update(trans._catalog) break else: - self._catalogs.insert(0, trans._catalog) + self._catalogs.insert(0, trans._catalog.copy()) self._plurals.insert(0, trans.plural) def get(self, key, default=None): diff --git a/docs/releases/2.2.13.txt b/docs/releases/2.2.13.txt index 450f7acdbf..9555d40f7b 100644 --- a/docs/releases/2.2.13.txt +++ b/docs/releases/2.2.13.txt @@ -4,9 +4,11 @@ Django 2.2.13 release notes *Expected June 3, 2020* -Django 2.2.13 fixes two security issues and a bug in 2.2.12. +Django 2.2.13 fixes two security issues and a regression in 2.2.12. Bugfixes ======== -* ... +* Fixed a regression in Django 2.2.12 that affected translation loading for + apps providing translations for only a subset of all supported languages + (:ticket:`31570`). diff --git a/docs/releases/3.0.7.txt b/docs/releases/3.0.7.txt index c7bc3730fd..3dd2f911c9 100644 --- a/docs/releases/3.0.7.txt +++ b/docs/releases/3.0.7.txt @@ -25,3 +25,7 @@ Bugfixes * Fixed a regression in Django 3.0 where all resolved ``Subquery()`` expressions were considered equal (:ticket:`31607`). + +* Fixed a regression in Django 2.2.12 that affected translation loading for + apps providing translations for only a subset of all supported languages + (:ticket:`31570`). diff --git a/tests/i18n/loading/__init__.py b/tests/i18n/loading/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/i18n/loading/__init__.py diff --git a/tests/i18n/loading/en/LC_MESSAGES/django.mo b/tests/i18n/loading/en/LC_MESSAGES/django.mo Binary files differnew file mode 100644 index 0000000000..f666550adb --- /dev/null +++ b/tests/i18n/loading/en/LC_MESSAGES/django.mo diff --git a/tests/i18n/loading/en/LC_MESSAGES/django.po b/tests/i18n/loading/en/LC_MESSAGES/django.po new file mode 100644 index 0000000000..d43d83e34a --- /dev/null +++ b/tests/i18n/loading/en/LC_MESSAGES/django.po @@ -0,0 +1,23 @@ +# 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: 2020-05-13 08:42+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: trans/tests.py:16 +msgid "local country person" +msgstr "local country person" diff --git a/tests/i18n/loading/en/__init__.py b/tests/i18n/loading/en/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/i18n/loading/en/__init__.py diff --git a/tests/i18n/loading/en_AU/LC_MESSAGES/django.mo b/tests/i18n/loading/en_AU/LC_MESSAGES/django.mo Binary files differnew file mode 100644 index 0000000000..98b016bc6c --- /dev/null +++ b/tests/i18n/loading/en_AU/LC_MESSAGES/django.mo diff --git a/tests/i18n/loading/en_AU/LC_MESSAGES/django.po b/tests/i18n/loading/en_AU/LC_MESSAGES/django.po new file mode 100644 index 0000000000..ec21ac899d --- /dev/null +++ b/tests/i18n/loading/en_AU/LC_MESSAGES/django.po @@ -0,0 +1,23 @@ +# 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: 2020-05-13 08:42+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: trans/tests.py:16 +msgid "local country person" +msgstr "aussie" diff --git a/tests/i18n/loading/en_AU/__init__.py b/tests/i18n/loading/en_AU/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/i18n/loading/en_AU/__init__.py diff --git a/tests/i18n/loading/en_CA/LC_MESSAGES/django.mo b/tests/i18n/loading/en_CA/LC_MESSAGES/django.mo Binary files differnew file mode 100644 index 0000000000..4d6da00f65 --- /dev/null +++ b/tests/i18n/loading/en_CA/LC_MESSAGES/django.mo diff --git a/tests/i18n/loading/en_CA/LC_MESSAGES/django.po b/tests/i18n/loading/en_CA/LC_MESSAGES/django.po new file mode 100644 index 0000000000..06e52a4c55 --- /dev/null +++ b/tests/i18n/loading/en_CA/LC_MESSAGES/django.po @@ -0,0 +1,22 @@ +# 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: 2020-05-13 08:42+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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" + +#: trans/tests.py:16 +msgid "local country person" +msgstr "canuck" diff --git a/tests/i18n/loading/en_CA/__init__.py b/tests/i18n/loading/en_CA/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/i18n/loading/en_CA/__init__.py diff --git a/tests/i18n/loading/en_NZ/LC_MESSAGES/django.mo b/tests/i18n/loading/en_NZ/LC_MESSAGES/django.mo Binary files differnew file mode 100644 index 0000000000..f71850a5b1 --- /dev/null +++ b/tests/i18n/loading/en_NZ/LC_MESSAGES/django.mo diff --git a/tests/i18n/loading/en_NZ/LC_MESSAGES/django.po b/tests/i18n/loading/en_NZ/LC_MESSAGES/django.po new file mode 100644 index 0000000000..41b7499291 --- /dev/null +++ b/tests/i18n/loading/en_NZ/LC_MESSAGES/django.po @@ -0,0 +1,22 @@ +# 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: 2020-05-13 08:42+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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" + +#: trans/tests.py:16 +msgid "local country person" +msgstr "kiwi" diff --git a/tests/i18n/loading/en_NZ/__init__.py b/tests/i18n/loading/en_NZ/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/i18n/loading/en_NZ/__init__.py diff --git a/tests/i18n/loading_app/__init__.py b/tests/i18n/loading_app/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/i18n/loading_app/__init__.py diff --git a/tests/i18n/loading_app/apps.py b/tests/i18n/loading_app/apps.py new file mode 100644 index 0000000000..b4cdece232 --- /dev/null +++ b/tests/i18n/loading_app/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class LoadingAppConfig(AppConfig): + name = 'loading_app' diff --git a/tests/i18n/loading_app/locale/__init__.py b/tests/i18n/loading_app/locale/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/i18n/loading_app/locale/__init__.py diff --git a/tests/i18n/loading_app/locale/en/LC_MESSAGES/django.mo b/tests/i18n/loading_app/locale/en/LC_MESSAGES/django.mo Binary files differnew file mode 100644 index 0000000000..71cbdf3e9d --- /dev/null +++ b/tests/i18n/loading_app/locale/en/LC_MESSAGES/django.mo diff --git a/tests/i18n/loading_app/locale/en/LC_MESSAGES/django.po b/tests/i18n/loading_app/locale/en/LC_MESSAGES/django.po new file mode 100644 index 0000000000..e1422f19da --- /dev/null +++ b/tests/i18n/loading_app/locale/en/LC_MESSAGES/django.po @@ -0,0 +1,25 @@ +# 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: 2020-05-13 11:39+0300\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: apps.py:8 +msgid "" +"An app with its own translation files, with one for 'en' but not the " +"regional dialects of English" +msgstr "" diff --git a/tests/i18n/loading_app/locale/en/__init__.py b/tests/i18n/loading_app/locale/en/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/i18n/loading_app/locale/en/__init__.py diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 8f07c14247..ccf4c242cf 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -384,6 +384,50 @@ class TranslationTests(SimpleTestCase): self.assertIs(get_language_bidi(), True) +class TranslationLoadingTests(SimpleTestCase): + + def setUp(self): + """Clear translation state.""" + self._old_language = get_language() + self._old_translations = trans_real._translations + deactivate() + trans_real._translations = {} + + def tearDown(self): + trans_real._translations = self._old_translations + activate(self._old_language) + + @override_settings( + USE_I18N=True, + LANGUAGE_CODE='en', + LANGUAGES=[ + ('en', 'English'), + ('en-ca', 'Canadian'), + ('en-nz', 'New Zealandian'), + ('en-au', 'Australian'), + ], + LOCALE_PATHS=[os.path.join(here, 'loading')], + INSTALLED_APPS=['i18n.loading_app'], + ) + def test_translation_loading(self): + """ + ``loading_app`` does not have translations for all languages provided + by ``loading``. Catalogs must be merged correctly. + """ + tests = [ + ('en', 'local country person'), + ('en_AU', 'aussie'), + ('en_NZ', 'kiwi'), + ('en_CA', 'canuck'), + ] + # All translations are loaded by the second pass. + for rnd in range(1, 3): + for language, nickname in tests: + with self.subTest(language=language, round=rnd): + activate(language) + self.assertEqual(gettext('local country person'), nickname) + + class TranslationThreadSafetyTests(SimpleTestCase): def setUp(self): |