summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-01-06 18:33:29 +0100
committerClaude Paroz <claude@2xlibre.net>2016-01-06 20:33:26 +0100
commitfe6d5689f291c7c56f280203f9c9bbbdde87044a (patch)
tree63fdc8d0dd85a6572dcd1500a3acc6cd715f0792
parenta7b69c8657609c925da055553f289760a66c64cf (diff)
[1.9.x] Fixed #26046 -- Fixed a crash with translations and Django-unknown language code
Thanks Jens Lundstrom for the report and Tim Graham for the review. Backport of 632a9f21bc from master.
-rw-r--r--django/utils/translation/trans_real.py3
-rw-r--r--docs/releases/1.8.9.txt3
-rw-r--r--docs/releases/1.9.2.txt7
-rw-r--r--tests/i18n/tests.py4
4 files changed, 15 insertions, 2 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index b73f2b4869..5208e7a96f 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -117,6 +117,9 @@ class DjangoTranslation(gettext_module.GNUTranslations):
# default lang should have at least one translation file available.
raise IOError("No translation files found for default language %s." % settings.LANGUAGE_CODE)
self._add_fallback()
+ if self._catalog is None:
+ # No catalogs found for this language, set an empty catalog.
+ self._catalog = {}
def __repr__(self):
return "<DjangoTranslation lang:%s>" % self.__language
diff --git a/docs/releases/1.8.9.txt b/docs/releases/1.8.9.txt
index be3b719b1e..823bd9b3eb 100644
--- a/docs/releases/1.8.9.txt
+++ b/docs/releases/1.8.9.txt
@@ -11,3 +11,6 @@ Bugfixes
* Fixed a regression that caused the "user-tools" items to display on the
admin's logout page (:ticket:`26035`).
+
+* Fixed a crash in the translations system when the current language has no
+ translations (:ticket:`26046`).
diff --git a/docs/releases/1.9.2.txt b/docs/releases/1.9.2.txt
index 4cddae3938..f486d00311 100644
--- a/docs/releases/1.9.2.txt
+++ b/docs/releases/1.9.2.txt
@@ -9,8 +9,11 @@ Django 1.9.2 fixes several bugs in 1.9.1.
Bugfixes
========
-* Fixed a regression in ``ConditionalGetMiddleware`` causing ``If-None-Match`` checks
- to always return HTTP 200 (:ticket:`26024`).
+* Fixed a regression in ``ConditionalGetMiddleware`` causing ``If-None-Match``
+ checks to always return HTTP 200 (:ticket:`26024`).
* Fixed a regression that caused the "user-tools" items to display on the
admin's logout page (:ticket:`26035`).
+
+* Fixed a crash in the translations system when the current language has no
+ translations (:ticket:`26046`).
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index 8e545c9e43..667451119d 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -1577,6 +1577,10 @@ class TestLanguageInfo(SimpleTestCase):
def test_unknown_language_code(self):
six.assertRaisesRegex(self, KeyError, r"Unknown language code xx\.", get_language_info, 'xx')
+ with translation.override('xx'):
+ # A language with no translation catalogs should fallback to the
+ # untranslated string.
+ self.assertEqual(ugettext("Title"), "Title")
def test_unknown_only_country_code(self):
li = get_language_info('de-xx')