Repository navigation
fix(i18n): server t() fills {{ name }} holes written with spaces, as the Console does - #38265
Conversation
…the Console does FileI18nAdapter.t() and createMemoryI18n().t() now accept whitespace inside the braces, matching the Console's i18next; a hole with no value is written back exactly as authored. Claude-Session: https://claude.ai/code/session_01L9qibxWAZYhFuv668TruUa Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 41 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin eb3cbf3317960b1e91cc180aa82c454bb98aff12 && git checkout eb3cbf3317960b1e91cc180aa82c454bb98aff12
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 73ec085afa2f9689ef96263a9c25b82cde6fda47 f447517c5b7c8c8e229781c9a9a73498d02eccd1 && git checkout -B drift-repro 73ec085afa2f9689ef96263a9c25b82cde6fda47 && git merge --no-ff f447517c5b7c8c8e229781c9a9a73498d02eccd1
node scripts/docs-audit/affected-docs.mjs --json 73ec085afa2f9689ef96263a9c25b82cde6fda47
|
|
repo:objectstack#3 · os-tesla · session_01L9qibwSEecrzDjKjbk24r1 Contract reviewServed-tier: Why TIER_DEFAULT: the review is owed by the ① Derived judgments
② Semver levelRight. ③ Boundary flags
No must-fix, no should-fix. Implemented-by: VERDICT: PASS |
|
repo:objectstack#3 · os-tesla · session_01L9qibwSEecrzDjKjbk24r1 L1-a ACCEPT at
|
|
repo:objectstack#3 · os-tesla · session_01L9qibwSEecrzDjKjbk24r1 Contract reviewServed-tier: A mechanical delta from record 7238665113 (TIER_DEFAULT PASS at ① Derived judgments
② Semver levelUnchanged and right: ③ Boundary flags
No must-fix, no should-fix. Implemented-by: VERDICT: PASS |
|
repo:objectstack#3 · os-tesla · session_01L9qibwSEecrzDjKjbk24r1 L1-a delta: ACCEPT at
|
|
repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU Landing · 2026-11-28T12:17Z · zone
|
…l }} holes written with spaces, as the Console does (objectstack-ai#38275) <!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoJ9d2Ay3ahgdHpDaETT43do)_ Fixes objectstack-ai#38266 repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU Clause-②: yes (widening) Metadata-protocol: semantic Skills-docs: none — skills/objectstack-i18n already teaches the double-brace {{variable}} form; the spaced form is tolerated to match the Console and the server t(), not a new form to teach ## 维护者速读 - 部署方在翻译里覆盖校验报错或操作报错(导入失败、重复记录等)时,占位符写成花括号内带空格的形式,服务端返回的报错现在会填上值;以前用户直接看到花括号。 - 替写翻译的搭建者解决:同一句翻译在控制台正常,在服务端报错里露出花括号;与服务端翻译替换修复(同族的另一张卡)用同一条规则。 - 只改报错文案的填值规则,平台自带的报错文案一字不变;出问题最多是某句覆盖报错填值不对,可以直接撤回。 - 无 ## What changes - `packages/spec/src/system/validation-message.ts`: `interpolateValidationMessage` matches `{{`, optional whitespace, a word, optional whitespace, `}}` (`/\{\{\s*(\w+)\s*\}\}/g`, the same pattern as the two server `t()` in objectstack-ai#38265). A placeholder with no value is still written back exactly as matched, spaces included; single braces (`{name}`) are still not a placeholder. The function docblock and the module's `## Interpolation` section say so. - `packages/spec/src/system/operation-message.ts`: docblock only; it shares the interpolator. - Both renderers' override paths (`renderValidationMessage`, `renderOperationMessage`) and built-in paths go through this one function, so both catalogs change together. - Changeset: `@objectstack/spec` minor (`Metadata-protocol: semantic`: in a deployment's override translation, `{{ label }}` now means a placeholder instead of literal text). Not changed: core and service-i18n (objectstack-ai#38265), ui, locale packs, HotCRM, skills. Signature unchanged, so `api-surface` / `export-origins` do not move. ## Tests - `validation-message.test.ts`: the five spellings on `interpolateValidationMessage` and on the `renderValidationMessage` override path, plus `{{ label }} is needed` rendering `Qty is needed`. - `operation-message.test.ts`: `{{ field }} taken` rendering `Email taken` on the `renderOperationMessage` override path, plus the five spellings. - `validation-message.override-once.test.ts`: the fake translator follows the same `\s*` pattern (it models `FileI18nAdapter.t`), and a new case pins that a written VALUE containing `{{ label }}` is still printed as written (one pass, no re-expansion). Five spellings through each renderer's override path (params `{ name: 'Ada' }`; Console column measured with i18next 26.4.0 on the objectstack-ai#38092 card): | Template | Console | main c06dac7, both renderers | this PR, both renderers | |:--|:--|:--|:--| | `Hi {{name}}!` | `Hi Ada!` | `Hi Ada!` | `Hi Ada!` | | `Hi {{ name }}!` | `Hi Ada!` | `Hi {{ name }}!` | `Hi Ada!` | | tab and two spaces | `Hi Ada!` | as written | `Hi Ada!` | | `Hi {name}!` | `Hi {name}!` | `Hi {name}!` | `Hi {name}!` | | `Hi {{ missing }}!` | `Hi {{ missing }}!` | `Hi {{ missing }}!` | `Hi {{ missing }}!` | ## Acceptance notes - Premise measured on `origin/main` `c06dac7c` before any edit: a `validation.field.required` override `{{ label }} is needed` rendered as written, and an `errors.duplicate_record_field` override `{{ field }} taken` rendered as written. - Built-in catalogs byte-for-byte unchanged: every key of every locale in `BUILTIN_VALIDATION_MESSAGES` and `BUILTIN_OPERATION_MESSAGES`, rendered once with every placeholder filled and once with none, 1176 lines, sha256 `0ac2410a…68657ca` before and after (`cmp` identical). No built-in template carries a spaced hole. - Every caller of `interpolateValidationMessage` is inside `packages/spec` (the two renderers); other packages call only the renderers. - One widening, nothing narrowed: every string that rendered before renders the same, except that a spaced hole with a value is now filled. - Pre-existing gap, left as is on both sides: the Console's i18next also fills dotted paths (`{{a.b}}`) and format suffixes (`{{x, number}}`), which this interpolator and the two server `t()` in objectstack-ai#38265 still read as literal text (the name stays `\w+`); per the seat's ruling on the objectstack-ai#38265 contract review (7238665113), neither card widens it, so all three server interpolators handle it the same way. ## Verification - Two-minute check: `pnpm --filter @objectstack/spec exec vitest run src/system/validation-message.test.ts src/system/operation-message.test.ts src/system/validation-message.override-once.test.ts` shows 3 files, 163 passed. - Read first: `interpolateValidationMessage` in `validation-message.ts` (the one changed line), then the new spaced-value case in `validation-message.override-once.test.ts`. <details><summary>Local readings at 89321cb</summary> - The three suites above: Test Files 3 passed, Tests 163 passed. - Ablation through `scripts/ablation-replace.mjs` (pattern reverted to `/\{\{(\w+)\}\}/g`, tests run on `src`, no dist in the path): 8 failed (spaced and tab spellings on both renderers and on the function, and `Qty is needed`), 155 passed; restore blob `965a5ad4` == HEAD. The new spaced-value case in `override-once` stays green under the ablation by design: it pins one pass, which holds with either pattern. - `overlap-check.mjs` VERDICT clean exit 0 against origin/main e2a0e90 (shares two files with objectstack-ai#38185, merges cleanly). - `pnpm --filter @objectstack/spec build` (dts on), `typecheck`: VERDICT command-exit 0; `pnpm --filter @objectstack/spec test`: Test Files 911 passed (911), Tests 28869 passed, 1 todo. - `dispatch-gates --ran` (`gates-ran-89321cb5.list`): 87 derived, 87 run, 0 NOT MEASURED, 0 unrun. Three first exited 3 for a missing build (`check:doc-formula-expressions`, `check:dual-build-cjs-loads`, `check:lean-entry-closure`) and exited 0 after the packages turbo build. - PR check-runs on 89321cb: 58 success, 11 skipped, 0 failed. Report: objectstack-ai#38266 comment 7238709250. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibwBjX6kCcDLzx2jrwn)_ <!-- signed: repo:objectstack#3 · os-tesla · session_01L9qibwBjX6kCcDLzx2jrwn --> Co-authored-by: Claude <noreply@anthropic.com>
Requested by Tesla · project thread
Fixes #38092
repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU
Clause-②: yes (widening)
Metadata-protocol: semantic
Skills-docs: none — skills/objectstack-i18n already teaches the {{variable}} form; the spaced form is tolerated to match the Console, not a new form to teach
维护者速读
What changes
packages/services/service-i18n/src/file-i18n-adapter.ts:interpolatematches{{, optional whitespace, a word, optional whitespace,}}, so{{ name }}and tab-spaced holes are filled like{{name}}. A hole with no value is written back exactly as matched ({{ missing }}), where the old code re-spelled it as{{missing}}. Docblocks say so.packages/core/src/fallbacks/memory-i18n.ts: the in-memory fallbackt()gets the same pattern and the same write-back.{name}) are still not a placeholder on either side.@objectstack/core,@objectstack/service-i18nminor (Metadata-protocol: semantic: on the server a translation string's{{ name }}now means a placeholder instead of literal text).Not changed:
packages/spec(the validation / operation message override interpolator has the same gap; the seat files it as its own card), ui, locale packs, HotCRM, skills.Tests
packages/services/service-i18n/src/file-i18n-adapter.test.ts, a new top-leveldescribe: the same bundle string goes toFileI18nAdapter.t()andcreateMemoryI18n().t(), and each answer must equal what the Console's i18next answered for that template (measured, table below):{{name}},{{ name }}, a tab plus two spaces, single braces, and a spaced hole with no value.packages/core/src/fallbacks/fallbacks.test.ts: one test in core's own suite ({{ name }}filled, a spaced hole with no value kept as written), so core alone catches a regression.Per-form readings (params
{ name: 'Ada' }):FileI18nAdapter/createMemoryI18nHi {{name}}!Hi Ada!Hi Ada!Hi Ada!Hi {{ name }}!Hi Ada!Hi {{ name }}!Hi Ada!Hi Ada!Hi Ada!Hi {name}!Hi {name}!Hi {name}!Hi {name}!Hi {{ missing }}!Hi {{ missing }}!Hi {{ missing }}!Hi {{ missing }}!Acceptance notes
origin/mainbd5407ecbefore any edit: a probe fed one template to real i18next 26.4.0 (the Console's dependency, its default{{ }}interpolation),createMemoryI18n().t()andFileI18nAdapter.t(). Readings are the "Console" and "main" columns above.interpolateValidationMessageinpackages/spec/src/system/validation-message.tsfills translated validation and operation message overrides and still reads only{{label}}. The probe measured a{{ label }}override printed as written. The seat files it as a separate card.plugin-auditactivity-summary-message.ts,plugin-approvalsapproval-notification-text.ts, coresecurity/change-record-owner.ts. Their docblocks say they follow "the convention botht()use", which is now only true for unspaced holes. Left as is.Verification
pnpm --filter @objectstack/service-i18n exec vitest run src/file-i18n-adapter.test.tsshows 61 passed, 10 of them the new block.interpolateinfile-i18n-adapter.ts, then thet()return line inmemory-i18n.ts.Local readings at cc1fe06
pnpm --filter @objectstack/service-i18n test: Test Files 4 passed, Tests 87 passed;typecheckexit 0.pnpm --filter @objectstack/core typecheck && pnpm --filter @objectstack/core test: Test Files 158 passed, Tests 3807 passed.scripts/ablation-replace.mjs, each restore blob == HEAD andgit diff HEADempty:FileI18nAdapterspaced, tab).dist/: core suite 1 failed; adapter suite 2 failed (createMemoryI18nspaced, tab). After restore and a forced core rebuild,dist/index.jscarries the new pattern on the memory line.{{key}}: 1 failed (spaced hole with no value).dispatch-gates --ranwith recorded exit codes (gates-ran-cc1fe06c.list): 67 derived, 65 exit 0, 2 NOT MEASURED (exit 3:check-plugin-teardown-shape --self-test, fixture commit outside the shallow clone;check:dual-build-cjs-loads, needs a fullpnpm build), 0 unrun.check:lean-entry-closureexit 0 after an objectql build.overlap-check.mjsVERDICT clean exit 0 against origin/main 98bd8de.Generated by Claude Code