-
Notifications
You must be signed in to change notification settings - Fork 398
🌐(frontend) set html lang attribute dynamically based on current loc #1248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
e1b4609
to
9a5e259
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Work well !
Instead of HtmlLangUpdater
we should leverage directly i18next
i think.
Here we init i18next: https://github.com/suitenumerique/docs/blob/main/src/frontend/apps/impress/src/i18n/initI18n.ts
We could add a listener, wdyt ?
// Set initial lang attribute
document.documentElement.setAttribute(
'lang',
i18next.language || fallbackLng,
);
// Listen for language changes and update the lang attribute
i18next.on('languageChanged', (lang) => {
document.documentElement.setAttribute('lang', lang);
});
9a5e259
to
4c84518
Compare
4c84518
to
fc79efc
Compare
fc79efc
to
b59e16e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Last thing, can you add an assert in this test to check that the lang attribute switch correctly ?
docs/src/frontend/apps/e2e/__tests__/app-impress/language.spec.ts
Lines 26 to 27 in cde061c
test('checks language switching', async ({ page }) => { | |
const header = page.locator('header').first(); |
Of course, that makes sense. I’ve added assert for en, fr, and deutsch, since all three languages are covered in the test. |
b59e16e
to
32e3c70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you!
ensures proper language tag is set for accessibility and SEO compliance Signed-off-by: Cyril <[email protected]>
32e3c70
to
ec84f31
Compare
Purpose
Add a new HtmlLangUpdater component to dynamically update the attribute based on the current locale from i18next. This improves accessibility.
issue : 875
Proposal
Enregistrement.2025-07-31.113009.mp4
External contributions
Thank you for your contribution! 🎉
Please ensure the following items are checked before submitting your pull request:
git commit --signoff
(DCO compliance)git commit -S
)<gitmoji>(type) title description
## [Unreleased]
section (if noticeable change)