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:
parent
e35e79e84d
commit
0378a8edd7
2 changed files with 21 additions and 0 deletions
19
frontend/app/components/HtmlLang.tsx
Normal file
19
frontend/app/components/HtmlLang.tsx
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue