本文整理匯總了Python中icu.Locale方法的典型用法代碼示例。如果您正苦於以下問題:Python icu.Locale方法的具體用法?Python icu.Locale怎麽用?Python icu.Locale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類icu
的用法示例。
在下文中一共展示了icu.Locale方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _edit
# 需要導入模塊: import icu [as 別名]
# 或者: from icu import Locale [as 別名]
def _edit(bs: bistr, op: Callable, locale: Optional[str] = None) -> bistr:
builder = BistrBuilder(bs)
edits = icu.Edits()
ucur = icu.UnicodeString(builder.current)
if locale is None:
umod = icu.UnicodeString(op(ucur, edits))
else:
umod = icu.UnicodeString(op(icu.Locale(locale), ucur, edits))
for is_change, old_len, new_len, old_i, new_i, _ in edits.getFineIterator():
old_len = ucur.countChar32(old_i, old_len)
if is_change:
repl = str(umod[new_i:new_i+new_len])
builder.replace(old_len, repl)
else:
builder.skip(old_len)
return builder.build()
示例2: __init__
# 需要導入模塊: import icu [as 別名]
# 或者: from icu import Locale [as 別名]
def __init__(self, choice):
basic_name, code, confidence, bytesize = choice
self.locale = Locale(code)
self.confidence = float(confidence)
self.read_bytes = int(bytesize)
示例3: __init__
# 需要導入模塊: import icu [as 別名]
# 或者: from icu import Locale [as 別名]
def __init__(self, locale):
self.locale = Locale('locale')
self.breaker = None
示例4: sortkey
# 需要導入模塊: import icu [as 別名]
# 或者: from icu import Locale [as 別名]
def sortkey(strength, maxlength=None):
c = Collator.createInstance(Locale(''))
c.setStrength(strength)
c.setAttribute(UCollAttribute.ALTERNATE_HANDLING,
UCollAttributeValue.SHIFTED)
if maxlength is None:
return c.getSortKey
else:
return lambda x: c.getSortKey(x)[:maxlength]
示例5: sortkey_length
# 需要導入模塊: import icu [as 別名]
# 或者: from icu import Locale [as 別名]
def sortkey_length(strength, word):
c = Collator.createInstance(Locale(''))
c.setStrength(strength)
c.setAttribute(UCollAttribute.ALTERNATE_HANDLING,
UCollAttributeValue.SHIFTED)
coll_key = c.getSortKey(word)
return len(coll_key) - 1 #subtract 1 for ending \x00 byte
示例6: sort_for_script
# 需要導入模塊: import icu [as 別名]
# 或者: from icu import Locale [as 別名]
def sort_for_script(cp_list, script):
lang = lang_for_script(script)
if not lang:
print("cannot sort for script, no lang for %s" % script)
return cp_list
if _HAVE_ICU:
from icu import Locale, Collator
loc = Locale(lang + "_" + script)
col = Collator.createInstance(loc)
return sorted(cp_list, cmp=col.compare)
else:
import locale
return sorted(cp_list, cmp=locale.strcoll)
示例7: get_icu_locale
# 需要導入模塊: import icu [as 別名]
# 或者: from icu import Locale [as 別名]
def get_icu_locale():
try:
return icu.Locale(".".join(getlocale()))
except TypeError: # pragma: no cover
return icu.Locale()
示例8: get_locale_name
# 需要導入模塊: import icu [as 別名]
# 或者: from icu import Locale [as 別名]
def get_locale_name(locale_id: str) -> str:
"""Returns the name of the locale represented by `locale_id`, in its own language.
"""
locale = Locale(locale_id)
return locale.getDisplayLanguage(locale)
示例9: __init__
# 需要導入模塊: import icu [as 別名]
# 或者: from icu import Locale [as 別名]
def __init__(self, locale: str, constructor: Callable[[icu.Locale], icu.BreakIterator]):
# BreakIterator is not a thread-safe API, so store a cache of
# thread-local iterators
self._locale = icu.Locale(locale)
self._constructor = constructor
self._local = threading.local()
# Eagerly construct one on this thread as an optimization, and to check
# for errors
self._break_iterator()