Commit f82624f1 authored by Michal Čihař's avatar Michal Čihař

Support Android regional locales (fixes #292).

parent f9fc568d
......@@ -107,6 +107,8 @@ class LanguageManager(models.Manager):
'''
Gets matching language for code (the code does not have to be exactly
same, cs_CZ is same as cs-CZ) or creates new one.
It also handles Android special naming of regional locales like pt-rBR
'''
# First try getting langauge as is
......@@ -118,6 +120,9 @@ class LanguageManager(models.Manager):
# Parse the string
if '-' in code:
lang, country = code.split('-', 1)
# Android regional locales
if len(country) > 2 and country[0] == 'r':
country = country[1:]
elif '_' in code:
lang, country = code.split('_', 1)
else:
......
......@@ -32,6 +32,7 @@ class LanguagesTest(TestCase):
('cs_CZ', 'cs', 'ltr'),
('de-DE', 'de', 'ltr'),
('de_AT', 'de_AT', 'ltr'),
('pt-rBR', 'pt_BR', 'ltr'),
('ar', 'ar', 'rtl'),
('ar_AA', 'ar', 'rtl'),
('ar_XX', 'ar_XX', 'rtl'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment