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):
code = code.lower()
if len(code) == 2:
for l in _iso639_languages:
if l[2] == code:
return l[0]
elif len(code) == 3:
for l in _iso639_languages:
if l[3] == code:
return l[0]
if code:
code = code.lower()
if len(code) == 2:
for l in _iso639_languages:
if l[2] == code:
return l[0]
elif len(code) == 3:
for l in _iso639_languages:
if l[3] == code:
return l[0]
return None
def langTo3Code(lang):
lang = langEnglishName(lang)
if lang:
lang=lang.lower()
for l in _iso639_languages:
if l[0].lower() == lang:
return l[3]
lang = langEnglishName(lang)
if lang:
lang=lang.lower()
for l in _iso639_languages:
if l[0].lower() == lang:
return l[3]
return None
def langTo2Code(lang):
lang = langEnglishName(lang)
if lang:
lang=lang.lower()
for l in _iso639_languages:
if l[0].lower() == lang:
return l[2]
lang = langEnglishName(lang)
if lang:
lang=lang.lower()
for l in _iso639_languages:
if l[0].lower() == lang:
return l[2]
return None
def langCode2To3(code):
@ -230,7 +233,7 @@ def langCode3To2(code):
def langEnglishName(lang):
lang = lang.lower()
for l in _iso639_languages:
if l[1].lower() == lang:
if l[1].lower() == lang or l[0].lower() == lang:
return l[0]
return None