factor langDir into separate func

This commit is contained in:
Damien Elmes 2012-04-18 03:19:47 +09:00
parent a0578f73d1
commit cbdd152f36

View file

@ -63,15 +63,16 @@ def _(str):
def ngettext(single, plural, n):
return localTranslation().ungettext(single, plural, n)
def langDir():
dir = os.path.join(os.path.dirname(
os.path.abspath(__file__)), "locale")
if not os.path.exists(dir):
dir = os.path.join(os.path.dirname(sys.argv[0]), "locale")
return dir
def setLang(lang, local=True):
base = os.path.dirname(os.path.abspath(__file__))
localeDir = os.path.join(base, "locale")
if not os.path.exists(localeDir):
localeDir = os.path.join(
os.path.dirname(sys.argv[0]), "locale")
trans = gettext.translation('libanki', localeDir,
languages=[lang],
fallback=True)
trans = gettext.translation(
'libanki', langDir(), languages=[lang], fallback=True)
if local:
threadLocal.currentLang = lang
threadLocal.currentTranslation = trans