fix(ios): localize plural counts without Intl.PluralRules (Hermes gap) - #113
Merged
Conversation
Hermes (React Native's JS engine) ships without `Intl.PluralRules`, and
i18next's plural resolver depends on it — so on device every plural key fell
back to English ("1 app installed" instead of "已安装 1 个应用") while
non-plural keys localized fine. Web has `Intl.PluralRules`, so it never showed
there. Found via iPhone 17 simulator testing; diagnostic confirmed
`Intl.PluralRules === undefined` on Hermes.
The standard `@formatjs/intl-pluralrules` polyfill can't install here — Hermes
declares `Intl.PluralRules` as a non-configurable stub, so the polyfill's
`defineProperty` throws ("property is not writable"). Instead add a tiny
`tCount(baseKey, count)` helper that selects the English one/other form
manually (no Intl) and uses the single "other" form for the other locales; the
strings interpolate `{{n}}` so i18next's own plural machinery never triggers.
Routed the four plural call sites through it: apps installed count, search
result count, search "looking across N objects", and the record-list count.
Verified on device: "已安装 1 个应用" now renders. e2e (33) + unit (1298) pass.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found via iOS Simulator testing
On device the Apps screen showed "1 app installed" (English) while everything else was Chinese. Diagnostic on the iPhone 17 sim confirmed the cause:
Hermes (React Native's JS engine) ships without
Intl.PluralRules, and i18next v25's plural resolver depends on it — so every plural key (apps.installed,search.resultCount,search.lookingAcross,records.recordCount) falls back to the fallback language (en) on device, while non-plural keys localize fine. Web hasIntl.PluralRules, which is why it never reproduced there.Why not the polyfill
@formatjs/intl-pluralrulescan't install here: Hermes declaresIntl.PluralRulesas a non-configurable stub, so the polyfill'sdefineProperty(Intl, "PluralRules", …)throws "property is not writable" (also crashed the app). i18next v25 always usesIntl.PluralRulesregardless ofcompatibilityJSONv3/v4, so switching that flag doesn't help either.Fix
A tiny
tCount(baseKey, count)helper inlib/i18n.tsthat:_one/_otherform manually (noIntl),_otherform for the other locales,{{n}}(renamed from{{count}}) so i18next's own plural machinery never triggers.Routed the 4 plural call sites through it. No new dependency.
Verified
On the iPhone 17 simulator the Apps screen now renders "已安装 1 个应用". e2e (33) + unit (1298) pass, tsc + lint clean.
🤖 Generated with Claude Code