fix: rester sur la même page au changement de langue

This commit is contained in:
2026-07-06 18:13:32 +04:00
parent 09fef8f590
commit 40df39cc67
2 changed files with 28 additions and 2 deletions
+26
View File
@@ -69,6 +69,32 @@
themeToggle?.addEventListener('click', toggleTheme);
})();
// Language switch with page mapping
function switchLanguage(lang) {
const currentPath = window.location.pathname;
let newPath;
if (lang === 'fr') {
// Switch to French
if (currentPath.startsWith('/en/')) {
newPath = currentPath.substring(3); // Remove '/en'
} else {
newPath = currentPath;
}
newPath = newPath.replace('/press/', '/presse/');
} else {
// Switch to English
if (!currentPath.startsWith('/en/')) {
newPath = '/en' + currentPath;
} else {
newPath = currentPath;
}
newPath = newPath.replace('/presse/', '/press/');
}
window.location.href = newPath;
}
// Smooth scrolling (uniquement pour les ancres de la page courante)
document.querySelectorAll('a[href*="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {