Repository navigation
feat(i18n): add Simplified Chinese (zh-CN) - #1664
Conversation
Adds a complete `zh-CN` message bundle and wires the locale into the
configuration, formatter map and Telegram bare-word aliases.
- `messages/zh-CN.json`: all 13,019 keys, key-for-key with `en.json`.
Placeholders, ICU plural blocks and escaped HTML in the Telegram copy are
preserved verbatim; every `{count, plural, …}` uses the single `other`
branch that CLDR asks for in Chinese.
- `locales`: `zh-CN` appended to the shipped list (`config.ts` and
`project.inlang/settings.json`), so the language picker and the boot
script pick it up without further edits.
- `localeLanguageNames["zh-CN"]` is the English name "Simplified Chinese"
(model-facing directives have to be written in the prompt's own language);
`localeLabels["zh-CN"]` is the endonym 简体中文 for the picker.
- `localeFromLanguageTag`: an explicit alias table maps `zh`, `zh-Hans` and
`zh-SG` to this bundle, and `NON_GENERIC_PRIMARY` keeps the generic
primary-subtag fallback away from `zh`, so `zh-TW` and `zh-HK` keep
reading English rather than being handed a Simplified bundle with
mainland terminology.
- `INTL_LOCALE_MAP["zh-CN"] = "zh-CN"` so numbers, dates and times render
through the reader's own locale instead of falling back to `en-US`.
- Telegram bare words: 帮助 / 帮忙 / 求助 and 你好 / 您好 / 嗨.
The bundle is machine-translated, so `zh-CN` stays out of
`MAINTAINED_LOCALES` and the existing maintainership banner shows on the
auth shell until a native speaker has reviewed it.
Kept in English on purpose: brand and product names (Withings, WHOOP, Oura,
Fitbit, Polar, Garmin, Strava, Nightscout, Apple Health, Google Health,
Health Connect, Telegram), unit and format strings (`mmHg`, `mg/dL`,
`kg/m²`, `mL/(kg·min)`, `VO₂ max`), the sample address and the URL/UUID
placeholders. Questionnaire item wording stays English until a native
clinical review, which is what the existing `mentalHealth.wording.*`
strings already disclose in-app.
Adding `zh-CN` to `locales` makes every `Record<Locale, …>` incomplete, which
is the type checker doing its job: each of those maps decides something a
reader sees. This fills all of them, and every place where Chinese cannot be
filled in honestly yet reuses English on purpose.
Real Chinese content:
- `outbound-screen/locales/zh-cn.ts`: the safety bank, written for Chinese
rather than translated. `\b` is an ASCII word boundary and a Han character
is not `\w`, so every edge is spelled out; Chinese usually puts the change
verb before its target ("加到 2000 mg") and attaches the dosage counter to
the digit with no space ("2片"), so both orders are covered. 36 patterns:
dose changes, seven risk shapes, nine causal connectives, a maintenance
anchor and its change stem. Verified against the guard's own expectations —
every pattern matches a real Chinese sentence, no pattern puts `\b` beside a
Han character, all eight withhold shapes block and none of the three
harmless shapes does.
- `coach/population-norms/zh-cn.ts`: the population-norm framing patterns
("正常范围是", "多数人", "普通人群", "指南推荐").
- `citation-coverage.ts`: the normative vocabulary a claim is checked for
("目标", "应当", "正常范围", "高于", "低于").
- `parse-reference-range.ts`: the reference-range prose Chinese lab sheets
print ("至", "低于", "不超过", "不低于", "参考范围").
- `coach/system-prompt.ts` and `prompts/insights-reply-footers.ts`: zh-CN is
not a `NativeCoachLocale` (no safety-contract matrix), so it takes the
same English body plus reply footer that ko, nl, pt-BR and ru take, with a
footer that asks for Simplified Chinese and 你.
- `support/redact.ts`: `cn` and `sg` join `HOST_TLDS`, so a Chinese host in a
support report is recognised as a host at all.
Deliberately English until a native speaker has reviewed the wording:
`mental-health/wording/index.ts` (questionnaire items),
`ai/safety/outbound-screen.ts` is NOT one of them — its bank is Chinese — but
`medications/medicine-registry-default.ts` maps to an empty list because none
of the registries in that table covers mainland China.
Test fixtures gain `zh-CN` rows throughout: the safety tables (dose, risk,
causal, withhold shapes, named medications), the liveness sentence lists, the
language-name and prompt-body contract tables, the morning-copy blocklist, the
citations sentences, and the host-TLD regions.
`tsc --noEmit` reports no error.
The typography guard bans U+2192 outright: a menu path is written `Settings > Account`, not with an arrow, because the arrow reads as a transformation rather than a location. Nine occurrences slipped into the calendar-subscription help and the next-day shortcut, which the guard catches on CI and which this fixes here: - `cycle.feed.help.google`, `.apple`, `.outlook`: `→` becomes `>`. - `day.nextDayShortcut`: `Alt + →` becomes `Alt + 右方向键`, since there the arrow names a key rather than a path. Verified with the guard's own algorithm over all 13,019 strings: no U+2192, no `...`/`….`, no spaced middle dot or dash, no en dash outside a range, and every English plural block carried over with an `other` branch.
`LOCALE_LANGUAGE` is the map that decides which traineddata a document scan is read with, so adding the locale without an entry made the branch fail to typecheck on its own. Chinese now points at `eng`: the reader falls back to what every build carries, which is what a build without the Chinese pack did before this branch existed. The chi_sim pack and the one-line swap to it are a separate change, because staging it adds a multi-megabyte traineddata to the image.
The unreleased section documents every user-visible addition, and a new language is the most visible one there is. Both entries sit under `[Unreleased]`: `Added` for the language, `Changed` for the OCR language list that the existing entry already describes as "the account's own language". Both say what the bundle is not: machine-translated and not yet reviewed, so it stays out of the maintained set and the questionnaire item wording stays English.
…hinese Running the guard suite against the new bundle found eleven failures, and eight of them were the bundle's fault rather than the guard's. The bundle: - One word per dose state. `medications.phaseGreen` said 待服 (the pending state) where the phase announces the due state, `phaseYellow` did not contain 到期 at all, and the three reminder titles used a fourth wording. Every missed state now reads 漏服 — `doctorReport.colMissed`, the Telegram help, the confirm button — instead of 漏服 and 遗漏 side by side, which is exactly the drift this guard was written for. - A prohibition of the *omission* is not a hold. "不要漏服你的雷米普利" is the opposite advice to "今晚不要服用阿托伐他汀", and the negated shape now refuses to read 漏, 跳 or 忘 as its verb. - The causal bank lists 因为, 由于, 因此, 于是 and 之所以 on their own, the way the English bank lists `because`. - The population-norm bank accepts 健康成年人, not only 健康人. - The false-positive corpus carries seventeen harmless replies rather than three: a question, a reading, a medication fact, a habit, a clinician deferral — the shapes a real reply takes. Three rules were written for languages that put spaces between words, and a Chinese sentence cannot satisfy them: - `detectsNormativeClaim` required "not preceded by a letter" before a keyword. 应当 is always preceded by a Han character, so the whole Chinese keyword bank matched nothing. `NO_WORD_BOUNDARY_LOCALES` builds the alternation without that edge for Chinese, where a multi-character keyword is specific enough on its own. - `i18n-dose-vocabulary` required the dose participle at the start of a word. Chinese has no word spaces, so the same set makes it match the stem anywhere. - `targetLanguageName` is a second switch next to `localeLanguageNames` and returned "English" for zh-CN, which the assessment prompt then asked for. Verified: 19 test files, 1843 cases, 0 failures; `tsc --noEmit` clean. The local vitest config that made this runnable on Windows is not committed.
Landing the bundle made four guards discover work they could not see before.
The glossary (`src/lib/i18n/glossary.json`) is the project's one source of
terminology: 177 concepts, each with anchors into the bundle, and the guard
holds the two together. The Chinese column is **derived from the bundle**
rather than transcribed — for every concept the anchor key's zh-CN value *is*
the term, so the glossary and the bundle cannot drift by construction. The
seven concepts that carry only `contains` anchors needed a word chosen by
hand (剂量, 服药, 症状, 监护人, 分享链接, 数据来源, 体检提醒), and the short
forms come from each concept's short key, dropped entirely where the short form
is the same word as the name.
That surfaced two real inconsistencies in the bundle, both fixed here:
- `nav.seizures` said 发作日记 while the page title and the module label said
癫痫日记.
- Three event metrics kept the notification word in their full name and lost it
in the short form (高心率通知 / 高心率). Now 高心率事件通知 / 高心率提醒, the
same shape English uses ("High heart rate notification" / "High heart rate
alert"), and 高血压/低心率 likewise.
`normaliseLabKey` kept `[a-z0-9]` plus Cyrillic and Hangul, so every Chinese
analyte name folded to the empty string and no LOINC code resolved for a
zh-CN account — the same failure the comment there already records for Korean.
Han ideographs join the kept ranges, and `resolveLabCoding('总胆固醇')` now
answers 2093-3 like every other locale's name does.
Test fixtures gain their zh-CN rows: the two screen tests (a dose change and a
causal claim to withhold, one clean sentence to pass through), the ten-locale
lists become eleven, the surface-registry guard imports the new bundle, and the
source-size baseline records `insight-generator.ts` at 1116 lines.
Verified with the real suite: glossary 114/114, the two screen tests 64/64,
lab-loinc 39/39, source-size-ratchet 7/7.
The language-list guard asserts that every app locale reads with deu + eng + its own pack. zh-CN is the one locale whose pack the image does not carry on this branch: it maps to `eng` so the bundle can land on its own, which leaves it reading with two languages. This records that exception by name and says where it goes back to three, so the OCR change that stages `chi_sim` has one line to flip.
Four guards pinned the shipped-locale count at ten, and the AUDIT-C instrument carries a standard-drink sentence per language: adding zh-CN made five tests discover gaps the branch had not filled. - clinician-view-locales, context-vocabulary, irst-result-config: ten becomes eleven, and the clinician-view case names the count once instead of asserting it twice. - AUDIT_C_STANDARD_DRINK gains the Chinese sentence. It states the WHO definition the other languages state — 10 g of pure alcohol, with the beer, wine and spirits equivalents — because that sentence is what the drinker counts their drinks against. Verified: those five files 94/94, and the 76 test files that iterate locales run 4,259 cases with only the two Windows-only pre-existing failures left (manage-activity-inventory, dashboard-hrv-rmssd-fallback, both failing on the baseline branch as well).
Bring the bundle level with release: drop the 50 retired keys, word the 81 new ones and re-word the 17 whose English changed. The glossary takes release's score short forms and gains their Chinese short names.
…ice accepts The signing service refuses a manifest with an .lproj it does not list, for every account. With zh-CN in the app's locales every pass carried zh-CN.lproj and every signing failed. The pass now carries the languages the manifest rules list; a Chinese reader sees the pass in English until the service accepts the language.
The generator kept its own list of locales and wrote no zh-CN catalog, so the layout loaded a file that did not exist. It now reads the locales from the inlang project, which a test already holds equal to the config, and so does the key tool. A test runs the generator and checks every locale's file.
The report fonts covered Latin and Hangul, so a Chinese report drew every string as a box. ReportSansSC adds the GB2312 characters, CJK punctuation and the fullwidth forms from Noto Sans SC, and is loaded only for a Chinese report or Han text in the data. A test checks that every doctorReport string of every locale has a glyph in the font that locale's report is drawn in.
Every language but English and Russian was read with a decimal comma, so 5.4 in a Chinese reply became 54 and a correct figure was flagged as invented.
…slation template Regenerate the OpenAPI document for the new locale value, give the date picker its Chinese month and weekday names, offer zh-CN in the translation issue form, and describe the PDF font and the Wallet fallback in the changelog.
|
Thank you, @Remedy233. This is careful work. The safety bank written for Chinese word order, the alias table that keeps The branch had fallen 200 commits behind
One thing from #1528 is still open, and it's yours if you'd like it: the typography guard. I asked for the list in the description and it isn't there yet. The rule that matters most is no space between a number and its measure word. Right now about a thousand values write The full-width fold (#1655) is still open on its own and doesn't block this one. I'll merge this once the checks are green. Thanks again. |
Read the bundles through an import instead of the file system, check the boot catalogs by size, and fold the decimal-point rule into one set so the grounding file stays at its baseline.
|
Thank you — both for the merge and for reading the bundle closely enough to fix what the release had moved underneath it. Your Chinese: I read all 98. The short forms for the six scores (健康, 准备度, 睡眠评分, 恢复, 压力, 负荷), 测量(CSV)/ 用药(CSV)/ 心情(CSV), JSON 文件, Health Connect, Gadgetbridge, 医生报告 and the
Everything else I agree with, including The wallet-pass finding is the one I should have caught. A #1670 is now redundant with your own work. You added The typography guard is mine, and it will be there before Wednesday evening. I have already sized it against your branch:
So the PR is one new zh-CN-scoped test beside |
|
The typography guard you asked for is up, in the branch that will retarget to Against your merged state it found:
By measure word: 天 237, 个 97, 条 80, 次 74, 小时 56, 分钟 35, 周 20, 份 19, 月 13, 年 12, 步 9, 岁 7, 秒 4, 片 1. Three of the shapes had to handle a count arriving as a placeholder, as an ICU plural body's
One thing moved with the bundle: the Also: #1670 is closed as superseded by your own PDF work in this PR — thank you for taking it on. And the two Chinese strings I would change back are in my previous comment: |
|
@Remedy233 thank you for reading all of it, and for the guard. Your three points:
Closing #1670 makes sense, thank you for keeping the timeline clean. And 1190 findings with Latin units protected is great. I'll review Remedy233#3 as soon as it's pointed at the release branch. Refs #1528 |
|
One thing your merge made visible, and it is not mine to guess at:
I have translated those 52 and opened them on their own so they do not muddy the typography change: #1676, one commit on So the follow-ups are:
All four are single commits on Also: #1670 is closed — your |
|
@Remedy233 good catch, and thank you for getting there first. Two pieces landed side by side and the plural guard caught the gap, which is what it's there for. Your #1676 goes in first, since your Chinese beats ours, and a small follow-up then removes the 32 stray keys and fills in the few strings that arrived after your sync. After that the release branch should be green again. I'll go through #1673, #1674 and #1675 next. Splitting them by concern makes them very easy to review, thank you for that. Refs #1528 |
|
All three follow-ups are in They ship with the next release, which will most likely come out next Saturday. |
What this does
Adds a complete Simplified Chinese bundle — 13,019 keys, key-for-key with
en.json— and wireszh-CNinto the configuration.The bundle
messages/zh-CN.json. Placeholders, ICU plural blocks and the escaped HTML inthe Telegram copy are preserved verbatim. Every
{count, plural, …}uses thesingle
otherbranch that CLDR asks for in Chinese; nothing was invented.Kept in English on purpose, and why: brand and product names (Withings, WHOOP,
Oura, Fitbit, Polar, Garmin, Strava, Nightscout, Apple Health, Google Health,
Health Connect, Telegram), unit and format strings (
mmHg,mg/dL,kg/m²,mL/(kg·min),VO₂ max), the sample address, and the URL/UUID placeholders.A computed check with the leak guard's own algorithm found one multi-word
value that needed an explicit allowlist entry (
settings.chatIdis "Chat ID"in Chinese Telegram clients too).
The wiring
Adding
zh-CNtolocalesmakes everyRecord<Locale, …>incomplete, whichis the type checker doing its job. Each of those maps decides something a
reader sees. Where Chinese content is real, it is Chinese:
outbound-screen/locales/zh-cn.ts— the safety bank, written for Chineserather than translated.
\bis an ASCII word boundary and a Han character isnot
\w, so every edge is spelled out. Chinese usually puts the change verbbefore its target (
加到 2000 mg) and attaches the dosage counter to thedigit with no space (
2片), so both orders are covered. 36 patterns.coach/population-norms/zh-cn.ts— population-norm framing (正常范围是,多数人,普通人群,指南推荐).citation-coverage.ts— normative vocabulary (目标,应当,正常范围,高于,低于).parse-reference-range.ts— reference-range prose (至,低于,不超过,不低于,参考范围).coach/system-prompt.ts+prompts/insights-reply-footers.ts— zh-CN is nota
NativeCoachLocale(it has no safety-contract matrix), so it takes thesame English body plus reply footer as ko, nl, pt-BR and ru, with a footer
asking for Simplified Chinese and 你.
support/redact.ts—cnandsgjoinHOST_TLDS, so a Chinese host in asupport report is recognised as a host at all.
Where Chinese wording cannot be honest yet, it reuses English and says so in
the code: questionnaire items (
mental-health/wording/index.ts) stay Englishuntil a native speaker has reviewed them clinically, which is what the in-app
mentalHealth.wording.*disclosure already tells the reader. The Chinesereaders of
zh-TWandzh-HKdeliberately keep reading English rather thanbeing handed a Simplified bundle with mainland terminology.
Tag routing
localeFromLanguageTaggains an alias table:zh,zh-Hansandzh-SGmap tothis bundle, and
NON_GENERIC_PRIMARYkeeps the generic primary-subtagfallback away from
zh, sozh-TWandzh-HKdo not silently land on it.Machine-translated, and marked as such
zh-CNstays out ofMAINTAINED_LOCALES, so the existing maintainershipbanner shows on the auth shell. That is accurate: this bundle has not had a
native-speaker review, which this project asks for before a translation is
treated as final. I am happy to work through review comments.
Checks
tsc --noEmit: 0 errors across the repo (45 files touched: 1 new bundle,10 source maps, 29 test fixtures, 2 host-TLD tables)
strings:
findings=0for ellipsis, dot-separator, typography glyphs, keyparity, and the plural guard
no
\bbeside a Han character, all eight withhold shapes block, none of thethree harmless shapes does
vitestcould not run on this machine (its config collects files withfs.globSync, which returns backslash paths on Windows, so no file matchesthe
includepatterns). CI on Linux is the real gate for the test suite;the two harnesses above cover the assertions that matter for this bundle.
Depends on
Nothing. Optional follow-ups stack on top of it: the leak guard entry and the
chi_simOCR pack.