Add language selector

master
DjVinnii 4 years ago
parent 7dafa22762
commit 419fed5e6e

@ -15,6 +15,8 @@ import 'admin-lte/plugins/fontawesome-free/css/solid.css';
import 'admin-lte/build/scss/adminlte.scss'; import 'admin-lte/build/scss/adminlte.scss';
import 'admin-lte/plugins/datatables-bs4/css/dataTables.bootstrap4.css'; import 'admin-lte/plugins/datatables-bs4/css/dataTables.bootstrap4.css';
import 'admin-lte/plugins/datatables-responsive/css/responsive.bootstrap4.css'; import 'admin-lte/plugins/datatables-responsive/css/responsive.bootstrap4.css';
import 'admin-lte/plugins/bootstrap/js/bootstrap.js';
import 'admin-lte/build/js/AdminLTE.js';
import 'admin-lte/build/js/Layout.js'; import 'admin-lte/build/js/Layout.js';
import 'admin-lte/build/js/ControlSidebar.js'; import 'admin-lte/build/js/ControlSidebar.js';
import 'admin-lte/build/js/PushMenu.js'; import 'admin-lte/build/js/PushMenu.js';

@ -16,6 +16,16 @@
<a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a> <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
</li> </li>
</ul> </ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown">
<a class="nav-link" data-toggle="dropdown" href="#" aria-expanded="false">{{ session['language'] }}</a>
<div class="dropdown-menu dropdown-menu-right p-0">
{% for language in session['available_languages'] %}
<a class="dropdown-item {% if language == session['language'] %}active{% endif %} " href="{{ url_for('.set_language', language=language) }}">{{ language }}</a>
{% endfor %}
</div>
</li>
</ul>
</nav> </nav>
<aside class="main-sidebar sidebar-dark-primary"> <aside class="main-sidebar sidebar-dark-primary">
<a href="{{ config["WEB_ADMIN"] }}" class="brand-link"> <a href="{{ config["WEB_ADMIN"] }}" class="brand-link">

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

Loading…
Cancel
Save