fix(i18n): fix locale detection for regional variants on React Native#17037
fix(i18n): fix locale detection for regional variants on React Native#17037Beautiful-blue-sky wants to merge 1 commit intojitsi:masterfrom
Conversation
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.
There was a problem hiding this comment.
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 bothlang-regionandlang-script-regioninputs. - 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.
|
Hi, thanks for your contribution! |
Thank you! I have signed the Individual CLA. |
Summary
Fix locale detection for regional language variants on React Native (Android & iOS).
Problem
The
detect()function inlanguageDetector.native.tswas building locale strings by directly concatenating language and region codes without a separator. This produced invalid keys likezhCNinstead ofzh-CN, which never matched any entry inlanguages.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:zh-CN(Android)zhCN❌zh-CN✅zh-Hans-CN(iOS)zhCN❌zh-CN✅pt-BRptBR❌pt-BR✅fr-CAfrCA❌fr-CA✅Testing
Verified on Android emulator (API 36, locale
zh-Hans-CN):Language: zh(invalid fallback), UI displayed in EnglishLanguage: 中文(简体), UI displayed in Simplified ChineseAlso verified on physical Android device with Simplified Chinese system language.