diff options
| author | Bouke Haarsma <bouke@webatoom.nl> | 2013-11-04 18:31:34 +0100 |
|---|---|---|
| committer | Bouke Haarsma <bouke@webatoom.nl> | 2013-11-04 23:03:28 +0100 |
| commit | c0a2388a1c4ead1afaec98e4ebc953a772ca3849 (patch) | |
| tree | 8cc17cbee0032c9597e69cd53837d9573099541e /tests | |
| parent | cb2c3ce15443a0666646e8b60984830c38d3ecde (diff) | |
Fixed #18149 -- Changed language codes for Chinese
Language codes for Chinese are zh_Hans (Simplified) and zh_Hant (Traditional).
Added support for browsers that still send the deprecated language codes.
Thanks to Olli Wang for the report.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/deprecation/tests.py | 23 | ||||
| -rw-r--r-- | tests/i18n/tests.py | 25 |
2 files changed, 46 insertions, 2 deletions
diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py index f949bea24e..7d9ed16636 100644 --- a/tests/deprecation/tests.py +++ b/tests/deprecation/tests.py @@ -1,8 +1,8 @@ from __future__ import unicode_literals import warnings -from django.test import SimpleTestCase, RequestFactory -from django.utils import six +from django.test import SimpleTestCase, RequestFactory, override_settings +from django.utils import six, translation from django.utils.deprecation import RenameMethodsBase @@ -186,3 +186,22 @@ class DeprecatingRequestMergeDictTest(SimpleTestCase): '`request.POST` instead.', '`MergeDict` is deprecated, use `dict.update()` instead.', ]) + + +@override_settings(USE_I18N=True) +class DeprecatedChineseLanguageCodes(SimpleTestCase): + def test_deprecation_warning(self): + warnings.simplefilter('always') + + with warnings.catch_warnings(record=True) as recorded: + with translation.override('zh-cn'): + pass + with translation.override('zh-tw'): + pass + msgs = [str(warning.message) for warning in recorded] + self.assertEqual(msgs, [ + "The use of the language code 'zh-cn' is deprecated. " + "Please use the 'zh-hans' translation instead.", + "The use of the language code 'zh-tw' is deprecated. " + "Please use the 'zh-hant' translation instead.", + ]) diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 76f59bf919..f68a7361f6 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -871,6 +871,31 @@ class MiscTests(TransRealMixin, TestCase): r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,de'} self.assertEqual(g(r), 'zh-cn') + @override_settings( + LANGUAGES=( + ('en', 'English'), + ('zh-hans', 'Simplified Chinese'), + ('zh-hant', 'Traditional Chinese'), + ) + ) + def test_support_for_deprecated_chinese_language_codes(self): + """ + Some browsers (Firefox, IE etc) use deprecated language codes. As these + language codes will be removed in Django 1.9, these will be incorrectly + matched. For example zh-tw (traditional) will be interpreted as zh-hans + (simplified), which is wrong. So we should also accept these deprecated + language codes. + + refs #18419 -- this is explicitly for browser compatibility + """ + g = get_language_from_request + r = self.rf.get('/') + r.COOKIES = {} + r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,en'} + self.assertEqual(g(r), 'zh-hans') + r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-tw,en'} + self.assertEqual(g(r), 'zh-hant') + def test_parse_language_cookie(self): """ Now test that we parse language preferences stored in a cookie correctly. |
