From dc292037e4ba565feb3469b8d243c389e278edda Mon Sep 17 00:00:00 2001 From: John Ralls Date: Mon, 7 Apr 2014 11:51:02 -0700 Subject: [PATCH] 7588: Can not start [in Chinese on OSX] Force UTF-8 locale on Mac --- gramps/gen/utils/grampslocale.py | 2 +- gramps/gen/utils/maclocale.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index 7a0af3a0a..558af0536 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -45,7 +45,7 @@ _hdlr = None # GrampsLocale initialization comes before command-line argument # passing, so one must set the log level directly. The default is # logging.WARN. Uncomment the following to change it to logging.DEBUG: -#LOG.setLevel(logging.DEBUG) +# LOG.setLevel(logging.DEBUG) try: from icu import Locale, Collator HAVE_ICU = True diff --git a/gramps/gen/utils/maclocale.py b/gramps/gen/utils/maclocale.py index 97eea1ea4..6f2f54db4 100644 --- a/gramps/gen/utils/maclocale.py +++ b/gramps/gen/utils/maclocale.py @@ -231,6 +231,7 @@ def mac_setup_localization(glocale): LOG.debug("Environment locale %s not supported", _locale) if not glocale.lang: + LOG.debug("Setting from the environment didn't work out, checking defaults") (glocale.lang, glocale.currency, glocale.calendar) = _mac_get_locale() glocale.coll_qualifier = None @@ -241,6 +242,13 @@ def mac_setup_localization(glocale): glocale.lang = glocale.check_available_translations(coll_parts[0]) glocale.lang = locale.normalize(glocale.lang) + if not glocale.lang.split('.')[1].lower() in ['utf8', 'utf-8']: + LOG.debug('Forcing locale encoding to UTF-8') + glocale.lang = '.'.join([glocale.lang.split('.')[0], 'UTF-8']) + try: + locale.setlocale(locale.LC_ALL, glocale.lang) + except locale.Error: + LOG.debug('Attempt failed, locale %s unsupported', glocale.lang) glocale.encoding = glocale.lang.split('.')[1] if not glocale.language: lang = locale.getlocale(locale.LC_MESSAGES)[0]