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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user