husstanden/localizer.py

21 lines
459 B
Python
Raw Normal View History

2019-05-12 16:04:25 +02:00
from flask import g, request, session
from flask_babel import Babel
from objects import glob
babel = Babel(glob.app)
LANGUAGES = {
"en": "English",
"no": "Norwegian"
}
@babel.localeselector
def get_locale():
2019-05-12 16:24:20 +02:00
# force session lang to be set
session["lang"] = session.get("lang", "en")
2019-05-12 16:04:25 +02:00
if request.args.get("lang"):
session["lang"] = request.args.get("lang") if request.args.get("lang") in LANGUAGES.keys() else "en"
return session.get("lang", "en")