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:
Nicolas Varrot
2026-02-13 15:11:39 +00:00
parent a44b6db77d
commit d3e8f3143a
2 changed files with 5 additions and 1 deletions

View File

@@ -62,8 +62,8 @@ export function MessageSearch({ open, onClose, onSearch, matchCount }: Props) {
onChange={e => setQuery(e.target.value)}
onKeyDown={handleKeyDown}
placeholder={t('search.placeholder')}
className="bg-transparent text-sm text-pc-text placeholder:text-pc-text-muted outline-none w-48"
aria-label={t('search.placeholder')}
className="bg-transparent text-sm text-pc-text placeholder:text-pc-text-muted outline-none w-48"
/>
{query && (
<span className="text-xs text-pc-text-muted whitespace-nowrap">

View File

@@ -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());
}