Skip to content
Snippets Groups Projects
Commit 176588c6 authored by Jan Mach's avatar Jan Mach
Browse files

Make detection of best possible locale for application optional to enable forcing default.

parent ad197559
No related branches found
No related tags found
No related merge requests found
......@@ -65,6 +65,8 @@ class Config: # pylint: disable=locally-disabled,too-few-public-methods
#
BABEL_DEFAULT_LOCALE = vial.const.DEFAULT_LOCALE
BABEL_DEFAULT_TIMEZONE = vial.const.DEFAULT_TIMEZONE
BABEL_DETECT_LOCALE = True
"""Custom configuration, make detection of best possible locale optional to enable forcing default."""
#
# Flask-SQLAlchemy configurations.
......
......@@ -29,13 +29,14 @@ def get_locale(): # pylint: disable=locally-disabled,unused-variable
# Store the best locale selection into the session.
if 'locale' not in flask.session or not flask.session['locale']:
flask.session['locale'] = flask.request.accept_languages.best_match(
flask.current_app.config['SUPPORTED_LOCALES'].keys()
)
if flask.current_app.config['BABEL_DETECT_LOCALE']:
flask.session['locale'] = flask.request.accept_languages.best_match(
flask.current_app.config['SUPPORTED_LOCALES'].keys()
)
else:
flask.session['locale'] = flask.current_app.config['BABEL_DEFAULT_LOCALE']
if 'locale' in flask.session and flask.session['locale']:
return flask.session['locale']
return flask.current_app.config['BABEL_DEFAULT_LOCALE']
return flask.session['locale']
@BABEL.timezoneselector
def get_timezone(): # pylint: disable=locally-disabled,unused-variable
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment