Improve language detection script

This commit is contained in:
Sofía Aritz 2023-05-10 20:20:45 +02:00
parent 7d69d6d65e
commit 28e50e07c4

View file

@ -7,11 +7,11 @@ if (redirect_notice_enabled()) {
let language = (navigator.language || navigator.userLanguage).split("-")[0]
if (location.pathname.startsWith("/en")) {
if (language === "es") {
add_redirect_notice(location.pathname.replace("/en", ""), SPANISH_MESSAGE, SPANISH_BUTTON)
add_redirect_notice(location.pathname.replace("/en", "").slice(0, -1), SPANISH_MESSAGE, SPANISH_BUTTON)
}
} else if (!["weblog", "recommendations", "projects", "links"].includes(location.pathname.split("/")[1])) {
} else if (!["recommendations", "projects", "links"].includes(location.pathname.split("/")[1])) {
if (language !== "es") {
add_redirect_notice("/en" + location.pathname, ENGLISH_MESSAGE, ENGLISH_BUTTON)
add_redirect_notice("/en" + location.pathname.slice(0, -1), ENGLISH_MESSAGE, ENGLISH_BUTTON)
}
}
}