From 38cc711bde6690ebff59de25de5f5f5ac8d80909 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 19 Mar 2013 18:33:31 +0000 Subject: [PATCH] [r21693]GrampsLocale: Prevent some AttributeErrors and 'referenced before assignment' errors. svn: r21697 --- gramps/gen/utils/grampslocale.py | 16 ++++++++++++---- gramps/gen/utils/maclocale.py | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index fe92f8730..dd6eff757 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -191,6 +191,8 @@ class GrampsLocale(object): self.language.append('en') if not self.have_localedir and not self.lang.startswith('en'): LOG.warning("No translations for %s were found, setting localization to U.S. English", self.localedomain) + self.lang = 'en_US.UTF-8' + self.language = ['en'] #A variety of useful functions use the current locale for #formatting. Pending global replacement of those functions with ICU @@ -226,10 +228,11 @@ class GrampsLocale(object): # GtkBuilder uses GLib's g_dgettext wrapper, which oddly is bound # with locale instead of gettext. Win32 doesn't support bindtextdomain. - if not win(): - locale.bindtextdomain(self.localedomain, self.localedir) - else: - self._win_bindtextdomain(self.localedomain, self.localedir) + if self.have_localedir: + if not win(): + locale.bindtextdomain(self.localedomain, self.localedir) + else: + self._win_bindtextdomain(self.localedomain, self.localedir) def __init__(self, localedir=None, lang=None, domain=None, languages=None): @@ -257,6 +260,11 @@ class GrampsLocale(object): elif hasattr(_first, 'localedir'): self.localedir = _first.localedir else: + self.localedir = None + if localedir: + LOG.warning("Localedir %s doesn't exist, unable to set localization", localedir); + else: + LOG.warning("No Localedir provided, unable to set localization") self.have_localedir = False if lang: diff --git a/gramps/gen/utils/maclocale.py b/gramps/gen/utils/maclocale.py index b69c49d5a..8d1332b84 100644 --- a/gramps/gen/utils/maclocale.py +++ b/gramps/gen/utils/maclocale.py @@ -218,6 +218,7 @@ def mac_setup_localization(glocale): glocale.lang = lang if not glocale.language: + language = ['en_US'] if "LANGUAGE" in os.environ: language = [x for x in [glocale.check_available_translations(l) for l in os.environ["LANGUAGE"].split(":")]