This commit is contained in:
Éloi Rivard 2020-08-17 11:38:25 +02:00
parent 5957029860
commit e500c7920a
8 changed files with 88 additions and 6 deletions

3
babel.cfg Normal file
View file

@ -0,0 +1,3 @@
[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_

View file

@ -1,5 +1,8 @@
SECRET_KEY = "change me before you go in production"
# If unset, language is detected
LANGUAGE = 'en'
[LDAP]
URI = "ldaps://ldap.mydomain.tld"
BIND_USER = "cn=admin,dc=mydomain,dc=tld"

View file

@ -1,5 +1,5 @@
Flask
Flask-SQLAlchemy
Authlib==0.14.3
authlib
flask
flask-babel
python-ldap
toml

View file

@ -1,7 +1,9 @@
import ldap
import os
import toml
from flask import Flask, g
from flask import Flask, g, request
from flask_babel import Babel
from .oauth2 import config_oauth
from .routes import bp
@ -33,3 +35,22 @@ def setup_app(app):
config_oauth(app)
app.register_blueprint(bp, url_prefix="")
babel = Babel(app)
@babel.localeselector
def get_locale():
user = getattr(g, 'user', None)
if user is not None:
return user.locale
if app.config.get("LANGUAGE"):
return app.config.get("LANGUAGE")
return request.accept_languages.best_match(['fr', 'en'])
@babel.timezoneselector
def get_timezone():
user = getattr(g, 'user', None)
if user is not None:
return user.timezone

View file

@ -1,6 +1,6 @@
{% if user %}
<style>pre{white-space:wrap}</style>
<div>Logged in as <strong>{{user}}</strong> (<a href="{{ url_for('.logout') }}">Log Out</a>)</div>
<div>{{ _('Logged in as') }} <strong>{{user}}</strong> (<a href="{{ url_for('.logout') }}">Log Out</a>)</div>
{% for client in clients %}
<strong>Client</strong>
@ -24,7 +24,7 @@
<hr>
{% endfor %}
<br><a href="{{ url_for('.create_client') }}">Create Client</a>
<br><a href="{{ url_for('.create_client') }}">{% trans %}Create Client{% endtrans %}</a>
{% else %}
<form action="" method="post">

Binary file not shown.

View file

@ -0,0 +1,28 @@
# French translations for PROJECT.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2020.
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2020-08-17 11:20+0200\n"
"PO-Revision-Date: 2020-08-17 11:20+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: fr\n"
"Language-Team: fr <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n > 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.8.0\n"
#: website/templates/home.html:3
msgid "Logged in as"
msgstr "Connecté en tant que"
#: website/templates/home.html:27
msgid "Create Client"
msgstr "Créer un client"

View file

@ -0,0 +1,27 @@
# Translations template for PROJECT.
# Copyright (C) 2020 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2020.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2020-08-17 11:20+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.8.0\n"
#: website/templates/home.html:3
msgid "Logged in as"
msgstr ""
#: website/templates/home.html:27
msgid "Create Client"
msgstr ""