Skip to content

Conversation

Ovgodd
Copy link
Collaborator

@Ovgodd Ovgodd commented Jul 31, 2025

Purpose

Add a new HtmlLangUpdater component to dynamically update the attribute based on the current locale from i18next. This improves accessibility.

issue : 875

Proposal

  • Create HtmlLangUpdater component using useTranslation and useEffect
  • Integrate HtmlLangUpdater in the main app and document.tsx layout
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:

  • I have read and followed the contributing guidelines
  • I have read and agreed to the Code of Conduct
  • I have signed off my commits with git commit --signoff (DCO compliance)
  • I have signed my commits with my SSH or GPG key (git commit -S)
  • My commit messages follow the required format: <gitmoji>(type) title description
  • I have added a changelog entry under ## [Unreleased] section (if noticeable change)
  • I have added corresponding tests for new features or bug fixes (if applicable)

Copy link
Collaborator

@AntoLC AntoLC left a 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);
});

@Ovgodd Ovgodd force-pushed the fix/875-lang-attribute branch from 9a5e259 to 4c84518 Compare July 31, 2025 12:58
@Ovgodd Ovgodd requested a review from AntoLC July 31, 2025 13:00
@Ovgodd Ovgodd force-pushed the fix/875-lang-attribute branch from 4c84518 to fc79efc Compare July 31, 2025 13:02
@Ovgodd Ovgodd self-assigned this Jul 31, 2025
@Ovgodd Ovgodd force-pushed the fix/875-lang-attribute branch from fc79efc to b59e16e Compare July 31, 2025 13:12
Copy link
Collaborator

@AntoLC AntoLC left a 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 ?

test('checks language switching', async ({ page }) => {
const header = page.locator('header').first();

@Ovgodd
Copy link
Collaborator Author

Ovgodd commented Jul 31, 2025

Last thing, can you add an assert in this test to check that the lang attribute switch correctly ?

Of course, that makes sense. I’ve added assert for en, fr, and deutsch, since all three languages are covered in the test.

@Ovgodd Ovgodd force-pushed the fix/875-lang-attribute branch from b59e16e to 32e3c70 Compare July 31, 2025 14:31
@Ovgodd Ovgodd requested a review from AntoLC July 31, 2025 14:31
Copy link
Collaborator

@AntoLC AntoLC left a 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]>
@Ovgodd Ovgodd force-pushed the fix/875-lang-attribute branch from 32e3c70 to ec84f31 Compare August 4, 2025 06:43
@Ovgodd Ovgodd merged commit ec84f31 into main Aug 4, 2025
21 of 22 checks passed
@Ovgodd Ovgodd deleted the fix/875-lang-attribute branch August 4, 2025 07:14
@AntoLC AntoLC linked an issue Aug 6, 2025 that may be closed by this pull request
@AntoLC AntoLC mentioned this pull request Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importance of the lang attribute on HTML elements
2 participants