️(frontend) update html lang on language change

Performs lang attribute update on html tag on every language change.
By default the attribute value uses the i18n.language value.
This commit is contained in:
daproclaima
2024-07-01 18:32:42 +02:00
committed by Sebastien Nobour
parent bea23cc6e9
commit dfb5394310
2 changed files with 7 additions and 1 deletions

View File

@@ -16,6 +16,11 @@ i18n
preload: LANGUAGES_ALLOWED,
nsSeparator: '||',
})
.then(() => {
if (typeof window !== 'undefined') {
document.documentElement.lang = i18n.language;
}
})
.catch(() => {
throw new Error('i18n initialization failed');
});
@@ -24,6 +29,7 @@ i18n
i18n.on('languageChanged', (lng) => {
if (typeof window !== 'undefined') {
localStorage.setItem(LANGUAGE_LOCAL_STORAGE, lng);
document.documentElement.lang = lng;
}
});

View File

@@ -4,7 +4,7 @@ import '@/i18n/initI18n';
export default function RootLayout() {
return (
<Html lang="en">
<Html>
<Head />
<body suppressHydrationWarning={process.env.NODE_ENV === 'development'}>
<Main />