dont fail if no name exists

This commit is contained in:
j 2008-06-02 15:04:56 +02:00
parent c6930c883a
commit 22f6b39ad0

View file

@ -191,7 +191,7 @@ _iso639_languages = [
("Zulu", "", "zu", "zul"), ("Zulu", "", "zu", "zul"),
] ]
def langFromCode(code): def codeToLang(code):
code = code.lower() code = code.lower()
if len(code) == 2: if len(code) == 2:
for l in _iso639_languages: for l in _iso639_languages:
@ -204,24 +204,28 @@ def langFromCode(code):
return None return None
def langTo3Code(lang): def langTo3Code(lang):
lang = englishName(lang).lower() lang = englishName(lang)
if lang:
lang=lang.lower()
for l in _iso639_languages: for l in _iso639_languages:
if l[0].lower() == lang: if l[0].lower() == lang:
return l[3] return l[3]
return None return None
def langTo2Code(lang): def langTo2Code(lang):
lang = englishName(lang).lower() lang = englishName(lang)
if lang:
lang=lang.lower()
for l in _iso639_languages: for l in _iso639_languages:
if l[0].lower() == lang: if l[0].lower() == lang:
return l[2] return l[2]
return None return None
def langCode2To3(code): def langCode2To3(code):
langTo3Code(langFromCode(code)) langTo3Code(codeToLang(code))
def langCode3To2(code): def langCode3To2(code):
langTo2Code(langFromCode(code)) langTo2Code(codeToLang(code))
def englishName(lang): def englishName(lang):
lang = lang.lower() lang = lang.lower()