Ticket #3594: javascript_translation_catalog.patch

File javascript_translation_catalog.patch, 1.7 KB (added by Aku Kotkavuo, 15 years ago)

Fixed a case where translating from English but setting settings.LANGUAGE_CODE to something else would always choose that translation without the (unnecessary) English translation files.

  • django/views/i18n.py

     
    126126    locale = to_locale(get_language())
    127127    t = {}
    128128    paths = []
     129    en_catalog_missing = False
    129130    # first load all english languages files for defaults
    130131    for package in packages:
    131132        p = __import__(package, {}, {}, [''])
     
    135136            catalog = gettext_module.translation(domain, path, ['en'])
    136137            t.update(catalog._catalog)
    137138        except IOError:
    138             # 'en' catalog was missing. This is harmless.
     139            if locale.startswith('en'):
     140                # 'en' catalog was missing, but it is the selected language.
     141                # This would cause issues later on if default_locale is
     142                # something other than 'en'.
     143                en_catalog_missing = True
     144            # Otherwise it is harmless.
    139145            pass
    140146    # next load the settings.LANGUAGE_CODE translations if it isn't english
    141147    if default_locale != 'en':
     
    155161                catalog = None
    156162            if catalog is not None:
    157163                t.update(catalog._catalog)
     164        # If the flag en_catalog_missing has been set, the currently
     165        # selected language is English but it doesn't have a translation
     166        # catalog (presumably due to being the language translated from).
     167        # If that is the case, a wrong language catalog might have been
     168        # loaded in the previous step. It needs to be discarded.
     169        if en_catalog_missing:
     170            t = {}
    158171    src = [LibHead]
    159172    plural = None
    160173    if '' in t:
Back to Top