7588: Can not start [in Chinese on OSX]

Force UTF-8 locale on Mac
This commit is contained in:
John Ralls 2014-04-07 11:51:02 -07:00
parent 930a2f9819
commit dc292037e4
2 changed files with 9 additions and 1 deletions

View File

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

View File

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