Distinguish between browser-deprecated locales and internally
deprecated ones. Thanks to bouke for pointing this out.
This commit is contained in:
parent
366bdc4566
commit
8265323c91
|
@ -49,11 +49,13 @@ accept_language_re = re.compile(r'''
|
||||||
language_code_prefix_re = re.compile(r'^/([\w-]+)(/|$)')
|
language_code_prefix_re = re.compile(r'^/([\w-]+)(/|$)')
|
||||||
|
|
||||||
# some browsers use deprecated locales. refs #18419
|
# some browsers use deprecated locales. refs #18419
|
||||||
_DEPRECATED_LOCALES = {
|
_BROWSERS_DEPRECATED_LOCALES = {
|
||||||
'zh-cn': 'zh-hans',
|
'zh-cn': 'zh-hans',
|
||||||
'zh-tw': 'zh-hant',
|
'zh-tw': 'zh-hant',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_DJANGO_DEPRECATED_LOCALES = _BROWSERS_DEPRECATED_LOCALES
|
||||||
|
|
||||||
|
|
||||||
@receiver(setting_changed)
|
@receiver(setting_changed)
|
||||||
def reset_cache(**kwargs):
|
def reset_cache(**kwargs):
|
||||||
|
@ -208,10 +210,10 @@ def activate(language):
|
||||||
language and installs it as the current translation object for the current
|
language and installs it as the current translation object for the current
|
||||||
thread.
|
thread.
|
||||||
"""
|
"""
|
||||||
if language in _DEPRECATED_LOCALES:
|
if language in _DJANGO_DEPRECATED_LOCALES:
|
||||||
msg = ("The use of the language code '%s' is deprecated. "
|
msg = ("The use of the language code '%s' is deprecated. "
|
||||||
"Please use the '%s' translation instead.")
|
"Please use the '%s' translation instead.")
|
||||||
warnings.warn(msg % (language, _DEPRECATED_LOCALES[language]),
|
warnings.warn(msg % (language, _DJANGO_DEPRECATED_LOCALES[language]),
|
||||||
PendingDeprecationWarning, stacklevel=2)
|
PendingDeprecationWarning, stacklevel=2)
|
||||||
_active.value = translation(language)
|
_active.value = translation(language)
|
||||||
|
|
||||||
|
@ -415,9 +417,9 @@ def get_supported_language_variant(lang_code, supported=None, strict=False):
|
||||||
supported = OrderedDict(settings.LANGUAGES)
|
supported = OrderedDict(settings.LANGUAGES)
|
||||||
if lang_code:
|
if lang_code:
|
||||||
# some browsers use deprecated language codes -- #18419
|
# some browsers use deprecated language codes -- #18419
|
||||||
if (lang_code not in supported and lang_code in _DEPRECATED_LOCALES and
|
replacement = _BROWSERS_DEPRECATED_LOCALES.get(lang_code)
|
||||||
_DEPRECATED_LOCALES[lang_code] in supported):
|
if lang_code not in supported and replacement in supported:
|
||||||
return _DEPRECATED_LOCALES[lang_code]
|
return replacement
|
||||||
# if fr-CA is not supported, try fr-ca; if that fails, fallback to fr.
|
# if fr-CA is not supported, try fr-ca; if that fails, fallback to fr.
|
||||||
generic_lang_code = lang_code.split('-')[0]
|
generic_lang_code = lang_code.split('-')[0]
|
||||||
variants = (lang_code, lang_code.lower(), generic_lang_code,
|
variants = (lang_code, lang_code.lower(), generic_lang_code,
|
||||||
|
|
Loading…
Reference in New Issue