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