Skip to content

[A11y] Add lang attribute to language options for screen reader pronunciation#84588

Merged
dangrous merged 3 commits intomainfrom
claude-fixLanguagePageScreenReaderLang
Mar 16, 2026
Merged

[A11y] Add lang attribute to language options for screen reader pronunciation#84588
dangrous merged 3 commits intomainfrom
claude-fixLanguagePageScreenReaderLang

Conversation

@MelvinBot
Copy link
Contributor

Explanation of Change

Non-English language options on the Language preferences page (Settings > Preferences > Language) were being announced with English pronunciation by screen readers (e.g., JAWS + Chrome) because the HTML elements lacked the lang attribute. Per WCAG 3.1.1, the lang attribute tells screen readers which language to use for pronunciation, so without it, text like "中文 (简体)" or "日本語" was either mispronounced or skipped entirely.

This PR adds a lang property to the ListItem type, threads it through BaseListItem to the pressable DOM element, and sets it on each language option in LanguagePage using the locale code as the BCP 47 language tag. On web, React Native Web forwards the lang prop to the HTML lang attribute on the rendered <div>. On native platforms, the prop is harmlessly ignored.

Fixed Issues

$ #74881

Tests

  1. Enable a screen reader (JAWS on Windows, VoiceOver on Mac)
  2. Open the app and navigate to Settings > Preferences > Language
  3. Tab through the language options
  4. Verify each language option is announced using the correct pronunciation for that language (e.g., "Deutsch" with German pronunciation, "日本語" with Japanese pronunciation)
  5. Verify the language selection still works correctly when clicking/pressing Enter on an option
  • Verify that no errors appear in the JS console

Offline tests

N/A — These are accessibility attribute changes that don't affect offline behavior.

QA Steps

  1. Enable a screen reader (JAWS on Windows, VoiceOver on Mac)
  2. Navigate to Settings > Preferences > Language
  3. Tab through the language options
  4. Verify each language option is announced using the correct pronunciation for that language
  5. Verify selecting a language still changes the app locale correctly
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Web: Language Preferences Page with lang attributes

Language preferences page showing all 10 language options with lang attributes
Full-page screenshot of Language preferences page

DOM verification showing each language option now has the correct lang attribute:

English → lang="en"
Deutsch → lang="de"
Español → lang="es"
Français → lang="fr"
Italiano → lang="it"
Nederlands → lang="nl"
Polski → lang="pl"
Português (BR) → lang="pt-BR"
中文 (简体) → lang="zh-hans"
日本語 → lang="ja"

… pronunciation

Non-English language options on the Language preferences page were being
announced with English pronunciation by screen readers (JAWS + Chrome)
because the HTML elements lacked the lang attribute. This adds a lang
property to ListItem, threads it through BaseListItem to the pressable
element, and sets it on each language option in LanguagePage using the
locale code as the BCP 47 language tag.

Co-authored-by: Rushat Gabhane <rushatgabhane@users.noreply.github.com>
@rushatgabhane
Copy link
Member

@MelvinBot will this work on react native? https://reactnative.dev/docs/accessibility

suggest a fix that works on native too

@MelvinBot
Copy link
Contributor Author

Good catch — the lang prop only works on web (React Native Web forwards it to the HTML lang attribute). On native platforms, it's silently ignored by React Native's Pressable.

For iOS, React Native supports accessibilityLanguage — it accepts a BCP 47 language tag (same format as lang) and tells VoiceOver which language to use when reading the element. It's iOS-only; Android's TalkBack doesn't have a documented equivalent prop.

Suggested fix — in BaseListItem.tsx, pass both props so web and iOS are both covered:

lang={item.lang}
accessibilityLanguage={item.lang}

The prop forwarding chain (PressableWithFeedbackGenericPressable → RN Pressable) already spreads ...rest through, so accessibilityLanguage will reach the native Pressable without any plumbing changes. The lang field in the ListItem type can stay as-is since it's already a BCP 47 tag, which is exactly what accessibilityLanguage expects.

Platform coverage after this change:

  • Web:lang → HTML lang attribute (JAWS, NVDA, VoiceOver)
  • iOS:accessibilityLanguage → VoiceOver language hint
  • Android: ❌ No equivalent prop in React Native — TalkBack relies on system-level language detection. This is a React Native limitation, not something this PR can fix.

@rushatgabhane
Copy link
Member

@MelvinBot see what react native web needs? Also is our value passed to the prop correct?

@rushatgabhane
Copy link
Member

@MelvinBot mark ready for review

