From 897e85aa511ac88c40ac370d05030eb356adb32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Rapinat?= Date: Sat, 3 Sep 2011 15:44:06 +0000 Subject: [PATCH] 4973: Gramps doesn't handle locale setting failure very well; testing (Tim's patch) svn: r18109 --- src/gramps.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/gramps.py b/src/gramps.py index 420b77557..9289ba23b 100644 --- a/src/gramps.py +++ b/src/gramps.py @@ -61,12 +61,23 @@ import constfunc #TransUtils.setup_gettext() gettext.bindtextdomain(TransUtils.LOCALEDOMAIN, TransUtils.LOCALEDIR) try: - locale.setlocale(locale.LC_ALL,'C') locale.setlocale(locale.LC_ALL,'') -except locale.Error: - pass -except ValueError: - pass +except: + # FIXME: This should use LOG.warn, but logging has not been initialised yet + print >> sys.stderr, _("WARNING: Setting locale failed. Please fix the " + "LC_* and/or the LANG environment variables to prevent this error") + try: + # It is probably not necessary to set the locale to 'C' + # because the locale will just stay at whatever it was, + # which at startup is "C". + # however this is done here just to make sure that the locale + # functions are working + locale.setlocale(locale.LC_ALL,'C') + except: + print >> sys.stderr, _("ERROR: Setting the 'C' locale didn't work either") + # FIXME: This should propagate the exception, + # if that doesn't break Gramps under Windows + # raise gettext.textdomain(TransUtils.LOCALEDOMAIN) gettext.install(TransUtils.LOCALEDOMAIN, localedir=None, unicode=1) #None is sys default locale @@ -80,9 +91,6 @@ if not constfunc.win(): else: TransUtils.setup_windows_gettext() -LOG.debug('Using locale:', locale.getlocale()) - - #------------------------------------------------------------------------- # # Minimum version check @@ -339,6 +347,17 @@ def run(): from cli.argparser import ArgParser argv_copy = sys.argv[:] argpars = ArgParser(argv_copy) + + # Calls to LOG must be after setup_logging() and ArgParser() + LOG = logging.getLogger(".locale") + LOG.debug('Using locale: LC_CTYPE: %s %s'% locale.getlocale(locale.LC_CTYPE)) + LOG.debug('Using locale: LC_COLLATE: %s %s'% locale.getlocale(locale.LC_COLLATE)) + LOG.debug('Using locale: LC_TIME %s %s'% locale.getlocale(locale.LC_TIME)) + LOG.debug('Using locale: LC_MONETARY %s %s'% locale.getlocale(locale.LC_MONETARY)) + LOG.debug('Using locale: LC_MESSAGES %s %s'% locale.getlocale(locale.LC_MESSAGES)) + LOG.debug('Using locale: LC_NUMERIC %s %s'% locale.getlocale(locale.LC_NUMERIC)) + LOG.debug('Using LANG: %s'% os.environ.get('LANG')) + LOG.debug('Using LANGUAGE: %s'% os.environ.get('LANGUAGE')) if argpars.need_gui(): #A GUI is needed, set it up