diff -r 731b9d6d9c9a django/views/i18n.py
a
|
b
|
|
177 | 177 | locale = to_locale(get_language()) |
178 | 178 | t = {} |
179 | 179 | paths = [] |
180 | | en_catalog_missing = False |
| 180 | en_selected = locale.startswith('en') |
| 181 | en_catalog_missing = True |
181 | 182 | # first load all english languages files for defaults |
182 | 183 | for package in packages: |
183 | 184 | p = importlib.import_module(package) |
… |
… |
|
187 | 188 | catalog = gettext_module.translation(domain, path, ['en']) |
188 | 189 | t.update(catalog._catalog) |
189 | 190 | except IOError: |
190 | | # 'en' catalog was missing. |
191 | | if locale.startswith('en'): |
192 | | # If 'en' is the selected language this would cause issues |
193 | | # later on if default_locale is something other than 'en'. |
194 | | en_catalog_missing = True |
195 | | # Otherwise it is harmless. |
196 | 191 | pass |
| 192 | else: |
| 193 | # 'en' is the selected language and at least one of the packages |
| 194 | # listed in `packages` has an 'en' catalog |
| 195 | if en_selected: |
| 196 | en_catalog_missing = False |
197 | 197 | # next load the settings.LANGUAGE_CODE translations if it isn't english |
198 | 198 | if default_locale != 'en': |
199 | 199 | for path in paths: |
… |
… |
|
205 | 205 | t.update(catalog._catalog) |
206 | 206 | # last load the currently selected language, if it isn't identical to the default. |
207 | 207 | if locale != default_locale: |
208 | | # If the flag en_catalog_missing has been set, the currently |
209 | | # selected language is English but it doesn't have a translation |
210 | | # catalog (presumably due to being the language translated from). |
211 | | # If that is the case, a wrong language catalog might have been |
212 | | # loaded in the previous step. It needs to be discarded. |
213 | | if en_catalog_missing: |
| 208 | # If the currently selected language is English but it doesn't have a |
| 209 | # translation catalog (presumably due to being the language translated |
| 210 | # from) then a wrong language catalog might have been loaded in the |
| 211 | # previous step. It needs to be discarded. |
| 212 | if en_selected and en_catalog_missing: |
214 | 213 | t = {} |
215 | 214 | else: |
216 | 215 | locale_t = {} |
diff -r 731b9d6d9c9a tests/regressiontests/views/app0/__init__.py
diff -r 731b9d6d9c9a tests/regressiontests/views/app0/locale/en/LC_MESSAGES/djangojs.mo
Binary file tests/regressiontests/views/app0/locale/en/LC_MESSAGES/djangojs.mo has changed
diff -r 731b9d6d9c9a tests/regressiontests/views/app0/locale/en/LC_MESSAGES/djangojs.po
-
|
+
|
|
| 1 | # SOME DESCRIPTIVE TITLE. |
| 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER |
| 3 | # This file is distributed under the same license as the PACKAGE package. |
| 4 | # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
| 5 | # |
| 6 | #, fuzzy |
| 7 | msgid "" |
| 8 | msgstr "" |
| 9 | "Project-Id-Version: PACKAGE VERSION\n" |
| 10 | "Report-Msgid-Bugs-To: \n" |
| 11 | "POT-Creation-Date: 2007-09-15 19:15+0200\n" |
| 12 | "PO-Revision-Date: 2010-05-12 12:41-0300\n" |
| 13 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
| 14 | "Language-Team: LANGUAGE <LL@li.org>\n" |
| 15 | "MIME-Version: 1.0\n" |
| 16 | "Content-Type: text/plain; charset=UTF-8\n" |
| 17 | "Content-Transfer-Encoding: 8bit\n" |
| 18 | |
| 19 | msgid "il faut traduire cette chaîne de caractères de app0" |
| 20 | msgstr "this app0 string is to be translated" |
diff -r 731b9d6d9c9a tests/regressiontests/views/tests/i18n.py
a
|
b
|
|
40 | 40 | |
41 | 41 | def setUp(self): |
42 | 42 | self.old_language_code = settings.LANGUAGE_CODE |
| 43 | self.old_installed_apps = settings.INSTALLED_APPS |
43 | 44 | |
44 | 45 | def tearDown(self): |
| 46 | deactivate() |
45 | 47 | settings.LANGUAGE_CODE = self.old_language_code |
| 48 | settings.INSTALLED_APPS = self.old_installed_apps |
46 | 49 | |
47 | 50 | def test_jsi18n_with_missing_en_files(self): |
48 | 51 | """ |
… |
… |
|
72 | 75 | def testI18NLanguageNonEnglishDefault(self): |
73 | 76 | """ |
74 | 77 | Check if the Javascript i18n view returns an empty language catalog |
75 | | if the default language is non-English but the selected language |
76 | | is English. See #13388 and #3594 for more details. |
| 78 | if the default language is non-English, the selected language |
| 79 | is English and there is not 'en' translation available. See #13388, |
| 80 | #3594 and #13726 for more details. |
77 | 81 | """ |
78 | 82 | settings.LANGUAGE_CODE = 'fr' |
79 | 83 | activate('en-us') |
80 | 84 | response = self.client.get('/views/jsi18n/') |
81 | 85 | self.assertNotContains(response, 'Choisir une heure') |
82 | | deactivate() |
| 86 | |
| 87 | def test_nonenglish_default_english_userpref(self): |
| 88 | """ |
| 89 | Same as above with the difference that there IS an 'en' translation |
| 90 | available. The Javascript i18n view must return a NON empty language catalog |
| 91 | with the proper English translations. See #13726 for more details. |
| 92 | """ |
| 93 | settings.LANGUAGE_CODE = 'fr' |
| 94 | settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.views.app0'] |
| 95 | activate('en-us') |
| 96 | response = self.client.get('/views/jsi18n_english_translation/') |
| 97 | self.assertContains(response, javascript_quote('this app0 string is to be translated')) |
83 | 98 | |
84 | 99 | def testI18NLanguageNonEnglishFallback(self): |
85 | 100 | """ |
… |
… |
|
90 | 105 | activate('none') |
91 | 106 | response = self.client.get('/views/jsi18n/') |
92 | 107 | self.assertContains(response, 'Choisir une heure') |
93 | | deactivate() |
94 | 108 | |
95 | 109 | |
96 | 110 | class JsI18NTestsMultiPackage(TestCase): |
diff -r 731b9d6d9c9a tests/regressiontests/views/urls.py
a
|
b
|
|
16 | 16 | 'packages': ('regressiontests.views',), |
17 | 17 | } |
18 | 18 | |
| 19 | js_info_dict_english_translation = { |
| 20 | 'domain': 'djangojs', |
| 21 | 'packages': ('regressiontests.views.app0',), |
| 22 | } |
| 23 | |
19 | 24 | js_info_dict_multi_packages1 = { |
20 | 25 | 'domain': 'djangojs', |
21 | 26 | 'packages': ('regressiontests.views.app1', 'regressiontests.views.app2'), |
… |
… |
|
46 | 51 | # i18n views |
47 | 52 | (r'^i18n/', include('django.conf.urls.i18n')), |
48 | 53 | (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), |
| 54 | (r'^jsi18n_english_translation/$', 'django.views.i18n.javascript_catalog', js_info_dict_english_translation), |
49 | 55 | (r'^jsi18n_multi_packages1/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages1), |
50 | 56 | (r'^jsi18n_multi_packages2/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages2), |
51 | 57 | |