- ICU or UCA support is available for the current locale.
- You are sorting strings from alphabets outside the primary locale.
- You need to support collating multiple locales at once.
+ - You need the same results across multiple platforms.
+
"""
import locale
"""C library locale-based collation."""
def __init__(self, locale_code, encoding=None):
+ locale_code, encoding = collate._locale.getpair(locale_code, encoding)
try:
- locale.setlocale(locale.LC_COLLATE, locale_code)
+ setlocale = locale_code + "." + encoding
+ locale.setlocale(locale.LC_COLLATE, setlocale)
except locale.Error:
- raise collate.errors.InvalidLocaleError(locale_code)
+ raise collate.errors.InvalidLocaleError(setlocale)
self.locale = locale.getlocale(locale.LC_COLLATE)[0]
self.encoding = collate._locale.encoding(encoding)
If strs rather than unicodes are passed in, they are first
decoded according to the 'encoding' attribute of the Collator.
"""
-
if isinstance(a, str):
a = a.decode(self.encoding, "replace")
if isinstance(b, str):