當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。