GrampsLocale: Clean up _init_from_environment even more

And do it right this time!

svn: r21898
This commit is contained in:
John Ralls 2013-04-05 23:40:49 +00:00
parent 445f10396a
commit e21ba6c432

View File

@ -247,8 +247,27 @@ class GrampsLocale(object):
self.calendar = self.lang
def _init_from_environment(self):
def _check_locale(locale):
if not locale[0]:
return False
lang = self.check_available_translations(locale[0])
if not lang:
return False
self.lang = locale[0]
self.encoding = locale[1]
self.language = [lang]
return True
try:
locale.setlocale(locale.LC_ALL, '')
if not _check_locale(locale.getlocale()):
if not _check_locale(locale.getlocale(locale.LC_MESSAGES)):
if not _check_locale(locale.getdefaultlocale()):
self.lang = 'C'
self.encoding = 'ascii'
self.language = ['en']
except locale.Error as err:
LOG.warning("Locale error %s, localization will be US English.",
err);
@ -256,23 +275,6 @@ class GrampsLocale(object):
self.encoding = 'ascii'
self.language = ['en']
if not (hasattr(self, 'lang') and self.lang):
(lang, encoding) = locale.getlocale()
if self.check_available_translations(lang):
self.lang = lang
self.encoding = encoding
else:
loc = (locale.getlocale(locale.LC_MESSAGES) or
locale.getdefaultlocale())
if loc and self.check_available_translations(loc[0]):
self.lang = loc[0]
self.encoding = loc[1]
self.language = ['en']
else:
self.lang = 'C'
self.encoding = 'ascii'
self.language = ['en']
# $LANGUAGE overrides $LANG, $LC_MESSAGES
if not self.lang.startswith('C.') and "LANGUAGE" in os.environ:
language = [x for x in [self.check_available_translations(l)