created language switcher
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
import yaml
|
import yaml
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
LANG_LABELS = {
|
||||||
|
"en": "English",
|
||||||
|
"de": "Deutsch",
|
||||||
|
}
|
||||||
|
|
||||||
with open("content.yaml", "r") as f:
|
with open("content.yaml", "r") as f:
|
||||||
content = yaml.safe_load(f)
|
content = yaml.safe_load(f)
|
||||||
|
|
||||||
@@ -10,13 +15,28 @@ for page_name, translations in content.items():
|
|||||||
with open(template_file, "r") as f:
|
with open(template_file, "r") as f:
|
||||||
template = f.read()
|
template = f.read()
|
||||||
|
|
||||||
|
languages = list(translations.keys())
|
||||||
|
|
||||||
for lang, page_data in translations.items():
|
for lang, page_data in translations.items():
|
||||||
output = template
|
output = template
|
||||||
output = output.replace("{{lang}}", lang)
|
|
||||||
|
|
||||||
for key, value in page_data.items():
|
for key, value in page_data.items():
|
||||||
output = output.replace(f"{{{{{key}}}}}", value)
|
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
|
output_dir = lang
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="/en/index.html">English</a>
|
<a href="/en/index.html">English</a>
|
||||||
<a href="/de/index.html">Deutsch</a>
|
|
||||||
</nav>
|
</nav>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
<p>and this is my website</p>
|
<p>and this is my website</p>
|
||||||
</div>
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="/en/index.html">English</a>
|
|
||||||
<a href="/de/index.html">Deutsch</a>
|
<a href="/de/index.html">Deutsch</a>
|
||||||
</nav>
|
</nav>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
+1
-2
@@ -13,8 +13,7 @@
|
|||||||
<p>{{introduction-subheading}}</p>
|
<p>{{introduction-subheading}}</p>
|
||||||
</div>
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="/en/index.html">English</a>
|
{{language-switcher}}
|
||||||
<a href="/de/index.html">Deutsch</a>
|
|
||||||
</nav>
|
</nav>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user