Make HTML lang attribute dynamic based on selected language

- Create HtmlLang client component that updates document.documentElement.lang
- Add HtmlLang component to layout.tsx to sync HTML lang attribute with locale
- HTML lang now updates automatically when user changes language
This commit is contained in:
counterweight 2025-12-26 11:38:38 +01:00
parent e35e79e84d
commit 0378a8edd7
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1,19 @@
"use client";
import { useEffect } from "react";
import { useLanguage } from "../hooks/useLanguage";
/**
* Client component that updates the HTML lang attribute based on the selected language.
* This must be a client component because it uses hooks and DOM manipulation.
*/
export function HtmlLang() {
const { locale } = useLanguage();
useEffect(() => {
// Update the HTML lang attribute when locale changes
document.documentElement.lang = locale;
}, [locale]);
return null;
}