fix(a11y): WCAG 3.1.2 — set HTML lang attribute dynamically from locale#39243
Conversation
…le for screen readers
There was a problem hiding this comment.
Code Review Agent Run #95bf01
Actionable Suggestions - 1
-
superset-frontend/src/views/App.tsx - 1
- Accessibility: Incomplete BCP-47 locale normalization · Line 52-57
Review Details
-
Files reviewed - 1 · Commit Range:
41410f6..41410f6- superset-frontend/src/views/App.tsx
-
Files skipped - 0
-
Tools
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers a full AI review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.
Documentation & Help
| // WCAG 3.1.2: Set the HTML lang attribute based on the current locale | ||
| // so screen readers announce the correct language for the page content. | ||
| // Converts locale formats like "pt_BR" or "de-DE" to BCP-47 primary tag ("pt", "de"). | ||
| const locale = | ||
| bootstrapData.common?.locale || window.navigator.language || 'en'; | ||
| document.documentElement.lang = String(locale).split(/[_-]/)[0]; |
There was a problem hiding this comment.
The locale handling strips region subtags unnecessarily, which reduces precision for screen readers. BCP-47 recommends including region subtags when meaningful. Consider normalizing 'pt_BR' to 'pt-BR' instead of 'pt' for better accessibility compliance.
Code suggestion
Check the AI-generated fix before applying
| // WCAG 3.1.2: Set the HTML lang attribute based on the current locale | |
| // so screen readers announce the correct language for the page content. | |
| // Converts locale formats like "pt_BR" or "de-DE" to BCP-47 primary tag ("pt", "de"). | |
| const locale = | |
| bootstrapData.common?.locale || window.navigator.language || 'en'; | |
| document.documentElement.lang = String(locale).split(/[_-]/)[0]; | |
| // WCAG 3.1.2: Set the HTML lang attribute based on the current locale | |
| // so screen readers announce the correct language for the page content. | |
| // Normalize locale to BCP-47 format by replacing underscores with hyphens. | |
| const locale = | |
| bootstrapData.common?.locale || window.navigator.language || 'en'; | |
| document.documentElement.lang = String(locale).replace(/_/g, '-'); |
Code Review Run #95bf01
Should Bito avoid suggestions like this for future reviews? (Manage Rules)
- Yes, avoid them
…ng region subtag Address Bito code review finding: preserve region subtags like pt_BR as pt-BR so screen readers get locale-specific pronunciation hints, instead of collapsing to primary tag only (pt).
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thanks for the review @bito-code-review. Addressed the finding in |
Code Review Agent Run #d7441eActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
rusackas
left a comment
There was a problem hiding this comment.
LGTM! This one's easier than the rest :D
|
Approving CI 🤞 Will merge if it turns green. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #39243 +/- ##
==========================================
- Coverage 64.37% 64.37% -0.01%
==========================================
Files 2550 2550
Lines 132180 132182 +2
Branches 30661 30662 +1
==========================================
Hits 85096 85096
- Misses 45599 45601 +2
Partials 1485 1485
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
SUMMARY
Implements WCAG 2.1 criterion 3.1.2 (Language of Parts, Level AA).
document.documentElement.langfrombootstrapData.common.localeon app initializationpt_BRorde-DEto BCP-47 primary subtag (pt,de)window.navigator.languageorenTESTING INSTRUCTIONS
<html>element →langattribute should match the configured localeADDITIONAL INFORMATION
Part of a series of 16 individual WCAG 2.1 accessibility PRs. See also fix(a11y): Accessibility improvements for WCAG 2.1 Level A compliance #38342.