mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Fixed #19811 - Added language code fallback in get_language_info.
This commit is contained in:
parent
5278776a88
commit
6bd6a56896
@ -187,4 +187,10 @@ def get_language_info(lang_code):
|
|||||||
try:
|
try:
|
||||||
return LANG_INFO[lang_code]
|
return LANG_INFO[lang_code]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
if '-' in lang_code:
|
||||||
|
splited_lang_code = lang_code.split('-')[0]
|
||||||
|
try:
|
||||||
|
return LANG_INFO[splited_lang_code]
|
||||||
|
except KeyError:
|
||||||
|
raise KeyError("Unknown language code %r and %r." % (lang_code, splited_lang_code))
|
||||||
raise KeyError("Unknown language code %r." % lang_code)
|
raise KeyError("Unknown language code %r." % lang_code)
|
||||||
|
@ -956,6 +956,21 @@ class TestLanguageInfo(TestCase):
|
|||||||
self.assertEqual(li['name'], 'German')
|
self.assertEqual(li['name'], 'German')
|
||||||
self.assertEqual(li['bidi'], False)
|
self.assertEqual(li['bidi'], False)
|
||||||
|
|
||||||
|
def test_unknown_language_code(self):
|
||||||
|
with self.assertRaisesRegexp(KeyError, "Unknown language code u\'xx\'."):
|
||||||
|
get_language_info('xx')
|
||||||
|
|
||||||
|
def test_unknown_only_country_code(self):
|
||||||
|
li = get_language_info('de-xx')
|
||||||
|
self.assertEqual(li['code'], 'de')
|
||||||
|
self.assertEqual(li['name_local'], 'Deutsch')
|
||||||
|
self.assertEqual(li['name'], 'German')
|
||||||
|
self.assertEqual(li['bidi'], False)
|
||||||
|
|
||||||
|
def test_unknown_language_code_and_country_code(self):
|
||||||
|
with self.assertRaisesRegexp(KeyError, "Unknown language code u\'xx-xx\' and u\'xx\'."):
|
||||||
|
get_language_info('xx-xx')
|
||||||
|
|
||||||
|
|
||||||
class MultipleLocaleActivationTests(TestCase):
|
class MultipleLocaleActivationTests(TestCase):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user