fix(website): lang/dir not updating after switching language

This commit is contained in:
Elian Doran 2025-10-27 18:31:03 +02:00
parent 4f72f81a95
commit 6bde264156
No known key found for this signature in database

View File

@ -8,7 +8,7 @@ import Footer from './components/Footer.js';
import GetStarted from './pages/GetStarted/get-started.js';
import SupportUs from './pages/SupportUs/SupportUs.js';
import { createContext } from 'preact';
import { useRef } from 'preact/hooks';
import { useLayoutEffect, useRef } from 'preact/hooks';
import { changeLanguage } from 'i18next';
import { extractLocaleFromUrl, initTranslations, LOCALES, mapLocale } from './i18n';
@ -50,6 +50,13 @@ export function LocaleProvider({ children }) {
changeLanguage(localeId);
}
// Update html lang and dir attributes
useLayoutEffect(() => {
const correspondingLocale = LOCALES.find(l => l.id === localeId);
document.documentElement.lang = localeId;
document.documentElement.dir = correspondingLocale?.rtl ? "rtl" : "ltr";
}, [localeId]);
return (
<LocaleContext.Provider value={localeId}>
{children}