modified: app.py
modified: templates/base.html modified: templates/index.html
This commit is contained in:
8
app.py
8
app.py
@@ -29,6 +29,14 @@ def _set_language():
|
||||
g.lang = lang
|
||||
g.T = TRANSLATIONS[lang]
|
||||
|
||||
@app.after_request
|
||||
def _persist_language_cookie(response):
|
||||
"""If ?lang= was in the URL, save it as a cookie so it survives navigation."""
|
||||
url_lang = request.args.get("lang")
|
||||
if url_lang in TRANSLATIONS:
|
||||
response.set_cookie("lang", url_lang, max_age=60*60*24*365, samesite="Lax")
|
||||
return response
|
||||
|
||||
@app.context_processor
|
||||
def _inject_i18n():
|
||||
return {"T": g.get("T", TRANSLATIONS["de"]), "lang": g.get("lang", "de")}
|
||||
|
||||
Reference in New Issue
Block a user