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:
@@ -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">
|
||||
|
||||
@@ -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