fix: sync html lang attribute with i18n locale selection
- Set document.documentElement.lang on initial load and locale change - Ensures screen readers and browser features respect the active language - Removes duplicate aria-label on MessageSearch input
This commit is contained in:
@@ -277,6 +277,9 @@ function resolveInitialLocale(): string {
|
||||
let currentLocale = resolveInitialLocale();
|
||||
let dict = messages[currentLocale] || messages.en;
|
||||
|
||||
// Sync <html lang> on initial load
|
||||
try { document.documentElement.lang = currentLocale; } catch { /* SSR */ }
|
||||
|
||||
type Listener = () => void;
|
||||
const listeners = new Set<Listener>();
|
||||
|
||||
@@ -297,6 +300,7 @@ export function setLocale(loc: string): void {
|
||||
currentLocale = loc;
|
||||
dict = messages[loc];
|
||||
try { localStorage.setItem(STORAGE_KEY, loc); } catch { /* noop */ }
|
||||
try { document.documentElement.lang = loc; } catch { /* SSR */ }
|
||||
listeners.forEach((fn) => fn());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user