Use ICU for locale sort key

This commit is contained in:
Tomas Groth 2014-03-10 20:53:11 +01:00
parent 0091079b76
commit b831ebd48e

View File

@ -426,17 +426,14 @@ def get_locale_key(string):
The corresponding string. The corresponding string.
""" """
string = string.lower() string = string.lower()
# For Python 3 on platforms other than Windows ICU is not necessary. In those cases locale.strxfrm(str) can be used. global ICU_COLLATOR
if os.name == 'nt': if ICU_COLLATOR is None:
global ICU_COLLATOR import icu
if ICU_COLLATOR is None: from .languagemanager import LanguageManager
import icu language = LanguageManager.get_language()
from .languagemanager import LanguageManager icu_locale = icu.Locale(language)
language = LanguageManager.get_language() ICU_COLLATOR = icu.Collator.createInstance(icu_locale)
icu_locale = icu.Locale(language) return ICU_COLLATOR.getSortKey(string)
ICU_COLLATOR = icu.Collator.createInstance(icu_locale)
return ICU_COLLATOR.getSortKey(string)
return locale.strxfrm(string).encode()
def get_natural_key(string): def get_natural_key(string):