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.lang = lang
|
||||||
g.T = TRANSLATIONS[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
|
@app.context_processor
|
||||||
def _inject_i18n():
|
def _inject_i18n():
|
||||||
return {"T": g.get("T", TRANSLATIONS["de"]), "lang": g.get("lang", "de")}
|
return {"T": g.get("T", TRANSLATIONS["de"]), "lang": g.get("lang", "de")}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
<form class="nav-search" action="/wetter" method="get" autocomplete="off">
|
<form class="nav-search" action="/wetter" method="get" autocomplete="off">
|
||||||
<div class="nav-search-wrap">
|
<div class="nav-search-wrap">
|
||||||
<svg class="nav-search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>
|
<svg class="nav-search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>
|
||||||
|
<input type="hidden" name="lang" value="{{ lang }}">
|
||||||
<input type="text" name="ort" id="nav-ort" placeholder="{{ T.nav_placeholder }}" value="{{ request.args.get('ort','') }}"/>
|
<input type="text" name="ort" id="nav-ort" placeholder="{{ T.nav_placeholder }}" value="{{ request.args.get('ort','') }}"/>
|
||||||
<ul class="ac-list" id="nav-ac"></ul>
|
<ul class="ac-list" id="nav-ac"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<svg class="home-search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
<svg class="home-search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||||
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/>
|
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
<input type="hidden" name="lang" value="{{ lang }}">
|
||||||
<input type="text" name="ort" id="home-ort" placeholder="{{ T.home_placeholder }}" required autofocus/>
|
<input type="text" name="ort" id="home-ort" placeholder="{{ T.home_placeholder }}" required autofocus/>
|
||||||
<ul class="ac-list" id="home-ac"></ul>
|
<ul class="ac-list" id="home-ac"></ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -61,7 +62,7 @@ document.getElementById("btn-location").addEventListener("click", function() {
|
|||||||
this.textContent = _i18n.locating;
|
this.textContent = _i18n.locating;
|
||||||
this.disabled = true;
|
this.disabled = true;
|
||||||
navigator.geolocation.getCurrentPosition(
|
navigator.geolocation.getCurrentPosition(
|
||||||
pos => { window.location = `/wetter?lat=${pos.coords.latitude}&lon=${pos.coords.longitude}&ort=Mein+Standort`; },
|
pos => { window.location = `/wetter?lat=${pos.coords.latitude}&lon=${pos.coords.longitude}&ort=Mein+Standort&lang={{ lang }}`; },
|
||||||
() => { this.textContent = _i18n.locationUnavailable; this.disabled = false; }
|
() => { this.textContent = _i18n.locationUnavailable; this.disabled = false; }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user