Commit 27b986d1 authored by Michal Čihař's avatar Michal Čihař

Improve language aliases handling

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent c8b85314
......@@ -405,6 +405,7 @@ EXTRALANGS = (
NO_CODE_LANGUAGES = frozenset((
'zh_TW', 'zh_CN',
'zh_Hant', 'zh_Hans',
'sr_Latn', 'sr_Cyrl',
'de_AT', 'de_CH'
))
......@@ -735,9 +736,11 @@ LOCALE_ALIASES = {
'in': 'id',
# Prefer new variants
'sr@latin': 'sr_Latn',
'sr_RS@latin': 'sr_Latn',
'sr@cyrillic': 'sr_Cyrl',
'zh_cn': 'zh_Hans',
'zh_tw': 'zh_Hant',
'sr_RS@cyrillic': 'sr_Cyrl',
'zh_CN': 'zh_Hans',
'zh_TW': 'zh_Hant',
}
# List of languages we do not want to import from translate-toolkit
......
......@@ -152,11 +152,12 @@ class LanguageManager(models.Manager):
return ret
# Handle aliases
if code in data.LOCALE_ALIASES:
code = data.LOCALE_ALIASES[code]
ret = self.try_get(name=code)
if ret is not None:
return ret
for newcode in (code, code.replace('-', '_'), code.replace('-r', '_')):
if newcode in data.LOCALE_ALIASES:
newcode = data.LOCALE_ALIASES[newcode]
ret = self.try_get(code=newcode)
if ret is not None:
return ret
# Parse the string
lang, country = self.parse_lang_country(code)
......
......@@ -100,7 +100,7 @@ class LanguagesTest(TestCase):
),
(
'sr_RS@latin',
'sr_RS@latin',
'sr_Latn',
'ltr',
'n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && '
'(n%100<10 || n%100>=20) ? 1 : 2',
......@@ -108,15 +108,15 @@ class LanguagesTest(TestCase):
),
(
'sr-RS@latin',
'sr_RS@latin',
'sr_Latn',
'ltr',
'n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && '
'(n%100<10 || n%100>=20) ? 1 : 2',
'Serbian (latin)',
),
(
'sr_RS_Latin',
'sr_RS@latin',
'sr_Latn',
'ltr',
'n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && '
'(n%100<10 || n%100>=20) ? 1 : 2',
......@@ -138,31 +138,31 @@ class LanguagesTest(TestCase):
),
(
'zh_CN',
'zh_CN',
'zh_Hans',
'ltr',
'0',
'Chinese (China)',
'Simplified Chinese',
),
(
'zh-CN',
'zh_CN',
'zh_Hans',
'ltr',
'0',
'Chinese (China)',
'Simplified Chinese',
),
(
'zh-CN@test',
'zh_CN@test',
'ltr',
'0',
'Chinese (China)',
'Chinese (zh_CN@test)',
),
(
'zh-rCN',
'zh_CN',
'zh_Hans',
'ltr',
'0',
'Chinese (China)',
'Simplified Chinese',
),
(
'ar',
......
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