Refonte de la navigation en français et amélioration de la redirection linguistique
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
{{ $pageLink := replace (replace $context.RelPermalink (add $pageLang "/") "") $base.Path "/" }}
|
||||
|
||||
{{ if $context.IsTranslated }}
|
||||
<select class="{{ $class }} lang-select" onchange="location = this.value">
|
||||
<select class="{{ $class }} lang-select" onchange="(function(sel){
|
||||
var lang = sel.value.split('/')[1];
|
||||
localStorage.setItem('preferredLang', lang);
|
||||
location = sel.value;
|
||||
})(this)">
|
||||
{{ range $siteLanguages }}
|
||||
{{ if eq (string $pageLang) (string .Language) }}
|
||||
<option
|
||||
|
||||
Reference in New Issue
Block a user