summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2013-11-05 20:49:19 +0100
committerBaptiste Mispelon <bmispelon@gmail.com>2013-11-06 12:27:35 +0100
commit8265323c9169e95e9e765aa976b0e8065f0bd484 (patch)
treeae4e94bc2575cd3b08a01055387dab9a77c51a56
parent366bdc45661038c199ff7f268d045f6b7cb5c398 (diff)
Distinguish between browser-deprecated locales and internally
deprecated ones. Thanks to bouke for pointing this out.
-rw-r--r--django/utils/translation/trans_real.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 30a92aa3bc..8a7a7fafff 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -49,11 +49,13 @@ accept_language_re = re.compile(r'''
language_code_prefix_re = re.compile(r'^/([\w-]+)(/|$)')
# some browsers use deprecated locales. refs #18419
-_DEPRECATED_LOCALES = {
+_BROWSERS_DEPRECATED_LOCALES = {
'zh-cn': 'zh-hans',
'zh-tw': 'zh-hant',
}
+_DJANGO_DEPRECATED_LOCALES = _BROWSERS_DEPRECATED_LOCALES
+
@receiver(setting_changed)
def reset_cache(**kwargs):
@@ -208,10 +210,10 @@ def activate(language):
language and installs it as the current translation object for the current
thread.
"""
- if language in _DEPRECATED_LOCALES:
+ if language in _DJANGO_DEPRECATED_LOCALES:
msg = ("The use of the language code '%s' is deprecated. "
"Please use the '%s' translation instead.")
- warnings.warn(msg % (language, _DEPRECATED_LOCALES[language]),
+ warnings.warn(msg % (language, _DJANGO_DEPRECATED_LOCALES[language]),
PendingDeprecationWarning, stacklevel=2)
_active.value = translation(language)
@@ -415,9 +417,9 @@ def get_supported_language_variant(lang_code, supported=None, strict=False):
supported = OrderedDict(settings.LANGUAGES)
if lang_code:
# some browsers use deprecated language codes -- #18419
- if (lang_code not in supported and lang_code in _DEPRECATED_LOCALES and
- _DEPRECATED_LOCALES[lang_code] in supported):
- return _DEPRECATED_LOCALES[lang_code]
+ replacement = _BROWSERS_DEPRECATED_LOCALES.get(lang_code)
+ if lang_code not in supported and replacement in supported:
+ return replacement
# if fr-CA is not supported, try fr-ca; if that fails, fallback to fr.
generic_lang_code = lang_code.split('-')[0]
variants = (lang_code, lang_code.lower(), generic_lang_code,