mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-11-16 00:28:25 +01:00
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:
parent
7bc297e99f
commit
663493fd41
1 changed files with 22 additions and 16 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue