debianize-mobilizon/docs/javascripts/redirect.js
Thomas Citharel f3566430a3
Introduce multi-lingual docs
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2020-10-21 09:04:42 +02:00

19 lines
514 B
JavaScript

const languages = ["fr"];
const navigatorLanguage =
window.navigator.userLanguage || window.navigator.language;
let language;
if (languages.includes(navigatorLanguage)) {
language = navigatorLanguage;
}
const split = navigatorLanguage.split("-")[0];
if (languages.includes(split)) {
language = split;
}
const url = new URL(window.location.href);
if (language && (url.pathname === "/" || url.pathname.startsWith("/use/"))) {
url.pathname = `/${language}${url.pathname}`;
window.location.replace(url);
}