Ticket #3594: jsi18n_11620.patch

File jsi18n_11620.patch, 4.8 KB (added by Manuel Saelices, 15 years ago)

Uploaded a working patch with english and not english fallback language and with regression test included. Works with [11620] revision

  • tests/regressiontests/views/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 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

     
    2020
    2121    def test_jsi18n(self):
    2222        """The javascript_catalog can be deployed with language settings"""
    23         for lang_code in ['es', 'fr', 'en']:
     23        for lang_code in ['es', 'fr']:
    2424            activate(lang_code)
    2525            catalog = gettext.translation('djangojs', locale_dir, [lang_code])
    2626            trans_txt = catalog.ugettext('this is to be translated')
     
    2828            # in response content must to be a line like that:
    2929            # catalog['this is to be translated'] = 'same_that_trans_txt'
    3030            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

     
    127127    locale = to_locale(get_language())
    128128    t = {}
    129129    paths = []
     130    en_catalog_missing = False
    130131    # first load all english languages files for defaults
    131132    for package in packages:
    132133        p = importlib.import_module(package)
     
    136137            catalog = gettext_module.translation(domain, path, ['en'])
    137138            t.update(catalog._catalog)
    138139        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.
    140146            pass
    141     # next load the settings.LANGUAGE_CODE translations if it isn't english
    142     if default_locale != 'en':
     147    # next load the currently selected language, if it isn't english
     148    if locale != 'en':
    143149        for path in paths:
    144150            try:
    145                 catalog = gettext_module.translation(domain, path, [default_locale])
    146             except IOError:
    147                 catalog = None
    148             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:
    154151                catalog = gettext_module.translation(domain, path, [locale])
    155152            except IOError:
    156153                catalog = None
    157154            if catalog is not None:
    158155                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 = {}
    159163    src = [LibHead]
    160164    plural = None
    161165    if '' in t:
Back to Top