Skip to content

fix(i18n): fix locale detection for regional variants on React Native#17037

Open
Beautiful-blue-sky wants to merge 1 commit intojitsi:masterfrom
Beautiful-blue-sky:fix/i18n-native-locale-detection
Open

fix(i18n): fix locale detection for regional variants on React Native#17037
Beautiful-blue-sky wants to merge 1 commit intojitsi:masterfrom
Beautiful-blue-sky:fix/i18n-native-locale-detection

Conversation

@Beautiful-blue-sky
Copy link

Summary

Fix locale detection for regional language variants on React Native (Android & iOS).

Problem

The detect() function in languageDetector.native.ts was building locale strings by directly concatenating language and region codes without a separator. This produced invalid keys like zhCN instead of zh-CN, which never matched any entry in languages.json, causing the app to fall back to English — even when the system language was correctly set.

Affected locales: zh-CN, zh-TW, fr-CA, pt-BR, es-US, and any other regional variants.

Root cause introduced in commit 9be78c6 and carried over in 35c7f15.

Fix

Insert - separator when constructing the locale string:

System locale Before After
zh-CN (Android) zhCN zh-CN
zh-Hans-CN (iOS) zhCN zh-CN
pt-BR ptBR pt-BR
fr-CA frCA fr-CA

Testing

Verified on Android emulator (API 36, locale zh-Hans-CN):

  • Before fix: Settings showed Language: zh (invalid fallback), UI displayed in English
  • After fix: Settings showed Language: 中文(简体), UI displayed in Simplified Chinese

Also verified on physical Android device with Simplified Chinese system language.

The locale detection logic was concatenating language and region codes
without a separator, producing invalid keys like 'zhCN' instead of
'zh-CN'. This caused all regional language variants (zh-CN, zh-TW,
fr-CA, pt-BR, es-US) to fail matching against the languages list, and
fall back to English.

Fix by inserting the '-' separator when constructing the locale string:
- 2-part locale: 'zh' + '-' + 'CN' -> 'zh-CN' (Android)
- 3-part locale: 'zh' + '-' + 'CN' (skipping 'Hans' script) -> 'zh-CN' (iOS)

Fixes language detection for all regional language variants on both
Android and iOS.
Copilot AI review requested due to automatic review settings February 27, 2026 08:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes React Native locale detection so regional variants match languages.json keys (e.g., zh-CN, pt-BR) instead of incorrectly concatenated strings (e.g., zhCN) that caused unintended fallback to English.

Changes:

  • Construct BCP-47 style locale strings with a - separator for both lang-region and lang-script-region inputs.
  • Add clarifying inline examples for iOS (zh-Hans-CN) and Android (zh-CN) locale formats.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jitsi-jenkins
Copy link

Hi, thanks for your contribution!
If you haven't already done so, could you please make sure you sign our CLA (https://jitsi.org/icla for individuals and https://jitsi.org/ccla for corporations)? We would unfortunately be unable to merge your patch unless we have that piece :(.

@Beautiful-blue-sky
Copy link
Author

Hi, thanks for your contribution! If you haven't already done so, could you please make sure you sign our CLA (https://jitsi.org/icla for individuals and https://jitsi.org/ccla for corporations)? We would unfortunately be unable to merge your patch unless we have that piece :(.

Thank you! I have signed the Individual CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants