mirror of
https://github.com/django/django.git
synced 2024-12-24 10:05:46 +00:00
Fixed #13726 -- Further refine changes made in r12384 and r13069 for using non-English source languages in JavaScript translation catalogues. Thanks, Ramiro.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14901 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
2478f8588e
commit
6ec348fb41
@ -194,7 +194,8 @@ def javascript_catalog(request, domain='djangojs', packages=None):
|
|||||||
locale = to_locale(get_language())
|
locale = to_locale(get_language())
|
||||||
t = {}
|
t = {}
|
||||||
paths = []
|
paths = []
|
||||||
en_catalog_missing = False
|
en_selected = locale.startswith('en')
|
||||||
|
en_catalog_missing = True
|
||||||
# first load all english languages files for defaults
|
# first load all english languages files for defaults
|
||||||
for package in packages:
|
for package in packages:
|
||||||
p = importlib.import_module(package)
|
p = importlib.import_module(package)
|
||||||
@ -204,13 +205,12 @@ def javascript_catalog(request, domain='djangojs', packages=None):
|
|||||||
catalog = gettext_module.translation(domain, path, ['en'])
|
catalog = gettext_module.translation(domain, path, ['en'])
|
||||||
t.update(catalog._catalog)
|
t.update(catalog._catalog)
|
||||||
except IOError:
|
except IOError:
|
||||||
# '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
|
pass
|
||||||
|
else:
|
||||||
|
# 'en' is the selected language and at least one of the packages
|
||||||
|
# listed in `packages` has an 'en' catalog
|
||||||
|
if en_selected:
|
||||||
|
en_catalog_missing = False
|
||||||
# next load the settings.LANGUAGE_CODE translations if it isn't english
|
# next load the settings.LANGUAGE_CODE translations if it isn't english
|
||||||
if default_locale != 'en':
|
if default_locale != 'en':
|
||||||
for path in paths:
|
for path in paths:
|
||||||
@ -222,12 +222,11 @@ def javascript_catalog(request, domain='djangojs', packages=None):
|
|||||||
t.update(catalog._catalog)
|
t.update(catalog._catalog)
|
||||||
# last load the currently selected language, if it isn't identical to the default.
|
# last load the currently selected language, if it isn't identical to the default.
|
||||||
if locale != default_locale:
|
if locale != default_locale:
|
||||||
# If the flag en_catalog_missing has been set, the currently
|
# If the currently selected language is English but it doesn't have a
|
||||||
# selected language is English but it doesn't have a translation
|
# translation catalog (presumably due to being the language translated
|
||||||
# catalog (presumably due to being the language translated from).
|
# from) then a wrong language catalog might have been loaded in the
|
||||||
# If that is the case, a wrong language catalog might have been
|
# previous step. It needs to be discarded.
|
||||||
# loaded in the previous step. It needs to be discarded.
|
if en_selected and en_catalog_missing:
|
||||||
if en_catalog_missing:
|
|
||||||
t = {}
|
t = {}
|
||||||
else:
|
else:
|
||||||
locale_t = {}
|
locale_t = {}
|
||||||
|
1
tests/regressiontests/views/app0/__init__.py
Normal file
1
tests/regressiontests/views/app0/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
#
|
Binary file not shown.
@ -0,0 +1,20 @@
|
|||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||||
|
# This file is distributed under the same license as the PACKAGE package.
|
||||||
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
|
#
|
||||||
|
#, fuzzy
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2007-09-15 19:15+0200\n"
|
||||||
|
"PO-Revision-Date: 2010-05-12 12:41-0300\n"
|
||||||
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
|
msgid "il faut traduire cette chaîne de caractères de app0"
|
||||||
|
msgstr "this app0 string is to be translated"
|
@ -43,9 +43,12 @@ class JsI18NTests(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.old_language_code = settings.LANGUAGE_CODE
|
self.old_language_code = settings.LANGUAGE_CODE
|
||||||
|
self.old_installed_apps = settings.INSTALLED_APPS
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
deactivate()
|
||||||
settings.LANGUAGE_CODE = self.old_language_code
|
settings.LANGUAGE_CODE = self.old_language_code
|
||||||
|
settings.INSTALLED_APPS = self.old_installed_apps
|
||||||
|
|
||||||
def test_jsi18n_with_missing_en_files(self):
|
def test_jsi18n_with_missing_en_files(self):
|
||||||
"""
|
"""
|
||||||
@ -75,14 +78,26 @@ class JsI18NTests(TestCase):
|
|||||||
def testI18NLanguageNonEnglishDefault(self):
|
def testI18NLanguageNonEnglishDefault(self):
|
||||||
"""
|
"""
|
||||||
Check if the Javascript i18n view returns an empty language catalog
|
Check if the Javascript i18n view returns an empty language catalog
|
||||||
if the default language is non-English but the selected language
|
if the default language is non-English, the selected language
|
||||||
is English. See #13388 and #3594 for more details.
|
is English and there is not 'en' translation available. See #13388,
|
||||||
|
#3594 and #13726 for more details.
|
||||||
"""
|
"""
|
||||||
settings.LANGUAGE_CODE = 'fr'
|
settings.LANGUAGE_CODE = 'fr'
|
||||||
activate('en-us')
|
activate('en-us')
|
||||||
response = self.client.get('/views/jsi18n/')
|
response = self.client.get('/views/jsi18n/')
|
||||||
self.assertNotContains(response, 'Choisir une heure')
|
self.assertNotContains(response, 'Choisir une heure')
|
||||||
deactivate()
|
|
||||||
|
def test_nonenglish_default_english_userpref(self):
|
||||||
|
"""
|
||||||
|
Same as above with the difference that there IS an 'en' translation
|
||||||
|
available. The Javascript i18n view must return a NON empty language catalog
|
||||||
|
with the proper English translations. See #13726 for more details.
|
||||||
|
"""
|
||||||
|
settings.LANGUAGE_CODE = 'fr'
|
||||||
|
settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.views.app0']
|
||||||
|
activate('en-us')
|
||||||
|
response = self.client.get('/views/jsi18n_english_translation/')
|
||||||
|
self.assertContains(response, javascript_quote('this app0 string is to be translated'))
|
||||||
|
|
||||||
def testI18NLanguageNonEnglishFallback(self):
|
def testI18NLanguageNonEnglishFallback(self):
|
||||||
"""
|
"""
|
||||||
@ -93,7 +108,6 @@ class JsI18NTests(TestCase):
|
|||||||
activate('none')
|
activate('none')
|
||||||
response = self.client.get('/views/jsi18n/')
|
response = self.client.get('/views/jsi18n/')
|
||||||
self.assertContains(response, 'Choisir une heure')
|
self.assertContains(response, 'Choisir une heure')
|
||||||
deactivate()
|
|
||||||
|
|
||||||
|
|
||||||
class JsI18NTestsMultiPackage(TestCase):
|
class JsI18NTestsMultiPackage(TestCase):
|
||||||
|
@ -16,6 +16,11 @@ js_info_dict = {
|
|||||||
'packages': ('regressiontests.views',),
|
'packages': ('regressiontests.views',),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
js_info_dict_english_translation = {
|
||||||
|
'domain': 'djangojs',
|
||||||
|
'packages': ('regressiontests.views.app0',),
|
||||||
|
}
|
||||||
|
|
||||||
js_info_dict_multi_packages1 = {
|
js_info_dict_multi_packages1 = {
|
||||||
'domain': 'djangojs',
|
'domain': 'djangojs',
|
||||||
'packages': ('regressiontests.views.app1', 'regressiontests.views.app2'),
|
'packages': ('regressiontests.views.app1', 'regressiontests.views.app2'),
|
||||||
@ -56,6 +61,7 @@ urlpatterns = patterns('',
|
|||||||
# i18n views
|
# i18n views
|
||||||
(r'^i18n/', include('django.conf.urls.i18n')),
|
(r'^i18n/', include('django.conf.urls.i18n')),
|
||||||
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
|
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
|
||||||
|
(r'^jsi18n_english_translation/$', 'django.views.i18n.javascript_catalog', js_info_dict_english_translation),
|
||||||
(r'^jsi18n_multi_packages1/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages1),
|
(r'^jsi18n_multi_packages1/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages1),
|
||||||
(r'^jsi18n_multi_packages2/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages2),
|
(r'^jsi18n_multi_packages2/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages2),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user