Ticket #5494: js_catalog_r9076.diff

File js_catalog_r9076.diff, 2.3 KB (added by oggy, 10 years ago)
  • django/views/i18n.py

     
    121121        packages = ['django.conf']
    122122    if type(packages) in (str, unicode):
    123123        packages = packages.split('+')
    124     packages = [p for p in packages if p == 'django.conf' or p in settings.INSTALLED_APPS]
    125124    default_locale = to_locale(settings.LANGUAGE_CODE)
    126125    locale = to_locale(get_language())
    127126    t = {}
    128127    paths = []
    129     # first load all english languages files for defaults
    130128    for package in packages:
    131129        p = __import__(package, {}, {}, [''])
    132130        path = os.path.join(os.path.dirname(p.__file__), 'locale')
    133131        paths.append(path)
    134         try:
    135             catalog = gettext_module.translation(domain, path, ['en'])
    136             t.update(catalog._catalog)
    137         except IOError:
    138             # 'en' catalog was missing. This is harmless.
    139             pass
    140     # next load the settings.LANGUAGE_CODE translations if it isn't english
    141     if default_locale != 'en':
     132    # A list of locales to load. Fallbacks for the requested locale
     133    # are settings.LANGUAGE_CODE and 'en', in that order
     134    locales = ['en']
     135    # Two checks: one to avoid dupes, and another one to skip this
     136    # fallback if the requested language is 'en'
     137    if default_locale != 'en' and locale != 'en':
     138        locales.append(default_locale)
     139    if locale not in locales:
     140        locales.append(locale)
     141    for loc in locales:
    142142        for path in paths:
    143143            try:
    144                 catalog = gettext_module.translation(domain, path, [default_locale])
     144                catalog = gettext_module.translation(domain, path, [loc])
    145145            except IOError:
    146146                catalog = None
    147147            if catalog is not None:
    148148                t.update(catalog._catalog)
    149     # last load the currently selected language, if it isn't identical to the default.
    150     if locale != default_locale:
    151         for path in paths:
    152             try:
    153                 catalog = gettext_module.translation(domain, path, [locale])
    154             except IOError:
    155                 catalog = None
    156             if catalog is not None:
    157                 t.update(catalog._catalog)
    158149    src = [LibHead]
    159150    plural = None
    160151    if '' in t:
Back to Top