summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2015-12-18 17:00:53 +0100
committerClaude Paroz <claude@2xlibre.net>2015-12-18 17:50:16 +0100
commitcd3c042b0473e762b0e89bc69a9244c4a1fed66e (patch)
tree3f04b7e5a12ad644d86cd4fb953f9f8e4912e977 /django/utils
parent99a1265a394cb50f5b5aa9046f7b6cd230bc25cf (diff)
Fixed #25915 -- Allowed language not in Django's default LANGUAGES
This fixes a regression introduced by a5f6cbce07. Thanks Gavin Wahl for the report and Tim Graham for the review.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/translation/trans_real.py33
1 files changed, 16 insertions, 17 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 6c6fe6d2f2..b73f2b4869 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -108,10 +108,14 @@ class DjangoTranslation(gettext_module.GNUTranslations):
self.__language = language
self.__to_language = to_language(language)
self.__locale = to_locale(language)
+ self._catalog = None
self._init_translation_catalog()
self._add_installed_apps_translations()
self._add_local_translations()
+ if self.__language == settings.LANGUAGE_CODE and self._catalog is None:
+ # 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()
def __repr__(self):
@@ -125,32 +129,19 @@ class DjangoTranslation(gettext_module.GNUTranslations):
Using param `use_null_fallback` to avoid confusion with any other
references to 'fallback'.
"""
- translation = gettext_module.translation(
+ return gettext_module.translation(
domain='django',
localedir=localedir,
languages=[self.__locale],
codeset='utf-8',
fallback=use_null_fallback)
- if not hasattr(translation, '_catalog'):
- # provides merge support for NullTranslations()
- translation._catalog = {}
- translation._info = {}
- translation.plural = lambda n: int(n != 1)
- return translation
def _init_translation_catalog(self):
"""Creates a base catalog using global django translations."""
settingsfile = upath(sys.modules[settings.__module__].__file__)
localedir = os.path.join(os.path.dirname(settingsfile), 'locale')
- use_null_fallback = True
- if self.__language == settings.LANGUAGE_CODE:
- # default lang should be present and parseable, if not
- # gettext will raise an IOError (refs #18192).
- use_null_fallback = False
- translation = self._new_gnu_trans(localedir, use_null_fallback)
- self.plural = translation.plural
- self._info = translation._info.copy()
- self._catalog = translation._catalog.copy()
+ translation = self._new_gnu_trans(localedir)
+ self.merge(translation)
def _add_installed_apps_translations(self):
"""Merges translations from each installed app."""
@@ -183,7 +174,15 @@ class DjangoTranslation(gettext_module.GNUTranslations):
def merge(self, other):
"""Merge another translation into this catalog."""
- self._catalog.update(other._catalog)
+ if not getattr(other, '_catalog', None):
+ return # NullTranslations() has no _catalog
+ if self._catalog is None:
+ # Take plural and _info from first catalog found (generally Django's).
+ self.plural = other.plural
+ self._info = other._info.copy()
+ self._catalog = other._catalog.copy()
+ else:
+ self._catalog.update(other._catalog)
def language(self):
"""Returns the translation language."""