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

Improve language alias matching

- do it case insensitive
- do it regardless separator
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 27b986d1
......@@ -726,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',
......@@ -736,11 +736,11 @@ LOCALE_ALIASES = {
'in': 'id',
# Prefer new variants
'sr@latin': 'sr_Latn',
'sr_RS@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',
'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
......
......@@ -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,12 +167,9 @@ class LanguageManager(models.Manager):
return ret
# Handle aliases
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
ret = self.aliases_get(code)
if ret is not None:
return ret
# Parse the string
lang, country = self.parse_lang_country(code)
......
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