forked from julia-dizhak/aat-reinigung
/
app.py
38 lines (29 loc) · 949 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask, request, render_template, redirect, session
from flask.ext.babel import Babel
from config import LANGUAGES, BABEL_DEFAULT_LOCALE
app = Flask(__name__, static_folder='.', static_url_path='')
app.config.from_pyfile('config.py')
app.secret_key = 'Jhr]ogxQ[Vmi4oo'
babel = Babel(app)
LANGUAGE_KEY = '_LANG_'
@babel.localeselector
def get_locale():
lang = session.get(LANGUAGE_KEY, BABEL_DEFAULT_LOCALE)
return lang
@app.route('/lang/<language>/')
def set_language_code(language=None):
session[LANGUAGE_KEY] = language if language in LANGUAGES.keys() else BABEL_DEFAULT_LOCALE
return redirect('/')
@app.route('/')
def root():
languages = LANGUAGES
current_language = get_locale()
return render_template(
'index.html',
**{
'LANGAUGES': LANGUAGES,
'LANGUAGE_CODE': current_language,
}
)
if __name__ == '__main__':
app.run(debug=True)