From 5ac6f853d0b345f8f3fc59d34b57d4adca0c44bd Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 11 Mar 2014 20:38:47 +0100 Subject: [PATCH] Changed get_locale_key to only use ICU if available. --- openlp/core/utils/__init__.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 1e358454f..510528bcb 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -426,15 +426,18 @@ def get_locale_key(string): The corresponding string. """ string = string.lower() + # ICU is the prefered way to handle locale sort key, we fallback to locale.strxfrm which will work in most cases. global ICU_COLLATOR - if ICU_COLLATOR is None: - import icu - from .languagemanager import LanguageManager - language = LanguageManager.get_language() - icu_locale = icu.Locale(language) - ICU_COLLATOR = icu.Collator.createInstance(icu_locale) - return ICU_COLLATOR.getSortKey(string) - + try: + if ICU_COLLATOR is None: + import icu + from .languagemanager import LanguageManager + language = LanguageManager.get_language() + icu_locale = icu.Locale(language) + ICU_COLLATOR = icu.Collator.createInstance(icu_locale) + return ICU_COLLATOR.getSortKey(string) + except: + return locale.strxfrm(string).encode() def get_natural_key(string): """