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,28 +247,30 @@ class GrampsLocale(object):
self.calendar = self.lang self.calendar = self.lang
def _init_from_environment(self): 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: try:
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
except locale.Error as err: if not _check_locale(locale.getlocale()):
LOG.warning("Locale error %s, localization will be US English.", if not _check_locale(locale.getlocale(locale.LC_MESSAGES)):
err); if not _check_locale(locale.getdefaultlocale()):
self.lang = 'C' self.lang = 'C'
self.encoding = 'ascii' self.encoding = 'ascii'
self.language = ['en'] self.language = ['en']
if not (hasattr(self, 'lang') and self.lang): except locale.Error as err:
(lang, encoding) = locale.getlocale() LOG.warning("Locale error %s, localization will be US English.",
if self.check_available_translations(lang): err);
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.lang = 'C'
self.encoding = 'ascii' self.encoding = 'ascii'
self.language = ['en'] self.language = ['en']