Commit 5b1adfe3 authored by Weblate's avatar Weblate

Merge remote-tracking branch 'origin/master'

parents 952fccb5 da0167e5
......@@ -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'
))
......@@ -725,9 +726,9 @@ LOCALE_ALIASES = {
'german': 'de',
'french': 'fr',
# Android
'be-rBY': 'be@latin',
'be-rby': 'be@latin',
# Misc invalid codes
'val-ES': 'ca@valencia',
'val_es': 'ca@valencia',
'jp': 'ja',
# Old locale codes
'iw': 'he',
......@@ -735,7 +736,9 @@ LOCALE_ALIASES = {
'in': 'id',
# Prefer new variants
'sr@latin': 'sr_Latn',
'sr_rs@latin': 'sr_Latn',
'sr@cyrillic': 'sr_Cyrl',
'sr_rs@cyrillic': 'sr_Cyrl',
'zh_cn': 'zh_Hans',
'zh_tw': 'zh_Hant',
}
......
......@@ -132,6 +132,21 @@ class LanguageManager(models.Manager):
code = code[:-1]
return code
def aliases_get(self, code):
code = code.lower()
codes = (
code,
code.replace('-', '_'),
code.replace('-r', '_')
)
for newcode in codes:
if newcode in data.LOCALE_ALIASES:
newcode = data.LOCALE_ALIASES[newcode]
ret = self.try_get(code=newcode)
if ret is not None:
return ret
return None
def fuzzy_get(self, code):
'''
Gets matching language for code (the code does not have to be exactly
......@@ -152,11 +167,9 @@ 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
ret = self.aliases_get(code)
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