diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/views/i18n.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/django/views/i18n.py b/django/views/i18n.py index 0280698aae..23d248a2bc 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -127,6 +127,7 @@ def javascript_catalog(request, domain='djangojs', packages=None): locale = to_locale(get_language()) t = {} paths = [] + en_catalog_missing = False # first load all english languages files for defaults for package in packages: p = importlib.import_module(package) @@ -136,7 +137,12 @@ def javascript_catalog(request, domain='djangojs', packages=None): catalog = gettext_module.translation(domain, path, ['en']) t.update(catalog._catalog) except IOError: - # 'en' catalog was missing. This is harmless. + # 'en' catalog was missing. + if locale.startswith('en'): + # If 'en' is the selected language this would cause issues + # later on if default_locale is something other than 'en'. + en_catalog_missing = True + # Otherwise it is harmless. pass # next load the settings.LANGUAGE_CODE translations if it isn't english if default_locale != 'en': @@ -149,13 +155,21 @@ def javascript_catalog(request, domain='djangojs', packages=None): t.update(catalog._catalog) # last load the currently selected language, if it isn't identical to the default. if locale != default_locale: - for path in paths: - try: - catalog = gettext_module.translation(domain, path, [locale]) - except IOError: - catalog = None - if catalog is not None: - t.update(catalog._catalog) + # If the flag en_catalog_missing has been set, the currently + # selected language is English but it doesn't have a translation + # catalog (presumably due to being the language translated from). + # If that is the case, a wrong language catalog might have been + # loaded in the previous step. It needs to be discarded. + if en_catalog_missing: + t = {} + else: + for path in paths: + try: + catalog = gettext_module.translation(domain, path, [locale]) + except IOError: + catalog = None + if catalog is not None: + t.update(catalog._catalog) src = [LibHead] plural = None if '' in t: |
