mirror of
https://github.com/django/django.git
synced 2025-11-01 20:31:40 +00:00
Fixed #32479 -- Added fallbacks to subsequent language codes in translations.
Thanks Claude Paroz and Nick Pope for reviews.
This commit is contained in:
parent
96f55ccf79
commit
06fd4df41a
2 changed files with 26 additions and 3 deletions
|
|
@ -1424,6 +1424,26 @@ class MiscTests(SimpleTestCase):
|
|||
r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-my,en'}
|
||||
self.assertEqual(get_language_from_request(r), 'zh-hans')
|
||||
|
||||
def test_subsequent_code_fallback_language(self):
|
||||
"""
|
||||
Subsequent language codes should be used when the language code is not
|
||||
supported.
|
||||
"""
|
||||
tests = [
|
||||
('zh-Hans-CN', 'zh-hans'),
|
||||
('zh-hans-mo', 'zh-hans'),
|
||||
('zh-hans-HK', 'zh-hans'),
|
||||
('zh-Hant-HK', 'zh-hant'),
|
||||
('zh-hant-tw', 'zh-hant'),
|
||||
('zh-hant-SG', 'zh-hant'),
|
||||
]
|
||||
r = self.rf.get('/')
|
||||
r.COOKIES = {}
|
||||
for value, expected in tests:
|
||||
with self.subTest(value=value):
|
||||
r.META = {'HTTP_ACCEPT_LANGUAGE': f'{value},en'}
|
||||
self.assertEqual(get_language_from_request(r), expected)
|
||||
|
||||
def test_parse_language_cookie(self):
|
||||
"""
|
||||
Now test that we parse language preferences stored in a cookie correctly.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue