Repository navigation
Commit d085e6c
fix(i18n): server t() fills {{ name }} holes written with spaces, as the Console does (#38265)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6Jao5sbi7ZRGktseLEY4Auk4YX)_
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`:
`interpolate` matches `{{`, 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 fallback
`t()` gets the same pattern and the same write-back.
- Single braces (`{name}`) are still not a placeholder on either side.
- Changeset: `@objectstack/core`, `@objectstack/service-i18n` minor
(`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-level `describe`: the same bundle string goes to
`FileI18nAdapter.t()` and `createMemoryI18n().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' }`):
| Template | Console (i18next 26.4.0) | main `FileI18nAdapter` /
`createMemoryI18n` | this PR, both |
|:--|:--|:--|:--|
| `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` `bd5407ec` before any edit: a probe
fed one template to real i18next 26.4.0 (the Console's dependency, its
default `{{ }}` interpolation), `createMemoryI18n().t()` and
`FileI18nAdapter.t()`. Readings are the "Console" and "main" columns
above.
- Same gap, not fixed here (seat ruling, claim 7237673531):
`interpolateValidationMessage` in
`packages/spec/src/system/validation-message.ts` fills 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.
- Three more copies of the old pattern fill only the platform's own
English catalogs, which carry no spaced holes, so no author reaches
them: `plugin-audit` `activity-summary-message.ts`, `plugin-approvals`
`approval-notification-text.ts`, core `security/change-record-owner.ts`.
Their docblocks say they follow "the convention both `t()` use", which
is now only true for unspaced holes. Left as is.
- One widening, nothing narrowed: every string that rendered before
renders the same, except that a spaced hole with a value is now filled.
## Verification
- Two-minute check: `pnpm --filter @objectstack/service-i18n exec vitest
run src/file-i18n-adapter.test.ts` shows 61 passed, 10 of them the new
block.
- Read first: `interpolate` in `file-i18n-adapter.ts`, then the `t()`
return line in `memory-i18n.ts`.
<details><summary>Local readings at cc1fe06</summary>
- `pnpm --filter @objectstack/service-i18n test`: Test Files 4 passed,
Tests 87 passed; `typecheck` exit 0.
- `pnpm --filter @objectstack/core typecheck && pnpm --filter
@objectstack/core test`: Test Files 158 passed, Tests 3807 passed.
- Ablations through `scripts/ablation-replace.mjs`, each restore blob ==
HEAD and `git diff HEAD` empty:
- adapter pattern reverted: 2 failed (`FileI18nAdapter` spaced, tab).
- memory pattern reverted, core rebuilt and marker read in `dist/`: core
suite 1 failed; adapter suite 2 failed (`createMemoryI18n` spaced, tab).
After restore and a forced core rebuild, `dist/index.js` carries the new
pattern on the memory line.
- adapter write-back re-spelled as `{{key}}`: 1 failed (spaced hole with
no value).
- `dispatch-gates --ran` with 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 full `pnpm build`),
0 unrun. `check:lean-entry-closure` exit 0 after an objectql build.
- `overlap-check.mjs` VERDICT clean exit 0 against origin/main 98bd8de.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibxWAZYhFuv668TruUa)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent baa38c0 commit d085e6c
5 files changed
Lines changed: 56 additions & 6 deletions
File tree
- .changeset
- packages
- core/src/fallbacks
- services/service-i18n/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
227 | 234 | | |
228 | 235 | | |
229 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
188 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
189 | 191 | | |
190 | 192 | | |
191 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
590 | 590 | | |
591 | 591 | | |
592 | 592 | | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
82 | 86 | | |
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
88 | | - | |
89 | | - | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
102 | | - | |
| 106 | + | |
103 | 107 | | |
104 | 108 | | |
105 | 109 | | |
| |||
0 commit comments