From 5ecdde56f4f0bfe015f3158b81007c134b83ab12 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 9 Mar 2013 22:37:54 +0000 Subject: [PATCH] [r21595]GrampsLocale: Improve handling the language list Replace "en" with "C" when setting $LANGUAGE ("en" confuses GtkBuilder), and explicitly iterate over languages when finding the translator, because left to itself gettext will ignore English. svn: r21598 --- gramps/gen/utils/grampslocale.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index cb810d96c..d65f4aa02 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -225,7 +225,7 @@ class GrampsLocale(object): if len(check_lang) < 2 or check_lang[1] not in ["utf-8", "UTF-8"]: self.lang = '.'.join((check_lang[0], 'UTF-8')) os.environ["LANG"] = self.lang - os.environ["LANGUAGE"] = ':'.join(self.language) + os.environ["LANGUAGE"] = ':'.join(['C' if l.startswith('en') else l for l in self.language]) # GtkBuilder uses GLib's g_dgettext wrapper, which oddly is bound # with locale instead of gettext. Win32 doesn't support bindtextdomain. @@ -309,19 +309,18 @@ class GrampsLocale(object): if not localedir: localedir = self.localedir - lang = gettext.find(domain, localedir, languages) - if lang: - translator = gettext.translation(domain, localedir, - languages, - class_ = GrampsTranslations) - translator._language = os.path.basename(os.path.dirname(os.path.dirname(lang))).split('.')[0] - return translator + for lang in languages: + if gettext.find(domain, localedir, [lang]): + translator = gettext.translation(domain, localedir, + [lang], + class_ = GrampsTranslations) + translator._language = lang + return translator - else: - if not languages == ["en"]: - LOG.debug("Unable to find translations for %s and %s in %s", - domain, languages, localedir) - return GrampsNullTranslations() + elif lang.startswith("en") or lang.startswith("C"): + translator = GrampsNullTranslations() + translator._language = "en" + return translator def _set_dictionaries(self): """