created language switcher
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
</div>
|
||||
<nav>
|
||||
<a href="/en/index.html">English</a>
|
||||
<a href="/de/index.html">Deutsch</a>
|
||||
</nav>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -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
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user