Repository navigation
fix(service-i18n): a missing translation's fallback is reported once through the plugin logger - #28539
Conversation
…e plugin logger What t() returns is unchanged; the fallback-served case warns once per key and locale, a locale with no bundle warns once, a key no bundle holds is a debug line, and reports stop after a bounded count. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5ngfAAwCv6XCUZUQ5e
…, not a warn Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5ngfAAwCv6XCUZUQ5e
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5ngfAAwCv6XCUZUQ5e
📓 Docs Drift CheckThis PR changes 1 package(s): 2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 5 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 0bbbf82a04f231a5130be2e5ded605915b4eee3b && git checkout 0bbbf82a04f231a5130be2e5ded605915b4eee3b
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 37184244b82b9e4234581b653cdc7554e74e6136 0be93784dc193637a8ca371c8b2582a4f7a03ae1 && git checkout -B drift-repro 37184244b82b9e4234581b653cdc7554e74e6136 && git merge --no-ff 0be93784dc193637a8ca371c8b2582a4f7a03ae1
node scripts/docs-audit/affected-docs.mjs --json 37184244b82b9e4234581b653cdc7554e74e6136
|
|
domain:server#2 · os-project-manager · session_0186vfjHHMsRXC9EUT9hTFMo 席位核对ACCEPT · The maintainer's standing authorisation for landing reviewed PRs, verbatim: 「按照 pm-dispatch 规则复核过的都授权」.
Generated by Claude Code |
Requested by Leehom · project thread
Fixes #28109
Clause-②: no (the returned strings are unchanged; a log signal only)
Metadata-protocol: none
维护者速读
FileI18nAdapter.t()在缺翻译回退时,经插件 logger 说一次:请求语言缺某个键、由回退语言补上时,每个「键 + 语言」说一次;请求语言整包都没有时,每个语言只说一次;所有包都没有这个键时记一条 debug。返回给用户的字符串一个字节都不变。supportedLocales,未声明时即已加载的语言)才是 warn,其余是 debug,所以客户端乱发Accept-Language推不高 warn 量。回滚即 revert。packages/services/service-i18n/src/file-i18n-adapter.ts(t()的回退分支与新的reportMiss);src/file-i18n-adapter.test.ts末尾的新 describe;src/i18n-service-plugin.ts(把ctx.logger传给适配器的一行)。pnpm --filter @objectstack/service-i18n exec vitest run --maxWorkers=2→ 4 个文件 71/71 通过。What changes
The signal: a once-per-key runtime warning (the dev's choice the triage left open). An author diagnostic was not chosen: most
t()keys are computed at run time (objects.X.fields.Y.label,validation.field.required), so no static check can list them, and the triage excludes a new gate.FileI18nAdaptertakes an optionallogger(thewarnanddebugmembers ofLoggerfrom@objectstack/spec/contracts). Without one it is silent, exactly as before, so a library user constructing the adapter by hand sees no change.I18nServicePlugin.initpassesctx.logger.On a miss in the requested locale,
t()callsreportMissafter the fallback leg. The fallback order and the returned value are untouched (the reporting reads only whatt()already computed). Each report is said once:warnif the stack offers the locale, elsedebugwarnif the stack offers the locale, elsedebugdebug, alwayswarn, then silence until restart"Offers" is
getLocales(): the declaredi18n.supportedLocales, else every loaded locale. For any other locale the client asked for something the app never offered (often straight fromAccept-Language), the fallback is the designed answer, and a client cannot drive the warn volume by sending locales.Why the key-missed-everywhere case is
debug, not the louder warning the order leaned toward. At least tent()callers probe on purpose and read the echoed key as "not overridden": the field/object label ladders in objectql (record-validator.ts,engine-validation-messages.ts,rule-validator.ts), the approvals reader labels and refusal override address, the audit activity summary, messaging's notification text, the sandbox hook refusal catalogue and automation's node text. Measured live (below), every both-missed line on a plain boot and page load is one of these probes (objects.showcase_account.fields.__search.label,validation.field.required,flows.*.labelinen, where the source label lives in metadata, not in a bundle). Awarnthere would report misses nobody has to fix. Messaging already warns once per key for its own catalog misses.The bound.
FileI18nAdapter.MISSING_TRANSLATION_REPORT_LIMIT = 1000, shared by per-key and per-locale entries. The largest per-page report count measured below is 12 distinct entries per locale, so 1000 leaves room for a whole partial locale while costing at most some tens of KB of short strings.Tests
src/file-i18n-adapter.test.ts,src/i18n-service-plugin.test.ts):Tests 6 failed | 44 passed (50). The failures were exactly the reporting cases; the controls ("a hit in the requested locale logs nothing", "returns exactly what an adapter without a logger returns") passed on base.pnpm --filter @objectstack/service-i18n exec vitest run --maxWorkers=2→Test Files 4 passed (4) · Tests 71 passed (71);pnpm typecheckexit 0.debugper key and locale and still returns the key; an offered locale with no bundle is onewarnfor any number of keys; an unoffered locale with no bundle is onedebug; a fallback in an unoffered locale isdebugwhile an offered one iswarn; an authored translation counts as the locale's bundle and as a hit; the bound stops after 1000 with one closing line; the returned strings (with and without interpolation, every case) equal those of an adapter with no logger; the plugin passes its logger through.node scripts/ablation-replace.mjs --deleteof thethis.reportMiss(...)call int(); tests importsrc/relatively, so no build leg): anchor 1 → 0, blobbbf3e2c1→07a841a0;Tests 8 failed | 44 passed (52)in the two files, every reporting case red and every control green; restored, blob == HEAD,git diff HEADempty.Acceptance notes
Noise, measured live on
objectstack dev --seed-admin --freshatOS_LOG_LEVEL=debug, after a fullpnpm buildand the console build, loading the real Console home (/_console/home, 20 to 21 API requests) once per locale in Chromium with thatAccept-Language. Report lines added by each load:Zero
warnlines on either stack at the head. Base logged nothing of any kind. At the defaultinfolevel a plain boot and page load therefore print nothing new.An intermediate head that warned on every locale with a bundle measured 3
warnlines per Console home load in ja-JP and in es-ES on the showcase (objects.showcase_invoice.label,objects.showcase_contact.label,objects.showcase_account.label: the platform plugins ship ja-JP/es-ES bundles, the showcase translates its objects only in zh-CN). That is the case the "offered" rule turns intodebug: the showcase never offered those locales.The first measured
frload (i18n: French is not a platform locale, so a user whose locale isfrreads Englishsys_userlabels (Home feed field labels) #28107:fris not a platform locale) gave one line for the whole page, not one per key.A locale requested before its bundles are pushed (platform bundles load at
kernel:ready) would be reported as having no bundle once; none of the measured boots produced such a line.Verification
Derived gate list at head (60 commands), each exit captured before any pipe, reconciled with --ran
Run at head
0be93784(each line isCOMMAND :: exit N):node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran FILE→ exit 0:60 derived famil(ies) accounted for — 60 run, 0 NOT-MEASURED.check-plugin-teardown-shape.mjs --self-testneededgit fetch --depth=1 origin 621a4876…on this shallow clone first (exit 3 before, 0 after). Families CI runs outside the derived list (artifact roster, wide-population, type-check lanes, Test Core) are read from the PR's check-runs, not re-run here.Scoped lint
node --stack-size=4000 node_modules/eslint/bin/eslint.js packages/services/service-i18n --no-inline-config→ exit 0. Control-byte self-scan of the touched files: no hit.test:repo(vitestrepoproject) is not run locally: the diff edits no repo-project test and the derived list does not name it; CI's Test Core runs it.Generated by Claude Code