1
0
Fork 0
mirror of https://github.com/Findus23/lw1.at.git synced 2024-09-10 05:13:46 +02:00
lw1.at/assets/redirector.ts
2022-04-26 17:31:08 +02:00

25 lines
593 B
TypeScript

import type {Language} from "./types";
export function defaultLanguage(): Language {
const lang = navigator.language.toLowerCase()
if (lang.includes("de")) {
return "de"
}
return "en"
}
export function redirect(): void {
const l = window.location
const imprintName = {"de": "impressum", "en": "imprint"}
const currentPath = l.pathname
const lang = defaultLanguage()
if (currentPath.startsWith("/i")) {
l.replace("/" + lang + "/" + imprintName[lang])
return
}
l.replace("/" + defaultLanguage() + l.pathname)
}
redirect()