Skip to content

Commit 6bde264

Browse files
committed
fix(website): lang/dir not updating after switching language
1 parent 4f72f81 commit 6bde264

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

apps/website/src/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Footer from './components/Footer.js';
88
import GetStarted from './pages/GetStarted/get-started.js';
99
import SupportUs from './pages/SupportUs/SupportUs.js';
1010
import { createContext } from 'preact';
11-
import { useRef } from 'preact/hooks';
11+
import { useLayoutEffect, useRef } from 'preact/hooks';
1212
import { changeLanguage } from 'i18next';
1313
import { extractLocaleFromUrl, initTranslations, LOCALES, mapLocale } from './i18n';
1414

@@ -50,6 +50,13 @@ export function LocaleProvider({ children }) {
5050
changeLanguage(localeId);
5151
}
5252

53+
// Update html lang and dir attributes
54+
useLayoutEffect(() => {
55+
const correspondingLocale = LOCALES.find(l => l.id === localeId);
56+
document.documentElement.lang = localeId;
57+
document.documentElement.dir = correspondingLocale?.rtl ? "rtl" : "ltr";
58+
}, [localeId]);
59+
5360
return (
5461
<LocaleContext.Provider value={localeId}>
5562
{children}

0 commit comments

Comments
 (0)