當前位置: 首頁>>代碼示例>>Python>>正文


Python g.locale方法代碼示例

本文整理匯總了Python中flask.g.locale方法的典型用法代碼示例。如果您正苦於以下問題:Python g.locale方法的具體用法?Python g.locale怎麽用?Python g.locale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.g的用法示例。


在下文中一共展示了g.locale方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init_babel

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import locale [as 別名]
def __init_babel(self):
        self.babel = Babel(self.app)
        # translations = Translations.load('translations')
        # translations.merge(Translations.load())
        # todo: support for multiple plugins
        supported_languages = []
        for supported_lang in self.cfg_engine.get('appkernel.i18n.languages', ['en-US']):
            supported_languages.append(supported_lang)
            if '-' in supported_lang:
                supported_languages.append(supported_lang.split('-')[0])

        def get_current_locale():
            with self.app.app_context():
                best_match = request.accept_languages.best_match(supported_languages, default='en')
                return best_match.replace('-', '_')

        self.babel.localeselector(get_current_locale)
        # catalogs = gettext.find('locale', 'locale', all=True)
        # self.logger.info('Using message catalogs: {}'.format(catalogs)) 
開發者ID:accelero-cloud,項目名稱:appkernel,代碼行數:21,代碼來源:engine.py

示例2: before_request

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import locale [as 別名]
def before_request():
	g.locale = 'en'
	g.session = database.get_db_session(flask_sess_if_possible=False)
	print("Checked out session") 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:6,代碼來源:views.py

示例3: before_request

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import 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

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import locale [as 別名]
def get_locale():
    locale = 'en'  # request.accept_languages.best_match(LANGUAGES.keys())
    if request.cookies.get('lang') in LANGUAGES.keys():
        locale = request.cookies.get('lang')
    if request.args.get('lang') in LANGUAGES.keys():
        locale = request.args.get('lang')
    return locale 
開發者ID:c3nav,項目名稱:c3nav-32c3,代碼行數:9,代碼來源:main.py

示例5: before_request

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import locale [as 別名]
def before_request():
    g.locale = get_locale() 
開發者ID:c3nav,項目名稱:c3nav-32c3,代碼行數:4,代碼來源:main.py

示例6: title

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import locale [as 別名]
def title(self):
        return self.any_titles.get(g.locale, self.name) 
開發者ID:c3nav,項目名稱:c3nav-32c3,代碼行數:4,代碼來源:poigroup.py

示例7: title

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import locale [as 別名]
def title(self):
        return self.titles.get(g.locale, self.name) 
開發者ID:c3nav,項目名稱:c3nav-32c3,代碼行數:4,代碼來源:location.py

示例8: __init_web_layer

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import 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

示例9: get

# 需要導入模塊: from flask import g [as 別名]
# 或者: from flask.g import locale [as 別名]
def get(self, server=None, client=None, conf=None):
        """Reads a given client configuration"""
        try:
            conf = unquote(conf)
        except:
            pass
        args = self.parser_get.parse_args()
        template = args.get('template', False)
        statictemplate = args.get('statictemplate', False)
        parser = bui.client.get_parser(agent=server)
        res = parser.read_client_conf(client, conf, template, statictemplate)
        refresh()
        # Translate the doc and placeholder API side
        cache_keys = {
            'doc': '_doc_parser_{}-{}'.format(server, g.locale),
            'placeholders': '_placeholders_parser_{}-{}'.format(server, g.locale),
            'boolean_cli': '_boolean_cli_parser_{}'.format(server),
            'string_cli': '_string_cli_parser_{}'.format(server),
            'integer_cli': '_integer_cli_parser_{}'.format(server),
            'multi_cli': '_multi_cli_parser_{}'.format(server),
            'values': '_suggest_parser_{}'.format(server),
            'defaults': '_defaults_parser_{}'.format(server),
        }
        cache_results = {}
        for name, key in cache_keys.items():
            if not cache.cache.has(key):
                if name in ['doc', 'placeholders']:
                    _tmp = bui.client.get_parser_attr(name, server).copy()
                    _tmp2 = {}
                    for k, v in _tmp.items():
                        _tmp2[k] = _(v)
                    cache_results[name] = _tmp2
                else:
                    cache_results[name] = bui.client.get_parser_attr(name, server)
                cache.cache.set(key, cache_results[name], 3600)
            else:
                cache_results[name] = cache.cache.get(key)

        return jsonify(
            results=res,
            boolean=cache_results['boolean_cli'],
            string=cache_results['string_cli'],
            integer=cache_results['integer_cli'],
            multi=cache_results['multi_cli'],
            server_doc=cache_results['doc'],
            suggest=cache_results['values'],
            placeholders=cache_results['placeholders'],
            defaults=cache_results['defaults']
        ) 
開發者ID:ziirish,項目名稱:burp-ui,代碼行數:51,代碼來源:settings.py


注:本文中的flask.g.locale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。