fix: [SDK-5202] canonicalize Chinese locales and make setLanguage("") use device default - #1746
Conversation
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
There was a problem hiding this comment.
Multi-model review (Opus 5, GPT 5.6 Sol, Grok 4.6)
Substantive diff +329/−34 = 363 across 11 source/test/demo/docs files (nothing generated, lock, vendor, or snapshot). The IAM candidate walk and Chinese script/region mapping look directionally right, and dropping substringToIndex:2 removes a real crash on short tags. One production crash remains.
Act on
containsObject:on a nil region (Grok):languageVariantCandidatesForLanguage:treats bare"zh"(no script, no region) as!scriptCode && [@["HK",@"MO",@"TW"] containsObject:regionCode].NSArray containsObject:raisesNSInvalidArgumentExceptionon nil. Reachable viasetLanguage("zh")and a hydrated server"zh". Device init never emits"zh", and the IAM tests never use it, so the suite stays green.
Consider
- Dropped
zhcandidate (Opus): the old matcher always used the first two characters, so a dashboardzhvariant still matched. The new Chinese path never adds"zh". Appending it last is cheap insurance. - Demo override vs fetch hydration (Sol+Grok):
restoreLanguageOverride()runs immediately afterlogin. Existing switch-user tests show fetch hydration then overwriteslanguagewithremote_language, so the selector and IAM can diverge. - Device language now stores the base code (Opus): new users get
eninstead ofen-US. Cached installs keep the old tag. Call this out if intentional. setLanguage("zh-CN")is not normalized (Opus): IAM still matches via the ObjC path; the stored/backend property stayszh-CN.
Noted / dismissed
- Dual Swift/ObjC normalizers diverge on exotic scripts (
zh-Latn-TW). languageis no longer nil when_useris missing.yue/wuustay unmapped — outside this ticket’szh-Hans/zh-Hantscope.setLanguage("")snapshots the device language once; it does not track later system changes.
Sent by Cursor Automation: PR Reviews
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
nan-li
left a comment
There was a problem hiding this comment.
Approving.
One small thing, fine to do later. The code that turns a Chinese locale into zh-Hans or zh-Hant now exists in two places, OSLanguageProviderDevice and languageVariantCandidatesForLanguage:. They give the same answers today, but two copies will not stay in sync. Put it in one function that both can call.
|
Done. Chinese locale canonicalization now lives only in |
fa99f72 to
dfe2f1f
Compare
Co-authored-by: Cursor <[email protected]>
dfe2f1f to
61b5c0c
Compare


Description
One Line Summary
Fix IAM variant matching for Simplified and Traditional Chinese language tags.
Details
Motivation
The SDK truncated language tags to two characters, causing
zh-Hansandzh-HantIAMs to miss their configured variants and fall back to the default variant.Scope
zh-Hans-CN,zh-Hant-TW,zh-CN, andzh-TW.zh-Hansorzh-Hant.setLanguagevalue as restoring the device language.Testing
Unit testing
Manual testing
Not run on a physical device; covered by focused simulator tests and the demo Release build.
Affected code checklist
Checklist
Overview
Testing
Final pass