diff options
| author | Jannis Leidel <jannis@leidel.info> | 2010-02-05 01:54:22 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2010-02-05 01:54:22 +0000 |
| commit | 01d43168749abe027473b34002ca76b4ce3d1eaa (patch) | |
| tree | b79e97a1c6552d21a47c874b15be491ebff025b1 /django/views | |
| parent | 88bd40c551365c92312e79a51fc4891a0099d9fe (diff) | |
[1.1.X] Fixed #3594 - Added ability to discard the language catalog in the JavaScript i18n view in case the selected language is English but no English translation catalog actual exists, e.g. due to being the language translated from. Thanks to msaelices, aryx and Ramiro Morales.
Backport of r12384.
Conflicts:
tests/regressiontests/views/tests/i18n.py
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12385 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/views')
| -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: |
