created language switcher

This commit is contained in:
2026-04-22 22:36:32 +02:00
parent 259e4dd330
commit ff0ba86bf1
4 changed files with 25 additions and 8 deletions
+21 -1
View File
@@ -1,6 +1,11 @@
import yaml
import os
LANG_LABELS = {
"en": "English",
"de": "Deutsch",
}
with open("content.yaml", "r") as f:
content = yaml.safe_load(f)
@@ -10,13 +15,28 @@ for page_name, translations in content.items():
with open(template_file, "r") as f:
template = f.read()
languages = list(translations.keys())
for lang, page_data in translations.items():
output = template
output = output.replace("{{lang}}", lang)
for key, value in page_data.items():
output = output.replace(f"{{{{{key}}}}}", value)
output = output.replace("{{lang}}", lang)
links = []
for other_lang in languages:
if other_lang == lang:
continue
label = LANG_LABELS.get(other_lang, other_lang)
link = f'<a href="/{other_lang}/{page_name}.html">{label}</a>'
links.append(link)
language_switcher = " ".join(links)
output = output.replace("{{language-switcher}}", language_switcher)
output_dir = lang
os.makedirs(output_dir, exist_ok=True)
-1
View File
@@ -14,7 +14,6 @@
</div>
<nav>
<a href="/en/index.html">English</a>
<a href="/de/index.html">Deutsch</a>
</nav>
</body>
-1
View File
@@ -13,7 +13,6 @@
<p>and this is my website</p>
</div>
<nav>
<a href="/en/index.html">English</a>
<a href="/de/index.html">Deutsch</a>
</nav>
</body>
+1 -2
View File
@@ -13,8 +13,7 @@
<p>{{introduction-subheading}}</p>
</div>
<nav>
<a href="/en/index.html">English</a>
<a href="/de/index.html">Deutsch</a>
{{language-switcher}}
</nav>
</body>