Add /language/<language> route for changing the locale using a session variable

master
DjVinnii 4 years ago
parent f30cca1263
commit 7dafa22762

@ -1,4 +1,4 @@
__all__ = [ __all__ = [
'admins', 'aliases', 'alternatives', 'base', 'domains', 'fetches', 'admins', 'aliases', 'alternatives', 'base', 'domains', 'fetches',
'managers', 'users', 'relays', 'tokens' 'managers', 'users', 'relays', 'tokens', 'languages'
] ]

@ -0,0 +1,9 @@
from mailu.ui import ui, forms, access
import flask
@ui.route('/language/<language>', methods=['GET'])
def set_language(language=None):
flask.session['language'] = language
return flask.redirect(flask.url_for('.user_settings'))

@ -27,10 +27,17 @@ babel = flask_babel.Babel()
@babel.localeselector @babel.localeselector
def get_locale(): def get_locale():
try:
language = flask.session['language']
except KeyError:
language = None
if language is not None:
return language
translations = list(map(str, babel.list_translations())) translations = list(map(str, babel.list_translations()))
return flask.request.accept_languages.best_match(translations) return flask.request.accept_languages.best_match(translations)
# Proxy fixer # Proxy fixer
class PrefixMiddleware(object): class PrefixMiddleware(object):
def __call__(self, environ, start_response): def __call__(self, environ, start_response):

Loading…
Cancel
Save