@MelvinBot
Copy link
Contributor Author

Investigated both questions:

1. What does React Native Web need?

RNW explicitly supports the lang prop — it's whitelisted in the forwardPropsList for View (source):

const forwardPropsList = {
  // ...
  lang: true,
  // ...
};

It does two things with it:

  • Forwards it to the DOM as the HTML lang attribute (via the pickProps filter)
  • Uses it internally to determine text direction — getLocaleDirection(props.lang) sets the dir attribute (RTL vs LTR) and feeds it into the LocaleProvider context

So the current approach of passing lang to PressableWithFeedback works correctly on web. The prop flows through PressableWithFeedbackGenericPressable → RN Pressable → RNW's View → DOM element.

2. Are the values correct?

The values come from CONST.LOCALES in src/CONST/LOCALES.ts. The full set is:

Locale BCP 47 valid?
en
es
de
fr
it
ja
nl
pl
pt-BR
zh-hans ✅ (technically canonical form is zh-Hans, but BCP 47 tags are case-insensitive and browsers/screen readers handle both)

All values are valid BCP 47 language tags. Screen readers (JAWS, NVDA, VoiceOver on macOS) will correctly switch pronunciation based on these tags.

One note on native platforms (from my earlier comment): on iOS, this prop has no effect — iOS needs accessibilityLanguage instead. Adding accessibilityLanguage={item.lang} alongside lang={item.lang} in BaseListItem.tsx would cover iOS VoiceOver as well.

@MelvinBot MelvinBot marked this pull request as ready for review March 9, 2026 13:14
@MelvinBot MelvinBot requested a review from a team as a code owner March 9, 2026 13:14
@MelvinBot
Copy link
Contributor Author

Done — PR is now marked as ready for review.

@melvin-bot melvin-bot bot requested review from ahmedGaber93 and joekaufmanexpensify and removed request for a team March 9, 2026 13:14
@melvin-bot
Copy link

melvin-bot bot commented Mar 9, 2026

@ahmedGaber93 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot bot removed the request for review from a team March 9, 2026 13:14
@rushatgabhane
Copy link
Member

@ahmedGaber93 all yours

@joekaufmanexpensify
Copy link
Contributor

No product review needed

@joekaufmanexpensify joekaufmanexpensify removed their request for review March 9, 2026 18:43
@rushatgabhane rushatgabhane requested review from mkhutornyi and removed request for ahmedGaber93 March 12, 2026 15:21
@rushatgabhane
Copy link
Member

reassigning to @mkhutornyi

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 labels Mar 12, 2026
@rushatgabhane
Copy link
Member

@mkhutornyi feel free to change this please, if something isn't working

@rushatgabhane
Copy link
Member

@MelvinBot please fix native too if not done

The lang prop only works on web (React Native Web forwards it as the
HTML lang attribute). On native iOS, VoiceOver uses the
accessibilityLanguage prop to determine pronunciation language.
This passes the same BCP 47 locale tag to accessibilityLanguage
so iOS VoiceOver announces language options correctly.

Co-authored-by: Rushat Gabhane <rushatgabhane@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner March 13, 2026 02:39
@melvin-bot melvin-bot bot requested a review from dangrous March 13, 2026 02:39
@melvin-bot
Copy link

melvin-bot bot commented Mar 13, 2026

@thesahindia @dangrous One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@MelvinBot
Copy link
Contributor Author

Added accessibilityLanguage={item.lang} to BaseListItem alongside the existing lang prop.

  • lang → works on web (React Native Web forwards it as the HTML lang attribute)
  • accessibilityLanguage → works on iOS (tells VoiceOver which language to use for pronunciation)
  • Android → TalkBack doesn't have an equivalent React Native prop; it relies on automatic language detection

Both props receive the same BCP 47 locale tag (e.g., "de", "ja", "zh-hans"), so no additional data changes were needed.

@MelvinBot
Copy link
Contributor Author

The failing check is unrelated to this PR.

Analysis: The failure is in tests/ui/components/IOURequestStepConfirmationPageTest.tsx with TypeError: Cannot read properties of undefined (reading 'GRANTED') at __mocks__/react-native-permissions.ts:11. This is a module-level initialization error in the react-native-permissions mock where RESULTS imported from react-native-permissions/dist/commonjs/permissions is undefined.

Evidence:

  • This PR only modifies 3 files: BaseListItem.tsx, ListItem/types.ts, and LanguagePage.tsx — all related to adding a lang attribute for screen reader accessibility
  • Both the mock file and the failing test file are identical to what's on main (git diff main shows no changes for either)
  • The same Jest test workflow passes on main (most recent run: 22883635643)
  • This is a flaky/intermittent test failure caused by a transient module resolution issue in CI

