gitinspector now tries to get around any invalid locale.

Whenever a locale is found that is simply wrong; gitinspector will try to
get the default strings from gettext and try to execute.
This commit is contained in:
Adam Waldenberg 2013-06-26 03:51:43 +02:00
parent f030147206
commit cd1c1f0c65
1 changed files with 16 additions and 12 deletions

View File

@ -24,19 +24,23 @@ import locale
import os
def init():
locale.setlocale(locale.LC_ALL, '')
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
filename = "translations/messages_%s.mo" % lang[0][0:2]
try:
translation = gettext.GNUTranslations(open( filename, "rb" ) )
except IOError:
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 = "translations/messages_%s.mo" % lang[0][0:2]
try:
translation = gettext.GNUTranslations(open( filename, "rb" ) )
except IOError:
translation = gettext.NullTranslations()
translation.install(True)