mirror of
https://github.com/django/django.git
synced 2025-10-28 18:43:19 +00:00
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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12384 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
cdeb90e345
commit
8600ad4c50
4 changed files with 60 additions and 29 deletions
|
|
@ -177,6 +177,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)
|
||||
|
|
@ -186,7 +187,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':
|
||||
|
|
@ -199,13 +205,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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue