1
0
mirror of https://github.com/Mailu/Mailu.git synced 2025-01-16 02:46:44 +02:00

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

This commit is contained in:
DjVinnii 2021-04-03 10:33:08 +02:00
parent f30cca1263
commit 7dafa22762
3 changed files with 18 additions and 2 deletions

View File

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

View File

@ -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'))

View File

@ -27,10 +27,17 @@ babel = flask_babel.Babel()
@babel.localeselector
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()))
return flask.request.accept_languages.best_match(translations)
# Proxy fixer
class PrefixMiddleware(object):
def __call__(self, environ, start_response):