本文整理匯總了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
示例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
示例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')