本文整理汇总了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()