From 649bdf7bb7395638088e4276d7c5289ce290c248 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 3 Mar 2013 21:55:02 +0000 Subject: [PATCH] GrampsLocale: Restore setlocale, add GrampsLocale.encoding encoding to replace translation().info()['encoding'] which isn't the encoding we're looking for. svn: r21539 --- gramps/gen/datehandler/_grampslocale.py | 6 +----- gramps/gen/utils/file.py | 5 +---- gramps/gen/utils/grampslocale.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gramps/gen/datehandler/_grampslocale.py b/gramps/gen/datehandler/_grampslocale.py index 211bb64e2..c398f518f 100644 --- a/gramps/gen/datehandler/_grampslocale.py +++ b/gramps/gen/datehandler/_grampslocale.py @@ -42,11 +42,7 @@ if sys.version_info[0] < 3: else: #locale returns unicode in python 3 to_uni = lambda x, y: x -try: - codeset = glocale.get_translation().info()["charset"] -except KeyError: - codeset = "UTF-8" - +codeset = glocale.encoding try: month_to_int = { diff --git a/gramps/gen/utils/file.py b/gramps/gen/utils/file.py index e78a1d9e9..1103c6828 100644 --- a/gramps/gen/utils/file.py +++ b/gramps/gen/utils/file.py @@ -284,10 +284,7 @@ def fix_encoding(value, errors='strict'): try: return cuni(value) except: - try: - info = glocale.get_translation().info()["charset"] - except: - codeset = "UTF-8" + codeset = glocale.encoding if sys.version_info[0] < 3: return unicode(value, codeset, errors) else: diff --git a/gramps/gen/utils/grampslocale.py b/gramps/gen/utils/grampslocale.py index 6d9011afb..ecd4f5c75 100644 --- a/gramps/gen/utils/grampslocale.py +++ b/gramps/gen/utils/grampslocale.py @@ -102,6 +102,9 @@ class GrampsLocale(object): return super(GrampsLocale, cls).__new__(cls) def __init_from_environment(self, lang=None, language=None): +#First, globally set the locale to what's in the environment: + locale.setlocale(locale.LC_ALL, '') + if not lang: lang = ' ' try: @@ -184,6 +187,20 @@ class GrampsLocale(object): maclocale.mac_setup_localization(self, lang, language) else: self.__init_from_environment(lang, language) +#A variety of useful functions use the current locale for +#formatting. Pending global replacement of those functions with ICU +#equivalents, we need to use setlocale to our chosen default. This +#unfortunately doesn't work in Windows because it uses different +#values until VS2012 (which only works on Win8), so while we can set +#translations and date formats with lang, we can't affect currency or +#numeric format. Those are fixed by the user's system settings. + + if not win(): + locale.setlocale(locale.LC_COLLATE, self.collation) + locale.setlocale(locale.LC_TIME, self.calendar) + locale.setlocale(locale.LC_MONETARY, self.currency) +#Next, we need to know what is the encoding from the native environment: + self.encoding = locale.getlocale()[1] #GtkBuilder depends on reading Glade files as UTF-8 and crashes if it #doesn't, so set $LANG to have a UTF-8 locale. NB: This does *not*