Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Distinguish between browser-deprecated locales and internally

deprecated ones.

Thanks to bouke for pointing this out.
  • Loading branch information...
commit 8265323c9169e95e9e765aa976b0e8065f0bd484 1 parent 366bdc4
Baptiste Mispelon authored November 05, 2013

Showing 1 changed file with 8 additions and 6 deletions. Show diff stats Hide diff stats

  1. 14  django/utils/translation/trans_real.py
14  django/utils/translation/trans_real.py
@@ -49,11 +49,13 @@
49 49
 language_code_prefix_re = re.compile(r'^/([\w-]+)(/|$)')
50 50
 
51 51
 # some browsers use deprecated locales. refs #18419
52  
-_DEPRECATED_LOCALES = {
  52
+_BROWSERS_DEPRECATED_LOCALES  = {
53 53
     'zh-cn': 'zh-hans',
54 54
     'zh-tw': 'zh-hant',
55 55
 }
56 56
 
  57
+_DJANGO_DEPRECATED_LOCALES = _BROWSERS_DEPRECATED_LOCALES
  58
+
57 59
 
58 60
 @receiver(setting_changed)
59 61
 def reset_cache(**kwargs):
@@ -208,10 +210,10 @@ def activate(language):
208 210
     language and installs it as the current translation object for the current
209 211
     thread.
210 212
     """
211  
-    if language in _DEPRECATED_LOCALES:
  213
+    if language in _DJANGO_DEPRECATED_LOCALES:
212 214
         msg = ("The use of the language code '%s' is deprecated. "
213 215
                "Please use the '%s' translation instead.")
214  
-        warnings.warn(msg % (language, _DEPRECATED_LOCALES[language]),
  216
+        warnings.warn(msg % (language, _DJANGO_DEPRECATED_LOCALES[language]),
215 217
                       PendingDeprecationWarning, stacklevel=2)
216 218
     _active.value = translation(language)
217 219
 
@@ -415,9 +417,9 @@ def get_supported_language_variant(lang_code, supported=None, strict=False):
415 417
         supported = OrderedDict(settings.LANGUAGES)
416 418
     if lang_code:
417 419
         # some browsers use deprecated language codes -- #18419
418  
-        if (lang_code not in supported and lang_code in _DEPRECATED_LOCALES and
419  
-                _DEPRECATED_LOCALES[lang_code] in supported):
420  
-            return _DEPRECATED_LOCALES[lang_code]
  420
+        replacement = _BROWSERS_DEPRECATED_LOCALES.get(lang_code)
  421
+        if lang_code not in supported and replacement in supported:
  422
+            return replacement
421 423
         # if fr-CA is not supported, try fr-ca; if that fails, fallback to fr.
422 424
         generic_lang_code = lang_code.split('-')[0]
423 425
         variants = (lang_code, lang_code.lower(), generic_lang_code,

0 notes on commit 8265323

Please sign in to comment.
Something went wrong with that request. Please try again.