From 663493fd4152356325f79db40337f8e613b7ba44 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Thu, 4 Jul 2013 10:55:54 +0200 Subject: [PATCH] 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. --- gitinspector/localization.py | 38 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/gitinspector/localization.py b/gitinspector/localization.py index ec2e52a..c236ca8 100644 --- a/gitinspector/localization.py +++ b/gitinspector/localization.py @@ -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)