GrampsLocale: Use the codeset from the singleton translation

Instead of locale.getlocale() or locale.nl_langinfo

svn: r21150
This commit is contained in:
John Ralls 2013-01-17 19:48:14 +00:00
parent fc609ef3d5
commit 9e8b2af5c1
2 changed files with 8 additions and 10 deletions

View File

@ -25,6 +25,8 @@ import locale
import sys import sys
from ..constfunc import mac, win, conv_to_unicode 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 Some OS environments do not support the locale.nl_langinfo() method
of determing month names and other date related information. of determing month names and other date related information.
@ -41,7 +43,11 @@ else:
#locale returns unicode in python 3 #locale returns unicode in python 3
to_uni = lambda x, y: x to_uni = lambda x, y: x
try: try:
codeset = locale.nl_langinfo(locale.CODESET) codeset = glocale.get_translation().info()["charset"]
except KeyError:
codeset = "UTF-8"
try:
month_to_int = { month_to_int = {
to_uni(locale.nl_langinfo(locale.MON_1), codeset).lower() : 1, to_uni(locale.nl_langinfo(locale.MON_1), codeset).lower() : 1,
@ -137,11 +143,6 @@ try:
except: except:
import time import time
codeset = None
if win() or mac():
codeset = locale.getlocale()[1]
if codeset is None:
codeset = locale.getpreferredencoding()
month_to_int = { month_to_int = {
to_uni(time.strftime('%B',(0,1,1,1,1,1,1,1,1)), codeset).lower() : 1, to_uni(time.strftime('%B',(0,1,1,1,1,1,1,1,1)), codeset).lower() : 1,

View File

@ -279,10 +279,7 @@ def fix_encoding(value, errors='strict'):
return cuni(value) return cuni(value)
except: except:
try: try:
if mac(): info = glocale.get_translation().info()["charset"]
codeset = locale.getlocale()[1]
else:
codeset = locale.getpreferredencoding()
except: except:
codeset = "UTF-8" codeset = "UTF-8"
if sys.version_info[0] < 3: if sys.version_info[0] < 3: