当前位置: 首页>>代码示例>>Python>>正文


Python icu.Locale方法代码示例

本文整理汇总了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() 
开发者ID:microsoft,项目名称:bistring,代码行数:21,代码来源:_icu.py

示例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) 
开发者ID:aboSamoor,项目名称:polyglot,代码行数:7,代码来源:base.py

示例3: __init__

# 需要导入模块: import icu [as 别名]
# 或者: from icu import Locale [as 别名]
def __init__(self, locale):
    self.locale = Locale('locale')
    self.breaker = None 
开发者ID:aboSamoor,项目名称:polyglot,代码行数:5,代码来源:base.py

示例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] 
开发者ID:itkach,项目名称:slob,代码行数:11,代码来源:slob.py

示例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 
开发者ID:itkach,项目名称:slob,代码行数:9,代码来源:slob.py

示例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) 
开发者ID:googlefonts,项目名称:nototools,代码行数:17,代码来源:generate_sample_from_exemplar.py

示例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() 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:7,代码来源:locale.py

示例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) 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:7,代码来源:__init__.py

示例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() 
开发者ID:microsoft,项目名称:bistring,代码行数:12,代码来源:_token.py


注:本文中的icu.Locale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。