diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-07-11 21:01:37 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-07-14 20:50:03 +0200 |
| commit | 5dcdbe95c749d36072f527e120a8cb463199ae0d (patch) | |
| tree | 7c3c4d0dac2220647212a2b342a8d1a3dc77d203 /tests | |
| parent | dd9b3312d0a931daf21c10279cef204f04648ef9 (diff) | |
Fixed #23005 -- Allowed specifying special fallback languages
This fixes the Chinese language issues described in #23005 but
also provides for other fallback exceptions by updating the
LANG_INFO structure.
Thanks caxekis at gmail.com for the report and Tim Graham for the
review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/i18n/tests.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index d07c0d94a0..986b4bfa1e 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -983,6 +983,16 @@ class MiscTests(TestCase): r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-tw,en'} self.assertEqual(g(r), 'zh-tw') + def test_special_fallback_language(self): + """ + Some languages may have special fallbacks that don't follow the simple + 'fr-ca' -> 'fr' logic (notably Chinese codes). + """ + r = self.rf.get('/') + r.COOKIES = {} + r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-my,en'} + self.assertEqual(get_language_from_request(r), 'zh-hans') + def test_parse_language_cookie(self): """ Now test that we parse language preferences stored in a cookie correctly. @@ -1156,6 +1166,16 @@ class TestLanguageInfo(TestCase): def test_unknown_language_code_and_country_code(self): six.assertRaisesRegex(self, KeyError, r"Unknown language code xx-xx and xx\.", get_language_info, 'xx-xx') + def test_fallback_language_code(self): + """ + get_language_info return the first fallback language info if the lang_info + struct does not contain the 'name' key. + """ + li = get_language_info('zh-my') + self.assertEqual(li['code'], 'zh-hans') + li = get_language_info('zh-cn') + self.assertEqual(li['code'], 'zh-cn') + class MultipleLocaleActivationTests(TestCase): """ |
