Ticket #6409: lang-code-fix.diff

File lang-code-fix.diff, 1.6 KB (added by Simon Blanchard, 17 years ago)
  • django/utils/translation/trans_real.py

     
    357357        return lang_code
    358358
    359359    accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '')
    360     for lang, unused in parse_accept_lang_header(accept):
    361         if lang == '*':
     360    for accept_lang, unused in parse_accept_lang_header(accept):
     361        if accept_lang == '*':
    362362            break
    363363
    364364        # We have a very restricted form for our language files (no encoding
     
    366366        # language each time. So we avoid the overhead of gettext.find() and
    367367        # look up the MO file manually.
    368368
    369         normalized = locale.locale_alias.get(to_locale(lang, True))
     369        normalized = locale.locale_alias.get(to_locale(accept_lang, True))
    370370        if not normalized:
    371371            continue
    372372
     
    378378            # need to check again.
    379379            return _accepted[normalized]
    380380
    381         for lang in (normalized, normalized.split('_')[0]):
     381        for lang in (accept_lang, accept_lang.split('-')[0]):
    382382            if lang not in supported:
    383383                continue
    384             langfile = os.path.join(globalpath, lang, 'LC_MESSAGES',
     384            normalized = locale.locale_alias.get(to_locale(lang, True)).split('.')[0]
     385            langfile = os.path.join(globalpath, normalized, 'LC_MESSAGES',
    385386                    'django.mo')
    386387            if os.path.exists(langfile):
    387388                _accepted[normalized] = lang
Back to Top