Ticket #750: translation.py.diff

File translation.py.diff, 2.1 KB (added by Esaj <jason at jasondavies.com>, 18 years ago)

Check LANGUAGES setting for language support

  • django/utils/translation.py

     
    259259    This is used to decide whether a user-provided language is available.
    260260    """
    261261    from django.conf import settings
     262    is_supported = False
     263    for l in settings.LANGUAGES:
     264        if lang_code == l[0]:
     265            is_supported = True
     266    if not is_supported:
     267        return False
    262268    globalpath = os.path.join(os.path.dirname(settings.__file__), 'locale')
    263269    if gettext_module.find('django', globalpath, [to_locale(lang_code)]) is not None:
    264270        return True
     
    306312        langs.sort(lambda a,b: -1*cmp(a[1], b[1]))
    307313
    308314        for lang, order in langs:
    309             langfile = gettext_module.find('django', globalpath, [to_locale(lang)])
    310             if langfile:
    311                 # reconstruct the actual language from the language
    312                 # filename, because otherwise we might incorrectly
    313                 # report de_DE if we only have de available, but
    314                 # did find de_DE because of language normalization
    315                 lang = langfile[len(globalpath):].split(os.path.sep)[1]
    316                 _accepted[accept] = lang
    317                 return lang
     315            is_supported = False
     316            for l in settings.LANGUAGES:
     317                if lang == l[0]:
     318                    is_supported = True
     319            if is_supported:
     320                langfile = gettext_module.find('django', globalpath, [to_locale(lang)])
     321                if langfile:
     322                    # reconstruct the actual language from the language
     323                    # filename, because otherwise we might incorrectly
     324                    # report de_DE if we only have de available, but
     325                    # did find de_DE because of language normalization
     326                    lang = langfile[len(globalpath):].split(os.path.sep)[1]
     327                    _accepted[accept] = lang
     328                    return lang
    318329
    319330    return settings.LANGUAGE_CODE
    320331
Back to Top