[r21882]GrampsLocale: Improve windows handling of no locale
svn: r21885
This commit is contained in:
parent
5fc65f68ea
commit
9979fd8792
@ -103,7 +103,7 @@ def _check_mswin_locale(locale):
|
|||||||
msloc = mslocales[locale[:2]]
|
msloc = mslocales[locale[:2]]
|
||||||
locale = locale[:2]
|
locale = locale[:2]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None
|
return (None, None)
|
||||||
return (locale, msloc)
|
return (locale, msloc)
|
||||||
|
|
||||||
def _check_mswin_locale_reverse(locale):
|
def _check_mswin_locale_reverse(locale):
|
||||||
@ -111,7 +111,7 @@ def _check_mswin_locale_reverse(locale):
|
|||||||
if msloc and locale == msloc[0]:
|
if msloc and locale == msloc[0]:
|
||||||
return (loc, msloc[1])
|
return (loc, msloc[1])
|
||||||
|
|
||||||
return None
|
return (None, None)
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -224,14 +224,20 @@ class GrampsLocale(object):
|
|||||||
self.collation = self.lang
|
self.collation = self.lang
|
||||||
else:
|
else:
|
||||||
(coll, loc) = _check_mswin_locale(coll)
|
(coll, loc) = _check_mswin_locale(coll)
|
||||||
if loc:
|
if not loc:
|
||||||
locale.setlocale(locale.LC_COLLATE, '.'.join(loc))
|
(coll, loc) = _check_mswin_locale(self.lang)
|
||||||
self.collation = coll
|
self.collation = '.'.join(loc)
|
||||||
else: #can't set the collation locale if MS doesn't support it
|
locale.setlocale(locale.LC_COLLATE, self.collation )
|
||||||
self.collation = self.lang
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
if HAVE_ICU:
|
||||||
self.collation = self.lang
|
self.collation = self.lang
|
||||||
|
else:
|
||||||
|
(coll, loc) = _check_mswin_locale(self.lang)
|
||||||
|
if loc:
|
||||||
|
self.collation = '.'.join(loc)
|
||||||
|
else:
|
||||||
|
self.collation = 'C'
|
||||||
|
locale.setlocale(locale.LC_COLLATE, self.collation )
|
||||||
|
|
||||||
# We can't import datahandler stuff or we'll get a circular
|
# We can't import datahandler stuff or we'll get a circular
|
||||||
# dependency, so we rely on the available translations list
|
# dependency, so we rely on the available translations list
|
||||||
@ -763,14 +769,6 @@ class GrampsLocale(object):
|
|||||||
#ICU can digest strings and unicode
|
#ICU can digest strings and unicode
|
||||||
return self.collator.getCollationKey(string).getByteArray()
|
return self.collator.getCollationKey(string).getByteArray()
|
||||||
else:
|
else:
|
||||||
try:
|
|
||||||
base_locale = locale.getlocale(locale.LC_COLLATE)
|
|
||||||
locale.setlocale(locale.LC_COLLATE, self.collation)
|
|
||||||
except Exception as err:
|
|
||||||
LOG.warn("Failed to set temporary locale with %s: %s",
|
|
||||||
self.lang, err)
|
|
||||||
return string
|
|
||||||
#locale in Python2 can't.
|
|
||||||
try:
|
try:
|
||||||
if sys.version_info[0] < 3 and isinstance(string, unicode):
|
if sys.version_info[0] < 3 and isinstance(string, unicode):
|
||||||
key = locale.strxfrm(string.encode("utf-8", "replace"))
|
key = locale.strxfrm(string.encode("utf-8", "replace"))
|
||||||
@ -781,11 +779,6 @@ class GrampsLocale(object):
|
|||||||
LOG.warn("Failed to obtain key for %s because %s",
|
LOG.warn("Failed to obtain key for %s because %s",
|
||||||
self.collation, str(err))
|
self.collation, str(err))
|
||||||
return string
|
return string
|
||||||
try:
|
|
||||||
locale.setlocale(locale.LC_COLLATE, base_locale)
|
|
||||||
except Exception as err:
|
|
||||||
LOG.warn("Failed to restore locale %s", err)
|
|
||||||
return key
|
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def strcoll(self, string1, string2):
|
def strcoll(self, string1, string2):
|
||||||
|
Loading…
Reference in New Issue
Block a user