Skip to content

fix(i18n): emit settings expected-result codes from producers - #4551

Open
orangeCatDeveloper wants to merge 3 commits into
apache:mainfrom
orangeCatDeveloper:fix/locale-producer-codes
Open

fix(i18n): emit settings expected-result codes from producers#4551
orangeCatDeveloper wants to merge 3 commits into
apache:mainfrom
orangeCatDeveloper:fix/locale-producer-codes

Conversation

@orangeCatDeveloper

@orangeCatDeveloper orangeCatDeveloper commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Settings-area producers emitted zh-only result strings, so English users either saw Chinese or — where consumers guarded with /[㐀-鿿]/ content sniffing — silently lost the information (permission guidance was dropped entirely). Producers now emit stable machine codes (IPC payloads stay locale-free), and each settings catalog maps its union exhaustively per locale with an explicit unknown-code fallback. CJK sniffing was removed where this PR code-ified the producer; one pre-existing zh-only action-error passthrough remains pending locale roadmap W2b. zh copy moved verbatim, en copy is new.

Covered producers: capability-snapshot reasons, memory ops, test-connection OAuth rate-limit, computer-use-host health reasons, the GitHub Copilot import path (github-copilot-local-credential + its IPC handler, re-based onto main's device-grant rewrite), plus the dev-singleton dialog, browser message-box close label, and artifact/config native dialog titles (wired through the main-process locale authority). subscriptionResultMessage now takes the result envelope and resolves code, then the typed reason (experimental_disabled), through the catalog before falling back to the keyword classifier; its trailing CJK passthrough is gone. It moved out of the useOAuthLoginFlow hook module into the catalog module beside the copy it renders, which also makes it testable from node.

The bot domain moved to its own PR so each PR is one reviewer context.

Memory messages now use complete per-locale templates instead of a shared sentence skeleton with translated fragments. The typed catalog owns counts, summaries, redaction notices, backup failures, and preview/action descriptions; existing wording and pluralization are preserved.

Refs #2672

Verification

apps/desktop typecheck (4 tsconfigs):   0 errors
workspace typecheck:                    0 errors
desktop main tests (dist):              2097 pass / 0 fail
rendered-output tests (en+zh):          Copilot code, memory rejection codes, experimental_disabled reason, unknown code → fallback
packages/core tests:                    801 pass / 0 fail
CJK-sniff regexes in touched files:     1 retained (provider action fallback; W2b)
zh literals in copilot producers:       0 remaining (was 8)
renderer architecture check:            passed against origin/main
biome (changed files):                  clean
check:tui-copy:                         ok

Boundaries: the four legacy capability reason tokens keep their existing prose form, and health.ts and permission-center-copy.ts retain parallel zh code-to-copy maps; #4524 coordinates that vocabulary and presenter cleanup. provider-panel-shared.ts retains one zh-only CJK passthrough until its remaining main-process producers are code-ified in locale roadmap W2b. subscriptionResultMessage still matches three English Host messages (enrollment is disabled, already in progress, did not present OAuth) as a fallback for Hosts that predate the codes; those matches go once every Host sends code.

Follow-up verification: all 13 memory-copy and label tests pass, with exact formatted-output coverage across all three locales, draft states, singular/plural counts, archived entries, backup kinds, and preview messages. Desktop build and all four typechecks, repository format/lint, and the renderer architecture check pass.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude Code, Muse Spark, and OpenCode — analysis, implementation, review fixes, tests, and this description, under the contributor's direction; each affected commit carries the corresponding Generated-by trailer.

OpenCode also implemented the complete memory-message templates and their output tests, and updated this description.

Checklist

  • Tests cover the change and fail without it

@github-actions github-actions Bot added the effort/XL Under 2500 readable lines label Sep 2, 2026
@orangeCatDeveloper
orangeCatDeveloper force-pushed the fix/locale-producer-codes branch 7 times, most recently from ad2b11d to 89c58cd Compare September 3, 2026 08:49
@orangeCatDeveloper orangeCatDeveloper changed the title fix(i18n): emit expected-result codes from producers fix(i18n): emit settings expected-result codes from producers Sep 3, 2026
@orangeCatDeveloper
orangeCatDeveloper force-pushed the fix/locale-producer-codes branch 2 times, most recently from 4b6d344 to b526451 Compare September 3, 2026 10:12
@github-actions github-actions Bot added effort/L Under 1000 readable lines and removed effort/XL Under 2500 readable lines labels Sep 3, 2026
@orangeCatDeveloper
orangeCatDeveloper marked this pull request as ready for review September 4, 2026 06:50
@orangeCatDeveloper
orangeCatDeveloper force-pushed the fix/locale-producer-codes branch 9 times, most recently from 236c0da to daeb9ba Compare September 5, 2026 04:59
@orangeCatDeveloper
orangeCatDeveloper marked this pull request as draft September 5, 2026 05:01
Astro-Han pushed a commit that referenced this pull request Sep 5, 2026
Adding a UI locale compiled cleanly and still rendered the wrong language wherever code compared `locale` to a literal, defaulted a `locale: UiLocale` parameter, sniffed CJK in a payload, or translated by looking up one locale's string. The type system cannot see any of the four, and Biome cannot express "no growth against base" for the two unformatted trees.

`scripts/check-locale-hygiene.mjs` counts those four patterns per file in `apps/desktop/src`, `packages/core/src` and `packages/ui/src`, both quote styles, per match, and fails CI when any (file, rule) count grows against the merge base or `BASE_SHA`. There is no ledger to maintain; only files in the diff are scanned. With no resolvable base the step fails instead of skipping. The step runs with the install-free gates before `setup-node`. `locale-literal-compare` is deliberately narrower than `check-tui-copy`'s AST rule so it stays dependency-free.

No runtime or migration impact. Baseline on this commit: 67 / 4 / 12 / 32; the four `silent-locale-default` hits retire with #4524 and #4551, after which that rule can become a hard zero.

Refs #2672

Generated-by: Claude Code
Settings-area producers (memory, data, permission center, connection
test, computer-use health, dev dialogs) emitted zh prose that reached en
users verbatim, and presenters sniffed CJK to decide whether to show it.
Producers now return stable codes and redact probe detail at the source;
each settings catalog maps its codes per locale with complete message
templates and an explicit unknown fallback. The remaining CJK passthrough
is gated to zh.

Generated-by: Claude Code
Claude-Session: https://claude.ai/code/session_01AqdSkg56F2x55wEGRWvzcB
Keep capability details localized with structured health signals and reuse the own-key lookup for unknown memory result codes.

Generated-by: OpenCode
The Copilot and local-memory producers emitted untyped code strings while
the renderer catalogs kept their own unions, so a new producer code could
miss the catalog without a type error.

Generated-by: Claude Code
@orangeCatDeveloper
orangeCatDeveloper marked this pull request as ready for review September 5, 2026 12:19
@github-actions github-actions Bot added effort/XL Under 2500 readable lines and removed effort/L Under 1000 readable lines labels Sep 5, 2026

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at af07077 against 03b5a2cc5a, two independent passes. This is the CapabilityReasonCode follow-up #4524 asked for, and the producer side is right: CAPABILITY_REASON_CODES is one closed list in @maka/core, the memory and subscription codes are closed unions, the native dialog titles read the existing main-process locale authority rather than a new one, the interim CJK sniff in settings-health-copy.ts is gone, and zh-TW is real traditional copy.

One P1, three P2s, then smaller items.

P1: the 23 capability reason codes get two full three-locale tables, and they already say different things. settings-health-copy.ts:257-333 and permission-center-copy.ts:153-348 each map every code. For missing platform credentials the Health center renders 等待填写平台凭据。 and the Permission Center 未配置平台凭据; macOS TCC only is 仅 macOS 系统权限可探测。 in one and 仅 macOS TCC 权限适用 in the other. That is 138 strings maintained twice and two pages describing one state in two ways, which is the exact defect this family of PRs exists to remove. The body defers the reconciliation to #4524, but #4524 is merged and did not do it; it is this PR's job. One Record<CapabilityReasonCode, string> per locale in a shared module, both pages read it, and the Permission Center keeps only its cuBackendStatus composition. (Path ①: both pages show the same capability.)

P2: the Permission Center loses every bot capability's reason. capability-snapshot.ts:247-251 passes the bot's readinessReason into runtimeProbe.reason; on main localizedSnapshotText shows it when it is not CJK, so English users see "Telegram requires a Bot Token." The new resolver at permission-center-page.tsx:723-729 sends anything that is not a capability code to reasonFallback, and the comment says bot reasons are machine codes owned by the bot page. That is #4639's world, not main's, and even after #4639 the right answer is the bot copy, not a generic line. Land after #4639 and resolve bot:* reasons through its botStatusReasonMessage; until then keep the non-CJK pass-through.

P2: three of the new "codes" are English prose. capabilities.ts:115-117 lists 'missing platform credentials', 'macOS TCC only' and 'no Electron API for per-target Apple Events TCC status', and the producer now emits those where it used to emit Chinese. The body says the legacy tokens "keep their existing prose form"; they changed language. Any consumer that misses the map shows English to a Chinese user, which is the old failure with the locales swapped. Make them snake_case like the other twenty, or correct the body and add the missing-map test.

P2: subscriptionResultMessage drops an unclassified Host reason. The old subscription-result-message.ts:52 passed a non-CJK message through when nothing matched; the new function (settings-provider-copy.ts:681) returns the generic fallback when the classifier has no match, which can contradict what the Host said. The order (code → typed reason → three legacy matches → classifier) is right; keep the raw-text pass-through as the last step, and note at the three legacy matches when they can go (once every Host sends code).

Smaller:

  • test-connection.ts:508 deletes the 429 message rather than coding it, so a rate-limited OAuth account is now indistinguishable from provider_unavailable and the "retry later or switch model" guidance is gone; the body lists it under covered producers.
  • settings-error-copy.ts:33 replaces the zh-CN user-visible main-process message with unknownError plus console.error; and scripts/storybook-visual-smoke.mjs:188-193 now matches that console line by full text, so a story that changes the sentence fails the smoke. Match on the [settings] prefix.
  • settingsTestResultMessage's default branch loses the en pass-through (settings-test-result-copy.ts:163-166); this is the line #4639 also changes.
  • runtime-host-memory-ipc-main.ts:626-627 writes reason and code with the same value, the Copilot IPC writes message: code, and bridge-contract.d.ts:1511-1517 still carries message that nothing reads. One field.
  • localizedCapabilityGuidance maps capability.guidance, which no producer fills; health.ts:398-404 prefers runtimeProbe.reason, which Computer Use always has, so the Health cu_backend_status entry is unreachable; apps/desktop/src/main/permission-snapshot-e2e-fixture.ts:94 still emits Chinese prose and now renders reasonFallback.
  • "W2b" appears only in this body; if it is a roadmap item, link it.
  • Separable scope: the dev-singleton dialog, the message-box close label and the native dialog titles are a different producer family with no code union; fine to keep, but they are why the diff is 42 files.

Ordering: #4639 first, then this rebases and picks up its bot copy; with #4641 and #4526 the shared files differ only by key, any order.

Manual acceptance, three locales: Permission Center's Computer Use row against main word for word, a bot row with a failed test, the Health center row for the same capability (should now match the Permission Center), a memory save with counts and a backup, an OAuth subscription failure without a code.

Evidence boundary: static read against main; memory string fidelity was not re-checked line by line; no build, no suites, no Desktop.

AI-assisted review: drafted with Maka in two passes; I verified the two reason tables, the Permission Center resolver, the three prose codes and the sniff removal myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XL Under 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants