当前位置: 首页>>代码示例>>Python>>正文


Python flask_babel.get_locale方法代码示例

本文整理汇总了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 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:i18n.py

示例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 
开发者ID:janeczku,项目名称:calibre-web,代码行数:13,代码来源:jinjia.py

示例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()) 
开发者ID:AUCR,项目名称:AUCR,代码行数:9,代码来源:routes.py

示例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" 
开发者ID:M-Mueller,项目名称:mattermost-poll,代码行数:9,代码来源:app.py

示例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) 
开发者ID:paxswill,项目名称:evesrp,代码行数:14,代码来源:requests.py

示例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 
开发者ID:paxswill,项目名称:evesrp,代码行数:7,代码来源:locale.py

示例7: numberfmt

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def numberfmt(number):
    return numbers.format_number(number, locale=get_locale()) 
开发者ID:paxswill,项目名称:evesrp,代码行数:4,代码来源:locale.py

示例8: percentfmt

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import get_locale [as 别名]
def percentfmt(percent):
    return numbers.format_percent(percent, locale=get_locale()) 
开发者ID:paxswill,项目名称:evesrp,代码行数:4,代码来源:locale.py

示例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) 
开发者ID:accelero-cloud,项目名称:appkernel,代码行数:13,代码来源:engine.py

示例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(),
    } 
开发者ID:apache,项目名称:incubator-superset,代码行数:15,代码来源:base.py


注:本文中的flask_babel.get_locale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。