Refonte de la navigation en français et amélioration de la redirection linguistique

This commit is contained in:
Boris Waaub
2026-01-19 16:52:36 +01:00
parent 7b724fb001
commit 2fce96f794
3 changed files with 85 additions and 72 deletions
+11 -10
View File
@@ -2,17 +2,18 @@
(function () {
"use strict";
(function() {
// Redirect to language-specific homepage based on browser language, default to English
var supportedLangs = ['fr', 'nl'];
var userLang = navigator.language || navigator.userLanguage;
userLang = userLang.split('-')[0];
var supportedLangs = ['fr', 'nl']; // Liste des langues supportées
var storedLang = localStorage.getItem('preferredLang');
var navigatorLang = (navigator.language || navigator.userLanguage).split('-')[0];
var currentPath = window.location.pathname;
var alreadyLang = supportedLangs.some(function(lang) {
return currentPath.startsWith('/' + lang + '/');
});
if (supportedLangs.includes(userLang) && !alreadyLang) {
window.location.href = '/' + userLang + '/';
// Redirige vers la langue stockée si présente, sinon vers la langue du navigateur
if (currentPath === '/') {
if (storedLang && storedLang !== '') {
window.location.href = '/' + storedLang;
} else if (supportedLangs.includes(navigatorLang)) {
window.location.href = '/' + navigatorLang;
}
}
})();