Localization module is now initialized only once (instead of twice).

This removes an unnecessary initialization and also fixes the behavior
under Windows which was broken because of the second initialization.
This commit is contained in:
Adam Waldenberg 2013-07-04 10:55:54 +02:00
parent 7bc297e99f
commit 663493fd41

View file

@ -24,24 +24,30 @@ import gettext
import locale
import os
__installed__ = False
def init():
try:
locale.setlocale(locale.LC_ALL, "")
except locale.Error:
translation = gettext.NullTranslations()
else:
lang = locale.getlocale()
#Fix for non-POSIX-compliant systems (Windows et al.).
if os.getenv('LANG') is None:
lang = locale.getdefaultlocale()
os.environ['LANG'] = lang[0]
filename = basedir.get_basedir() + "/translations/messages_%s.mo" % lang[0][0:2]
global __installed__
if not __installed__:
try:
translation = gettext.GNUTranslations(open(filename, "rb"))
except IOError:
locale.setlocale(locale.LC_ALL, "")
except locale.Error:
translation = gettext.NullTranslations()
else:
lang = locale.getlocale()
translation.install(True)
#Fix for non-POSIX-compliant systems (Windows et al.).
if os.getenv('LANG') is None:
lang = locale.getdefaultlocale()
os.environ['LANG'] = lang[0]
filename = basedir.get_basedir() + "/translations/messages_%s.mo" % lang[0][0:2]
try:
translation = gettext.GNUTranslations(open(filename, "rb"))
except IOError:
translation = gettext.NullTranslations()
__installed__ = True
translation.install(True)