fix ox.iso language lookup

This commit is contained in:
j 2014-09-03 13:48:11 +02:00
parent 3f15161bed
commit 9edf30085e

View file

@ -192,33 +192,36 @@ _iso639_languages = [
] ]
def codeToLang(code): def codeToLang(code):
code = code.lower() if code:
if len(code) == 2: code = code.lower()
for l in _iso639_languages: if len(code) == 2:
if l[2] == code: for l in _iso639_languages:
return l[0] if l[2] == code:
elif len(code) == 3: return l[0]
for l in _iso639_languages: elif len(code) == 3:
if l[3] == code: for l in _iso639_languages:
return l[0] if l[3] == code:
return l[0]
return None return None
def langTo3Code(lang): def langTo3Code(lang):
lang = langEnglishName(lang)
if lang: if lang:
lang=lang.lower() lang = langEnglishName(lang)
for l in _iso639_languages: if lang:
if l[0].lower() == lang: lang=lang.lower()
return l[3] for l in _iso639_languages:
if l[0].lower() == lang:
return l[3]
return None return None
def langTo2Code(lang): def langTo2Code(lang):
lang = langEnglishName(lang)
if lang: if lang:
lang=lang.lower() lang = langEnglishName(lang)
for l in _iso639_languages: if lang:
if l[0].lower() == lang: lang=lang.lower()
return l[2] for l in _iso639_languages:
if l[0].lower() == lang:
return l[2]
return None return None
def langCode2To3(code): def langCode2To3(code):
@ -230,7 +233,7 @@ def langCode3To2(code):
def langEnglishName(lang): def langEnglishName(lang):
lang = lang.lower() lang = lang.lower()
for l in _iso639_languages: for l in _iso639_languages:
if l[1].lower() == lang: if l[1].lower() == lang or l[0].lower() == lang:
return l[0] return l[0]
return None return None