From db9daced3c42ed44557e557beea07c7b446aef64 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 24 Feb 2013 00:55:13 +0000 Subject: [PATCH] [r21272]GrampsLocale: Extract function __init_from_environment svn: r21413 --- gramps/gen/utils/grampslocale.py | 49 +++++++++++++++++--------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index da9eb7d78..6e7a756eb 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -88,6 +88,31 @@ class GrampsLocale(object): return super(GrampsLocale, cls).__new__(cls) + def __init_from_environment(self, lang=None, language=None): + if not lang: + lang = ' ' + try: + lang = os.environ["LANG"] + except KeyError: + lang = locale.getlocale()[0] + if not lang: + try: + lang = locale.getdefaultlocale()[0] + '.UTF-8' + except TypeError: + LOG.warning('Unable to determine your Locale, using English') + lang = 'C.UTF-8' + self.lang = lang + + if not language or len(language) == 0: + if "LANGUAGE" in os.environ: + language = [l for l in os.environ["LANGUAGE"].split(":") + if l in self.get_available_translations()] + self.language = language + elif not lang == "C.UTF-8": + self.language = [lang[0:2]] + else: + self.language = ["en"] + def __init_first_instance(self, localedir=None, lang=None, domain=None, language=None): @@ -128,29 +153,7 @@ class GrampsLocale(object): from . import maclocale (self.lang, self.language) = maclocale.mac_setup_localization(self, lang, language) else: - if not lang: - lang = ' ' - try: - lang = os.environ["LANG"] - except KeyError: - lang = locale.getlocale()[0] - if not lang: - try: - lang = locale.getdefaultlocale()[0] + '.UTF-8' - except TypeError: - LOG.warning('Unable to determine your Locale, using English') - lang = 'C.UTF-8' - self.lang = lang - - if not language or len(language) == 0: - if "LANGUAGE" in os.environ: - language = [l for l in os.environ["LANGUAGE"].split(":") - if l in get_available_translations()] - self.language = language - elif not lang == "C.UTF-8": - self.language = [lang[0:2]] - else: - self.language = ["en"] + self.__init_from_environment(lang, language) #GtkBuilder depends on reading Glade files as UTF-8 and crashes if it #doesn't, so set $LANG to have a UTF-8 locale. NB: This does *not*