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:
parent
f30cca1263
commit
7dafa22762
@ -1,4 +1,4 @@
|
||||
__all__ = [
|
||||
'admins', 'aliases', 'alternatives', 'base', 'domains', 'fetches',
|
||||
'managers', 'users', 'relays', 'tokens'
|
||||
'managers', 'users', 'relays', 'tokens', 'languages'
|
||||
]
|
||||
|
9
core/admin/mailu/ui/views/languages.py
Normal file
9
core/admin/mailu/ui/views/languages.py
Normal 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'))
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user