From 9edf30085e3ba22adc81cde02f782e04055b2989 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 3 Sep 2014 13:48:11 +0200 Subject: [PATCH] fix ox.iso language lookup --- ox/iso.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/ox/iso.py b/ox/iso.py index 3b92acb..6c28435 100644 --- a/ox/iso.py +++ b/ox/iso.py @@ -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