space-workshop/extensions/fix_buttons/static/switch-language.js
2025-09-20 01:35:58 +02:00

20 lines
662 B
JavaScript

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;
}
}