本文整理汇总了Python中babel.Locale.default方法的典型用法代码示例。如果您正苦于以下问题:Python Locale.default方法的具体用法?Python Locale.default怎么用?Python Locale.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babel.Locale
的用法示例。
在下文中一共展示了Locale.default方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: defaultLocale
# 需要导入模块: from babel import Locale [as 别名]
# 或者: from babel.Locale import default [as 别名]
def defaultLocale():
try:
lang, _ = locale.getdefaultlocale()
except Exception:
lang = None
if lang is not None:
return Locale.parse(lang)
else:
return Locale.default()
示例2: __babel_default
# 需要导入模块: from babel import Locale [as 别名]
# 或者: from babel.Locale import default [as 别名]
def __babel_default(self):
logger.debug('Babel is using default locale')
# Locale.default will raise an UnknownLocaleError if
# the environment variables are not set or set wrong
# This generally happens on Windows only
# See: http://babel.edgewall.org/ticket/98
try:
locale = Locale.default()
except ValueError:
logger.debug('Babel did not understand default locale')
locale = Locale(self.fallback_language)
except UnknownLocaleError:
logger.debug('Babel does not support default locale')
locale = Locale(self.fallback_language)
else:
if locale is None:
logger.debug('Babel returned a default locale of None')
locale = Locale(self.fallback_language)
cbpos.locale = locale
示例3: test_default
# 需要导入模块: from babel import Locale [as 别名]
# 或者: from babel.Locale import default [as 别名]
def test_default(self, os_environ):
for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LC_MESSAGES']:
os_environ[name] = ''
os_environ['LANG'] = 'fr_FR.UTF-8'
default = Locale.default('LC_MESSAGES')
assert (default.language, default.territory) == ('fr', 'FR')
示例4: test_can_return_default_locale
# 需要导入模块: from babel import Locale [as 别名]
# 或者: from babel.Locale import default [as 别名]
def test_can_return_default_locale(os_environ):
os_environ['LC_MESSAGES'] = 'fr_FR.UTF-8'
assert Locale('fr', 'FR') == Locale.default('LC_MESSAGES')
示例5: test_default
# 需要导入模块: from babel import Locale [as 别名]
# 或者: from babel.Locale import default [as 别名]
def test_default(self, os_environ):
for name in ["LANGUAGE", "LC_ALL", "LC_CTYPE", "LC_MESSAGES"]:
os_environ[name] = ""
os_environ["LANG"] = "fr_FR.UTF-8"
default = Locale.default("LC_MESSAGES")
assert (default.language, default.territory) == ("fr", "FR")