當前位置: 首頁>>代碼示例>>Python>>正文


Python babel.UnknownLocaleError方法代碼示例

本文整理匯總了Python中babel.UnknownLocaleError方法的典型用法代碼示例。如果您正苦於以下問題:Python babel.UnknownLocaleError方法的具體用法?Python babel.UnknownLocaleError怎麽用?Python babel.UnknownLocaleError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在babel的用法示例。


在下文中一共展示了babel.UnknownLocaleError方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_locale

# 需要導入模塊: import babel [as 別名]
# 或者: from babel import UnknownLocaleError [as 別名]
def get_locale(locale_code):
    locale = None

    try:
        locale = Locale.parse(locale_code)
    except (UnknownLocaleError, ValueError) as e:
        try:
            locale = Locale.parse(locale_code, sep='-')
        except (UnknownLocaleError, ValueError) as e:
            pass

    if locale_code in _cached_locale_:
        locale = _cached_locale_[locale_code]

    if locale:
        _cached_locale_[locale_code] = locale

    return locale 
開發者ID:metasmile,項目名稱:strsync,代碼行數:20,代碼來源:strlocale.py

示例2: setup_languages

# 需要導入模塊: import babel [as 別名]
# 或者: from babel import UnknownLocaleError [as 別名]
def setup_languages(settings):
    if not settings['language']:
        settings['language'] = [get_locale()[:2]]

    languages = []
    language_names = []
    for lang_code in settings['language']:
        try:
            language_names.append(Locale(lang_code).english_name)
            languages.append(lang_code)
        except UnknownLocaleError:
            raise click.ClickException('Unknown language code: %s' % lang_code)

    logger.info('Languages: %s', ', '.join(language_names))
    return settings 
開發者ID:coagulant,項目名稱:critics,代碼行數:17,代碼來源:commands.py

示例3: __get_env_language_for_babel

# 需要導入模塊: import babel [as 別名]
# 或者: from babel import UnknownLocaleError [as 別名]
def __get_env_language_for_babel(self):
        language_code = self.env.lang
        try:
            return babel.Locale.parse(language_code, sep='-')
        except babel.UnknownLocaleError as e:
            # fallback language
            return babel.Locale('en') 
開發者ID:google,項目名稱:personfinder,代碼行數:9,代碼來源:utils.py


注:本文中的babel.UnknownLocaleError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。