本文整理汇总了Python中flask_babel.get_locale方法的典型用法代码示例。如果您正苦于以下问题:Python flask_babel.get_locale方法的具体用法?Python flask_babel.get_locale怎么用?Python flask_babel.get_locale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_babel
的用法示例。
在下文中一共展示了flask_babel.get_locale方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_translations
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def _get_translations():
"""Returns the correct gettext translations.
Copy from flask-babel with some modifications.
"""
ctx = _request_ctx_stack.top
if ctx is None:
return None
# babel should be in extensions for get_locale
if 'babel' not in ctx.app.extensions:
return None
translations = getattr(ctx, 'wtforms_translations', None)
if translations is None:
dirname = messages_path()
translations = support.Translations.load(
dirname, [get_locale()], domain='wtforms'
)
ctx.wtforms_translations = translations
return translations
示例2: formatdate_filter
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def formatdate_filter(val):
try:
conformed_timestamp = re.sub(r"[:]|([-](?!((\d{2}[:]\d{2})|(\d{4}))$))", '', val)
formatdate = datetime.datetime.strptime(conformed_timestamp[:15], "%Y%m%d %H%M%S")
return format_date(formatdate, format='medium', locale=get_locale())
except AttributeError as e:
log.error('Babel error: %s, Current user locale: %s, Current User: %s', e,
current_user.locale,
current_user.nickname
)
return formatdate
示例3: before_request
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def before_request() -> None:
"""Set user last seen time user."""
if current_user.is_authenticated:
current_user.last_seen = udatetime.utcnow().replace(tzinfo=None)
db.session.commit()
g.search_form = SearchForm()
g.locale = str(get_locale())
示例4: get_locale
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def get_locale():
"""Returns the locale for the current request."""
try:
return user_locale(request.user_id)
except AttributeError as e:
app.logger.warning(e)
return "en"
示例5: title
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def title(self):
current_locale = get_locale()
if current_locale is None:
current_locale = babel.Locale('en')
# Special case possesive form in English
if current_locale.language.lower() == 'en' and \
current_user.name[:-1] == u's':
return u"{}' Requests".format(current_user.name)
else:
# TRANS: The title of the page listing all requests an individual
# TRANS: user has made.
return gettext(u"%(name)s's Requests", name=current_user.name)
示例6: currencyfmt
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def currencyfmt(currency):
# We're only formatting ISK, so it has a bit of a special format
number = numbers.format_decimal(currency, format="#,##0.00;-#",
locale=get_locale())
return number
示例7: numberfmt
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def numberfmt(number):
return numbers.format_number(number, locale=get_locale())
示例8: percentfmt
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def percentfmt(percent):
return numbers.format_percent(percent, locale=get_locale())
示例9: __init_web_layer
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def __init_web_layer(self):
self.app.json_encoder = AppKernelJSONEncoder
self.app.register_error_handler(Exception, self.generic_error_handler)
for code in default_exceptions.keys():
# add a default error handler for everything is unhandled
self.app.register_error_handler(code, self.generic_error_handler)
def set_locale_on_request():
g.locale = str(get_locale())
self.app.before_request(set_locale_on_request)
示例10: common_bootstrap_payload
# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def common_bootstrap_payload() -> Dict[str, Any]:
"""Common data always sent to the client"""
messages = get_flashed_messages(with_categories=True)
locale = str(get_locale())
return {
"flash_messages": messages,
"conf": {k: conf.get(k) for k in FRONTEND_CONF_KEYS},
"locale": locale,
"language_pack": get_language_pack(locale),
"feature_flags": get_feature_flags(),
"menu_data": menu_data(),
}