Add language button and remove all others

This commit is contained in:
Kai Vogelgesang
2025-09-20 01:35:58 +02:00
parent 916c9e60e4
commit 19113626fb
3 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
const switchLanguage = () => {
// Get current URL
let url = window.location.href;
let path = window.location.pathname;
let filename = path.split("/").pop();
// Detect if it's an English page
if (filename.endsWith(".en.html")) {
// Switch to German: remove ".en"
let newFilename = filename.replace(".en.html", ".html");
let newUrl = url.replace(filename, newFilename);
window.location.href = newUrl;
} else if (filename.endsWith(".html")) {
// Switch to English: add ".en"
let newFilename = filename.replace(".html", ".en.html");
let newUrl = url.replace(filename, newFilename);
window.location.href = newUrl;
}
}