fix: rester sur la même page au changement de langue
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user