diff --git a/gramps/gen/datehandler/_grampslocale.py b/gramps/gen/datehandler/_grampslocale.py index e4926c271..1190f03e9 100644 --- a/gramps/gen/datehandler/_grampslocale.py +++ b/gramps/gen/datehandler/_grampslocale.py @@ -42,13 +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: - if win(): - codeset = locale.getlocale()[1] - else: - codeset = "UTF-8" +codeset = glocale.encoding try: diff --git a/gramps/gen/utils/file.py b/gramps/gen/utils/file.py index b4a6cad79..386534499 100644 --- a/gramps/gen/utils/file.py +++ b/gramps/gen/utils/file.py @@ -278,10 +278,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 1b6f5624b..89876d7cd 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*