From df46941e73ca96c13d97034e57c1bd2e7278171e Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 17 Jan 2013 19:48:14 +0000 Subject: [PATCH] GrampsLocale: Use the codeset from the singleton translation Instead of locale.getlocale() or locale.nl_langinfo svn: r21150 --- gramps/gen/datehandler/_grampslocale.py | 13 +++++++------ gramps/gen/utils/file.py | 5 +---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/gramps/gen/datehandler/_grampslocale.py b/gramps/gen/datehandler/_grampslocale.py index 0fd81916f..0a7a8acf1 100644 --- a/gramps/gen/datehandler/_grampslocale.py +++ b/gramps/gen/datehandler/_grampslocale.py @@ -25,6 +25,8 @@ import locale import sys from ..constfunc import mac, win, conv_to_unicode +from gramps.gen.const import GRAMPS_LOCALE as glocale + """ Some OS environments do not support the locale.nl_langinfo() method of determing month names and other date related information. @@ -41,7 +43,11 @@ else: #locale returns unicode in python 3 to_uni = lambda x, y: x try: - codeset = locale.nl_langinfo(locale.CODESET) + codeset = glocale.get_translation().info()["charset"] +except KeyError: + codeset = "UTF-8" + +try: month_to_int = { to_uni(locale.nl_langinfo(locale.MON_1), codeset).lower() : 1, @@ -137,11 +143,6 @@ try: except: import time - codeset = None - if win() or mac(): - codeset = locale.getlocale()[1] - if codeset is None: - codeset = locale.getpreferredencoding() month_to_int = { to_uni(time.strftime('%B',(0,1,1,1,1,1,1,1,1)), codeset).lower() : 1, diff --git a/gramps/gen/utils/file.py b/gramps/gen/utils/file.py index 07039ea61..82fbbc825 100644 --- a/gramps/gen/utils/file.py +++ b/gramps/gen/utils/file.py @@ -279,10 +279,7 @@ def fix_encoding(value, errors='strict'): return cuni(value) except: try: - if mac(): - codeset = locale.getlocale()[1] - else: - codeset = locale.getpreferredencoding() + info = glocale.get_translation().info()["charset"] except: codeset = "UTF-8" if sys.version_info[0] < 3: