[r21693]GrampsLocale: Prevent some AttributeErrors

and 'referenced before assignment' errors.

svn: r21697
This commit is contained in:
John Ralls 2013-03-19 18:33:31 +00:00
parent bdcc43b911
commit 38cc711bde
2 changed files with 13 additions and 4 deletions

View File

@ -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:

View File

@ -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(":")]