Skip to content

Commit

Permalink
[2.2.x] Fixed #31570 -- Corrected translation loading for apps provid…
Browse files Browse the repository at this point in the history
…ing territorial language variants with different plural equations.

Regression in e3e48b0.

Thanks to Shai Berger for report, reproduce and suggested fix.

Backport of dd1ca50 from master.
  • Loading branch information
carltongibson authored and felixxm committed Jun 1, 2020
1 parent e33220f commit 027840d
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 3 deletions.
2 changes: 1 addition & 1 deletion django/utils/translation/trans_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def update(self, trans):
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):
Expand Down
7 changes: 5 additions & 2 deletions docs/releases/2.2.13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ 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 territorial language variants as well as a
generic language, where the project has different plural equations for the
language (:ticket:`31570`).
Binary file added tests/i18n/loading/en/LC_MESSAGES/django.mo
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/i18n/loading/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -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"
Binary file added tests/i18n/loading/en_AU/LC_MESSAGES/django.mo
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/i18n/loading/en_AU/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -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"
Binary file added tests/i18n/loading/en_CA/LC_MESSAGES/django.mo
Binary file not shown.
22 changes: 22 additions & 0 deletions tests/i18n/loading/en_CA/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -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"
Binary file added tests/i18n/loading/en_NZ/LC_MESSAGES/django.mo
Binary file not shown.
22 changes: 22 additions & 0 deletions tests/i18n/loading/en_NZ/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -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"
Empty file.
5 changes: 5 additions & 0 deletions tests/i18n/loading_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class LoadingAppConfig(AppConfig):
name = 'loading_app'
Binary file not shown.
25 changes: 25 additions & 0 deletions tests/i18n/loading_app/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -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 ""
45 changes: 45 additions & 0 deletions tests/i18n/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,51 @@ def test_language_bidi_null(self):
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', 'English (Canada)'),
('en-nz', 'English (New Zealand)'),
('en-au', 'English (Australia)'),
],
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 are merged correctly.
"""
tests = [
('en', 'local country person'),
('en_AU', 'aussie'),
('en_NZ', 'kiwi'),
('en_CA', 'canuck'),
]
# Load all relevant translations.
for language, _ in tests:
activate(language)
# Catalogs are merged correctly.
for language, nickname in tests:
with self.subTest(language=language):
activate(language)
self.assertEqual(gettext('local country person'), nickname)


class TranslationThreadSafetyTests(SimpleTestCase):

def setUp(self):
Expand Down

0 comments on commit 027840d

Please sign in to comment.