本文整理汇总了Python中babel.core.Locale.default方法的典型用法代码示例。如果您正苦于以下问题:Python Locale.default方法的具体用法?Python Locale.default怎么用?Python Locale.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babel.core.Locale
的用法示例。
在下文中一共展示了Locale.default方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_metadata
# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import default [as 别名]
def get_metadata(app, docname):
'''
Extracts metadata from a document.
'''
env = app.builder.env
language = app.config.language
locale = Locale.parse(language) if language else Locale.default()
format_ui_date = partial(
format_date, format=UIStr.TIMESTAMP_FMT, locale=locale)
format_short_ui_short = partial(
format_date, format=UIStr.TIMESTAMP_FMT_SHORT, locale=locale)
env.blog_metadata[docname] = Metadata()
metadata = env.blog_metadata[docname]
# if it's a page
if docname.startswith("pages/"):
metadata.is_page = True
return
# posts are identified by ($YEAR)/($MONTH)/($DAY) paths
match = re.match(r"\d{4}/\d{2}/\d{2}/", docname)
# if not post return
if not match:
return
metadata.is_post = True
metadata.link = docname
metadata.date = datetime.datetime.strptime(match.group(), "%Y/%m/%d/")
# we format date here instead of inside template due to localization issues
# and Python2 vs Python3 incompatibility
metadata.formatted_date = format_ui_date(metadata.date)
metadata.formatted_date_short = format_short_ui_short(metadata.date)
示例2: get_currencies
# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import default [as 别名]
def get_currencies():
"""
Returns a list of currencies.
"""
return sorted(
Locale.default().currencies.items(),
key=operator.itemgetter(1)
)
示例3: defaultLocale
# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import default [as 别名]
def defaultLocale():
try:
lang, _ = locale.getdefaultlocale()
except Exception:
lang = None
if lang is not None:
return Locale.parse(lang)
else:
try:
return Locale.default()
except UnknownLocaleError:
return Locale('en', 'US')
示例4: get_console_locale
# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import default [as 别名]
def get_console_locale(env=None, lang=LANG):
"""Return negotiated locale for console by LANG environment and
[trac] default_language."""
if has_babel:
from babel.core import Locale, UnknownLocaleError, parse_locale
try:
lang = '_'.join(filter(None, parse_locale(lang)))
except:
lang = None
default = env.config.get('trac', 'default_language', '') \
if env else None
try:
return get_negotiated_locale([lang, default]) or Locale.default()
except UnknownLocaleError:
pass
return None
示例5: test_default
# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.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')
示例6: test_can_return_default_locale
# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.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')
示例7: test_can_return_default_locale
# 需要导入模块: from babel.core import Locale [as 别名]
# 或者: from babel.core.Locale import default [as 别名]
def test_can_return_default_locale(self):
os.environ['LC_MESSAGES'] = 'fr_FR.UTF-8'
self.assertEqual(Locale('fr', 'FR'), Locale.default('LC_MESSAGES'))