Ticket #3594: jsi18n_11620.patch
File jsi18n_11620.patch, 4.8 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/views/locale/en/LC_MESSAGES/djangojs.po
1 # SOME DESCRIPTIVE TITLE.2 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER3 # This file is distributed under the same license as the PACKAGE package.4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.5 #6 #, fuzzy7 msgid ""8 msgstr ""9 "Project-Id-Version: PACKAGE VERSION\n"10 "Report-Msgid-Bugs-To: \n"11 "POT-Creation-Date: 2007-09-15 16:45+0200\n"12 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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 "this is to be translated"20 msgstr "this is to be translated in english"21 No newline at end of file -
tests/regressiontests/views/tests/i18n.py
20 20 21 21 def test_jsi18n(self): 22 22 """The javascript_catalog can be deployed with language settings""" 23 for lang_code in ['es', 'fr' , 'en']:23 for lang_code in ['es', 'fr']: 24 24 activate(lang_code) 25 25 catalog = gettext.translation('djangojs', locale_dir, [lang_code]) 26 26 trans_txt = catalog.ugettext('this is to be translated') … … 28 28 # in response content must to be a line like that: 29 29 # catalog['this is to be translated'] = 'same_that_trans_txt' 30 30 self.assertContains(response, trans_txt, 1) 31 32 def test_jsi18n_with_missing_en_locale(self): 33 """ 34 The javascript_catalog shouldn't load the fallback language in the 35 case that the current selected language is actually the one translated 36 from, and hence missing translation files completely. 37 38 This happens easily when you're translating from English to other 39 languages and you've set settings.LANGUAGE_CODE to some other language 40 than English. 41 """ 42 settings.LANGUAGE_CODE = 'es' 43 activate('en-us') 44 response = self.client.get('/views/jsi18n/') 45 self.assertNotContains(response, 'esto tiene que ser traducido') -
django/views/i18n.py
127 127 locale = to_locale(get_language()) 128 128 t = {} 129 129 paths = [] 130 en_catalog_missing = False 130 131 # first load all english languages files for defaults 131 132 for package in packages: 132 133 p = importlib.import_module(package) … … 136 137 catalog = gettext_module.translation(domain, path, ['en']) 137 138 t.update(catalog._catalog) 138 139 except IOError: 139 # 'en' catalog was missing. This is harmless. 140 if locale.startswith('en'): 141 # 'en' catalog was missing, but it is the selected language. 142 # This would cause issues later on if default_locale is 143 # something other than 'en'. 144 en_catalog_missing = True 145 # Otherwise it is harmless. 140 146 pass 141 # next load the settings.LANGUAGE_CODE translationsif it isn't english142 if default_locale != 'en':147 # next load the currently selected language, if it isn't english 148 if locale != 'en': 143 149 for path in paths: 144 150 try: 145 catalog = gettext_module.translation(domain, path, [default_locale])146 except IOError:147 catalog = None148 if catalog is not None:149 t.update(catalog._catalog)150 # last load the currently selected language, if it isn't identical to the default.151 if locale != default_locale:152 for path in paths:153 try:154 151 catalog = gettext_module.translation(domain, path, [locale]) 155 152 except IOError: 156 153 catalog = None 157 154 if catalog is not None: 158 155 t.update(catalog._catalog) 156 # If the flag en_catalog_missing has been set, the currently 157 # selected language is English but it doesn't have a translation 158 # catalog (presumably due to being the language translated from). 159 # If that is the case, a wrong language catalog might have been 160 # loaded in the previous step. It needs to be discarded. 161 if en_catalog_missing: 162 t = {} 159 163 src = [LibHead] 160 164 plural = None 161 165 if '' in t: