feat(website/i18n): set right dir and lang tags

This commit is contained in:
Elian Doran
2025-10-25 19:58:31 +03:00
parent 966c08da87
commit 9515e2099b

View File

@@ -10,6 +10,7 @@ import SupportUs from './pages/SupportUs/SupportUs.js';
import { createContext } from 'preact';
import { useEffect } from 'preact/hooks';
import { changeLanguage } from 'i18next';
import { LOCALES } from './i18n';
export const LocaleContext = createContext('en');
@@ -34,14 +35,17 @@ export function App(props: {repoStargazersCount: number}) {
export function LocaleProvider({ children }) {
const { path } = useLocation();
const locale = path.split('/')[1] || 'en';
const localeId = path.split('/')[1] || 'en';
useEffect(() => {
changeLanguage(locale);
}, [ locale ]);
changeLanguage(localeId);
const correspondingLocale = LOCALES.find(l => l.id === localeId);
document.documentElement.lang = localeId;
document.documentElement.dir = correspondingLocale?.rtl ? "rtl" : "ltr";
}, [ localeId ]);
return (
<LocaleContext.Provider value={locale}>
<LocaleContext.Provider value={localeId}>
{children}
</LocaleContext.Provider>
);