Python flask.g.locale() Examples
The following are 10
code examples of flask.g.locale().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.g
, or try the search function
.
Example #1
Source File: engine.py From appkernel with Apache License 2.0 | 6 votes |
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))
Example #2
Source File: views.py From ReadableWebProxy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def before_request(): g.locale = 'en' g.session = database.get_db_session(flask_sess_if_possible=False) print("Checked out session")
Example #3
Source File: routes.py From AUCR with GNU General Public License v3.0 | 5 votes |
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())
Example #4
Source File: main.py From c3nav-32c3 with Apache License 2.0 | 5 votes |
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
Example #5
Source File: main.py From c3nav-32c3 with Apache License 2.0 | 5 votes |
def before_request(): g.locale = get_locale()
Example #6
Source File: poigroup.py From c3nav-32c3 with Apache License 2.0 | 5 votes |
def title(self): return self.any_titles.get(g.locale, self.name)
Example #7
Source File: roomgroup.py From c3nav-32c3 with Apache License 2.0 | 5 votes |
def title(self): return self.any_titles.get(g.locale, self.name)
Example #8
Source File: location.py From c3nav-32c3 with Apache License 2.0 | 5 votes |
def title(self): return self.titles.get(g.locale, self.name)
Example #9
Source File: engine.py From appkernel with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: settings.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 4 votes |
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'] )