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