fix(i18n,a11y): sync <html lang> + dir with i18n language

index.html ships <html lang='ru'> and that attribute never changed at
runtime, regardless of the user's selected language. Consequences:
- screen readers pronounced en/zh/fa content using Russian phonics
- browsers offered to translate already-translated content
- the Telegram login button and an OAuth widget read documentElement.lang
  to set their own locale and got the wrong one

LanguageSwitcher had a half-fix that only touched dir for fa, and only
locally — i18n changes from anywhere else (initial detect, Telegram
adopt) were not covered.

Move both lang and dir updates into a single languageChanged subscriber
inside i18n.ts, run once for the initial detected language, and drop
the now-redundant dir-setting in LanguageSwitcher. Layout direction
flips automatically for the full RTL set (fa + future ar/he/ur).
This commit is contained in:
c0mrade
2026-05-26 15:15:26 +03:00
parent 7f14c499ad
commit 28c682500c
2 changed files with 21 additions and 5 deletions

View File

@@ -34,15 +34,12 @@ export default function LanguageSwitcher() {
}, []);
const changeLanguage = (code: string) => {
// i18n.ts subscribes to languageChanged and syncs <html lang> + dir
// centrally — no need to set documentElement.dir here.
i18n.changeLanguage(code);
document.documentElement.dir = code === 'fa' ? 'rtl' : 'ltr';
setIsOpen(false);
};
useEffect(() => {
document.documentElement.dir = i18n.language === 'fa' ? 'rtl' : 'ltr';
}, [i18n.language]);
if (availableLanguages.length <= 1) {
return null;
}