@rushatgabhane
Copy link
Member

@MelvinBot merge main

@rushatgabhane rushatgabhane removed the request for review from thesahindia March 13, 2026 03:46
…eScreenReaderLang

Co-authored-by: Rushat Gabhane <rushatgabhane@users.noreply.github.com>
@MelvinBot
Copy link
Contributor Author

Merged main into the PR branch.

@mkhutornyi
Copy link
Contributor

mkhutornyi commented Mar 13, 2026

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari web

Copy link
Contributor

@dangrous dangrous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codewise seems great if it works!

@mkhutornyi
Copy link
Contributor

There's regression on staging so web testing is blocked at the moment. Works fine on production

Not able to select each menu item at all. I tested using VoiceOver.

staging:

reg.mov

production:

prod

@rushatgabhane should we create new issue for this? I can investigate if you'd assign me.

{...bind}
ref={pressableRef}
lang={item.lang}
accessibilityLanguage={item.lang}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot accessibilityLanguage is iOS only prop. https://reactnative.dev/docs/view#accessibilitylanguage-ios
Does this work on android too?

@rushatgabhane
Copy link
Member

@mkhutornyi this bug doesn't occur on Android btw, try it out

And for web regression on staging I don't think we need to wait on it if DOM element looks good

@MelvinBot
Copy link
Contributor Author

No — accessibilityLanguage does not work on Android. It is iOS-only, as you noted.

Current cross-platform coverage

Platform Mechanism Status
Web lang prop → HTML lang attribute ✅ Works
iOS accessibilityLanguage → VoiceOver language ✅ Works
Android ❌ No React Native support

Why Android doesn't work

React Native has no wiring for accessibilityLanguage on Android:

  • BaseViewConfig.android.js omits it from the valid attributes list (while BaseViewConfig.ios.js includes it)
  • Zero Java/Kotlin code in ReactAndroid/ references the prop
  • React Native's own ReactAccessibilityDelegate.java:371 has an explicit // TODO: Eventually support for other languages on talkback

The prop is silently ignored on Android — no crash, no error, just no effect.

What Android offers (outside RN)

  1. LocaleSpan — wraps text with a locale hint for TalkBack, but only works on SpannableString text, not arbitrary View accessibility labels. React Native doesn't support this.
  2. View.setLocaleList() — API 34+ (Android 14+) per-view locale API. React Native doesn't call it. A custom native module could bridge it, but only for newer devices.
  3. Automatic language detection — TalkBack on Android 13+ can auto-detect and switch languages mid-text. Imperfect but requires zero code changes.

Recommendation

The current approach (lang for web + accessibilityLanguage for iOS) is the best we can do within React Native's current APIs. For Android, TalkBack's automatic language detection on Android 13+ partially compensates. A full Android solution would require either an upstream React Native change or a custom native module — both out of scope for this PR.

If you'd like, I can file an upstream issue on facebook/react-native to track Android support, or we can accept the gap for now.

@mkhutornyi
Copy link
Contributor

mkhutornyi commented Mar 13, 2026

@mkhutornyi this bug doesn't occur on Android btw, try it out

And for web regression on staging I don't think we need to wait on it if DOM element looks good

DOM element looks good. Btw the original bug report is from web platform.

iOS works fine.

For android, I am not sure if there's solution to support all devices. Should we not block on this?
And as Melvin said, not supported in RN android.
In my old phone (android 12, Samsung Galaxy S10+), TalkBack doesn't support Chinese and Japanese.

Copy link
Contributor

@mkhutornyi mkhutornyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melvin-bot melvin-bot bot requested a review from dangrous March 13, 2026 17:10
@rushatgabhane
Copy link
Member

@dangrous all yours! 🙇

@rushatgabhane
Copy link
Member

rushatgabhane commented Mar 16, 2026

For android, I am not sure if there's solution to support all devices

yep it works on modern android versions. so i don't think we should block on this.

@dangrous dangrous merged commit d10004a into main Mar 16, 2026
37 of 38 checks passed
@dangrous dangrous deleted the claude-fixLanguagePageScreenReaderLang branch March 16, 2026 21:03
@github-actions
Copy link
Contributor

🚧 @dangrous has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/dangrous in version: 9.3.39-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/cristipaval in version: 9.3.39-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewing Has a PR in review Weekly KSv2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants