20 lines
662 B
JavaScript
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;
|
|
}
|
|
}
|