GrampsLocale: Prevent some AttributeErrors and 'referenced before assignment' errors.

svn: r21693
This commit is contained in:
John Ralls 2013-03-19 18:21:41 +00:00
parent 9e8f6aaab6
commit ec787da3fa
2 changed files with 13 additions and 4 deletions

View File

@ -191,6 +191,8 @@ class GrampsLocale(object):
self.language.append('en') self.language.append('en')
if not self.have_localedir and not self.lang.startswith('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) 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 #A variety of useful functions use the current locale for
#formatting. Pending global replacement of those functions with ICU #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 # GtkBuilder uses GLib's g_dgettext wrapper, which oddly is bound
# with locale instead of gettext. Win32 doesn't support bindtextdomain. # with locale instead of gettext. Win32 doesn't support bindtextdomain.
if not win(): if self.have_localedir:
locale.bindtextdomain(self.localedomain, self.localedir) if not win():
else: locale.bindtextdomain(self.localedomain, self.localedir)
self._win_bindtextdomain(self.localedomain, self.localedir) else:
self._win_bindtextdomain(self.localedomain, self.localedir)
def __init__(self, localedir=None, lang=None, domain=None, languages=None): def __init__(self, localedir=None, lang=None, domain=None, languages=None):
@ -257,6 +260,11 @@ class GrampsLocale(object):
elif hasattr(_first, 'localedir'): elif hasattr(_first, 'localedir'):
self.localedir = _first.localedir self.localedir = _first.localedir
else: 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 self.have_localedir = False
if lang: if lang:

View File

@ -218,6 +218,7 @@ def mac_setup_localization(glocale):
glocale.lang = lang glocale.lang = lang
if not glocale.language: if not glocale.language:
language = ['en_US']
if "LANGUAGE" in os.environ: if "LANGUAGE" in os.environ:
language = [x for x in [glocale.check_available_translations(l) language = [x for x in [glocale.check_available_translations(l)
for l in os.environ["LANGUAGE"].split(":")] for l in os.environ["LANGUAGE"].split(":")]