當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。