fix: rester sur la même page au changement de langue
This commit is contained in:
@@ -31,9 +31,9 @@
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% if locale == 'en' %}
|
||||
<a href="/" class="lang-switch" onclick="localStorage.setItem('oki-lang-pref','fr')">{{ t.ui.lang_switch_label }}</a>
|
||||
<a href="#" class="lang-switch" onclick="localStorage.setItem('oki-lang-pref','fr'); switchLanguage('fr'); return false;">{{ t.ui.lang_switch_label }}</a>
|
||||
{% else %}
|
||||
<a href="/en/" class="lang-switch" onclick="localStorage.setItem('oki-lang-pref','en')">{{ t.ui.lang_switch_label }}</a>
|
||||
<a href="#" class="lang-switch" onclick="localStorage.setItem('oki-lang-pref','en'); switchLanguage('en'); return false;">{{ t.ui.lang_switch_label }}</a>
|
||||
{% endif %}
|
||||
<button id="theme-toggle" class="theme-toggle" aria-label="{{ t.ui.theme_toggle }}" title="{{ t.ui.theme_toggle }}">
|
||||
<span class="theme-icon theme-icon-dark">🌙</span>
|
||||
|
||||
@@ -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