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