CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

feat: i18n Phase 1-4b wiring + rebase compile fixes

Open gordonlu opened this issue 6 months ago • 12 comments

Rebases and supersedes PR #812.

Wires the Phase 1–4b MessageId translations into the actual UI layer across 47 files. Fixes 109 compile errors caused by the upstream rebase (E0004 non-exhaustive patterns, E0061 argument count mismatches).

Changes

  • localization.rs: +1059 lines — 55 new MessageId variants for ConfigScope, AppMode, VimMode, Welcome, ContextInspector
  • 46 files wired: approval menu, agent cards, sidebar, history, context inspector, config views, onboarding/welcome, composer, header, status picker, pending input preview, tool card family labels
  • ** → **: renamed 1-arg version to avoid ambiguity with the new 2-arg — 109 call sites updated across 19 command files
  • Bug fixes:
    • default arm now propagates (was hardcoded )
    • test assertion corrected (was checking for nonexistent character)
    • Unused / imports removed to satisfy CI

Test status

3438 passed, 0 failures (2 pre-existing environment-specific tests do not apply in CI)

Greptile Summary

This PR wires the Phase 1–4b i18n MessageId translations into 46 UI files, renames the 1-arg CommandResult::error to error_msg and introduces a locale-aware 2-arg error, and fixes 109 compile errors from the upstream rebase (non-exhaustive match arms, argument-count mismatches).

  • Locale threading: AppMode::label, VimMode::label, ElevationOption::label/description, and all tool-card family labels now accept a Locale parameter; HookContext, analytics events, and StructuredState::capture() calls are all correctly pinned to Locale::En.
  • New message IDs: 55 variants added across ConfigScope, AppMode, VimMode, Welcome, ContextInspector, approval/elevation, queue commands, and tool-family labels — all with English strings wired end-to-end.
  • Bug fixes bundled: AppMode::label default arm now propagates Locale::En in model-facing contexts; the qa_pty viewport assertion is broadened to accept both old title-case and new uppercase mode labels.

Confidence Score: 4/5

Safe to merge after addressing two missed wiring spots: a model-facing relay instruction that embeds the user's locale instead of English, and a FanoutCounts message ID that was registered but never connected to the rendering code.

Two call sites were left partially wired. In build_relay_instruction the mode label is built with app.ui_locale rather than Locale::En, so the relay text sent to the model will contain a translated mode name once non-English locales are added — diverging from every other model-facing site in the same PR. In FanoutCard::render_lines the FanoutCounts message ID was declared and translated but the rendering code still uses a hardcoded format string, leaving fanout stats unlocalized and the new variant dead. Everything else — hook context, analytics, engine state capture, header, approval, context inspector, queue commands — is correctly wired.

crates/tui/src/commands/mod.rs (build_relay_instruction locale) and crates/tui/src/tui/widgets/agent_card.rs (FanoutCard stats row)

Important Files Changed

Filename Overview
crates/tui/src/localization.rs Adds 55 new MessageId variants and their English translations for Phase 1–4b; includes FanoutCounts which is defined but not yet wired in agent_card.rs
crates/tui/src/commands/mod.rs Renames error() to error_msg() and adds locale-aware error(); build_relay_instruction still passes app.ui_locale to mode.label() for model-facing text instead of Locale::En
crates/tui/src/tui/widgets/agent_card.rs Wires locale into AgentLifecycle labels, card headers, and render_lines; FanoutCard stats row still uses a hardcoded format string instead of FanoutCounts message ID
crates/tui/src/tui/app.rs AppMode::label and VimMode::label now take a Locale; HookContext and StructuredState calls correctly use Locale::En; status_message uses ui_locale (user-facing, correct)
crates/tui/src/core/engine.rs All three StructuredState::capture() call sites correctly updated to mode.label(Locale::En), keeping model-facing context locale-stable
crates/tui/src/tui/ui.rs Analytics/telemetry events and ElevationView construction updated to pass Locale::En and ui_locale respectively; context inspector and pending preview wired correctly
crates/tui/src/commands/queue.rs Queue commands wired with locale-aware strings; list_queue strips {n} from CmdEditingQueuedDraft leaving double-space and extraneous hint text in list context (pre-existing flag)
crates/tui/src/tui/context_inspector.rs Full locale wiring for build_context_inspector_text; all test assertions updated to use Locale::En and match new English strings correctly
crates/tui/src/tui/history.rs Locale threaded through ToolCell::render and SubAgentCell dispatch; legacy no-locale entry points fall back to Locale::En preserving backward compatibility
crates/tui/src/tui/approval.rs ElevationOption::label and description now locale-aware; ElevationView stores locale and passes it to the widget; all tests updated to Locale::En
crates/tui/src/tui/widgets/header.rs HeaderData gains a locale field; mode_name now delegates to AppMode::label(locale); tests updated, string expectations changed from title-case to uppercase to match new labels
crates/tui/tests/qa_pty.rs Viewport assertion broadened to accept both old title-case and new uppercase mode labels, maintaining backward compatibility during any transition

Comments Outside Diff (3)

  1. crates/tui/src/commands/queue.rs, line 51-52 (link)

    P1 Unresolved {n} placeholder in list context

    CmdEditingQueuedDraft translates to "Editing queued message {n} (press Enter to re-queue/send)", but in list_queue the {n} placeholder is never replaced. When a user runs /queue list with an active draft the output will literally contain "Editing queued message {n} (press Enter to re-queue/send):". The original string before this PR was a separate "Editing queued message:" without any placeholder, so these two sites need distinct message IDs — or the list site needs to call .replace("{n}", "") at minimum.

    Fix in Codex Fix in Claude Code Fix in Cursor

  2. crates/tui/src/commands/mod.rs, line 911-914 (link)

    P2 #[allow(dead_code)] on a function with 109+ callers

    error_msg is called at over 100 sites introduced in this very PR, so the compiler will not flag it as dead code. The annotation is a no-op right now but may mislead future readers into thinking the function is intended for eventual removal. Consider dropping the attribute, or — if error_msg is genuinely transitional — leave a // TODO: comment explaining the migration plan.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

    Fix in Codex Fix in Claude Code Fix in Cursor

  3. crates/tui/src/tui/widgets/agent_card.rs, line 318-328 (link)

    P1 FanoutCounts message ID wired but never used

    MessageId::FanoutCounts was added to localization.rs with the English translation "{done} done · {running} running · {failed} failed · {pending} pending", but FanoutCard::render_lines still builds this string with a hardcoded format literal rather than calling tr(locale, MessageId::FanoutCounts). The new message ID is effectively dead code, and the fanout stats row will always display in English regardless of the active locale — the only part of the fanout card that was not actually wired in this PR.

    Fix in Codex Fix in Claude Code Fix in Cursor

Fix All in Codex Fix All in Claude Code Fix All in Cursor

Reviews (2): Last reviewed commit: "fix: queue draft header {n} leak, hook/a..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

gordonlu avatar May 27 '26 01:05 gordonlu

Greptile review identified two remaining wiring issues. Here are the specific fixes:

Fix 1: FanoutCounts dead code in agent_card.rs (~line 321)

-                format!(
-                    "{done} done \u{00B7} {running} running \u{00B7} {failed} failed \u{00B7} {pending} pending"
-                ),
+                self.app.tr(locale, MessageId::FanoutCounts),

The FanoutCounts message ID was defined in localization.rs but never used — this wires it in.

Fix 2: Relay instruction locale in commands/mod.rs (line 830)

-    let _ = writeln!(out, "- Mode: {}", app.mode.label(app.ui_locale));
+    let _ = writeln!(out, "- Mode: {}", app.mode.label(Locale::En));

Relay instructions go to the model — they must use Locale::En for consistency with StructuredState::capture() and engine.rs.

After these two fixes, the PR is ready to merge. 3438 tests still pass.

Hmbown avatar May 27 '26 05:05 Hmbown

Independent review:

Verified merge-sim from PR head onto main: clean. Onto pr-2256 (v0.8.48): single conflict at commands/config.rs:476 (your error_msg vs v0.8.48's still-named error) — 30-second rebase. cargo check -p codewhale-tui is clean on this branch.

Findings:

  1. Dead translation, still active: MessageId::FanoutCounts is defined with named placeholders in EN/JA/ZhHans/PtBr ({done} done · {running} running · …), but agent_card.rs:320 still hardcodes English. Your own follow-up comment already flagged this — not yet applied. Same MessageId is unused in 4 language tables.
  2. Locale fallback chain is hardcoded, not driven by LocaleSpec.fallback: traditional_chinese() delegates to chinese_simplified(other)?, then english(id). LocaleSpec.fallback field is dead. Works, but the spec is misleading.
  3. Coverage scope: Title says "Phase 1-4b wiring" — accurate. ~104 hardcoded status_message = Some(...) literals remain in ui.rs; commands/{debug,goal,stash,skills}.rs still have plain English in CommandResult::message(...). Worth a "remaining scope" tracking issue.
  4. Performance: tr() returns &'static str — zero per-frame allocation. Format! calls predated this PR. Good.
  5. "Rebase compile fixes" scope: Legitimate. 109 errors from renaming 1-arg error→error_msg plus E0004 from new AppMode::Plan arm and E0061 from label(locale) signature change — all mechanical, all required.
  6. Engine pinning to Locale::En in StructuredState::capture, hooks, analytics: correct — those payloads cross the model boundary.

v0.8.48 impact: 1 trivial textual conflict (above). Land #2256 first, rebase this.

Hmbown avatar May 27 '26 13:05 Hmbown

Independent review:

Verified merge-sim from PR head onto main: clean. Onto pr-2256 (v0.8.48): single conflict at commands/config.rs:476 (your error_msg vs v0.8.48's still-named error) — 30-second rebase. cargo check -p codewhale-tui is clean on this branch.

Findings:

  1. Dead translation, still active: MessageId::FanoutCounts is defined with named placeholders in EN/JA/ZhHans/PtBr ({done} done · {running} running · …), but agent_card.rs:320 still hardcodes English. Your own follow-up comment already flagged this — not yet applied. Same MessageId is unused in 4 language tables.
  2. Locale fallback chain is hardcoded, not driven by LocaleSpec.fallback: traditional_chinese() delegates to chinese_simplified(other)?, then english(id). LocaleSpec.fallback field is dead. Works, but the spec is misleading.
  3. Coverage scope: Title says "Phase 1-4b wiring" — accurate. ~104 hardcoded status_message = Some(...) literals remain in ui.rs; commands/{debug,goal,stash,skills}.rs still have plain English in CommandResult::message(...). Worth a "remaining scope" tracking issue.
  4. Performance: tr() returns &'static str — zero per-frame allocation. Format! calls predated this PR. Good.
  5. "Rebase compile fixes" scope: Legitimate. 109 errors from renaming 1-arg error→error_msg plus E0004 from new AppMode::Plan arm and E0061 from label(locale) signature change — all mechanical, all required.
  6. Engine pinning to Locale::En in StructuredState::capture, hooks, analytics: correct — those payloads cross the model boundary.

v0.8.48 impact: 1 trivial textual conflict (above). Land #2256 first, rebase this.

Thanks for the thorough review!

I’ll wait for #2256 to be merged first, then rebase this PR and address the hardcoded English in agent_card.rs:320 (and other improvements you mentioned).

Please go ahead with #2256. Thanks again!

gordonlu avatar May 28 '26 01:05 gordonlu

thank YOU!

Hmbown avatar May 28 '26 06:05 Hmbown

Thanks @gordonlu — the i18n work here is clearly cared for, and I want it treated as a real product surface rather than a drive-by string pass.

I’m not merging it in this harvest because it spans composer/config/status-line behavior and can easily drop current UI copy unless it gets its own integration branch. The right path is a dedicated i18n pass with locale fixtures and screenshot/smoke coverage, not a hurried merge in the middle of unrelated PR harvesting.

Hmbown avatar May 31 '26 03:05 Hmbown

One follow-up from the current harvest pass, since the branch state has shifted a bit since the earlier note: GitHub is now reporting this as dirty against main, and a few specific i18n wiring items still need love before I’d feel good merging it.

The concrete next bits I’d focus on:

  • rebase onto current main
  • wire FanoutCounts through the actual fanout card instead of leaving those stats hardcoded in English
  • keep /relay model-facing mode/context text pinned to English even when the UI locale changes
  • split the /queue list copy from the edit-status sentence so placeholder handling stays clean

Still appreciate the care here. This is exactly the kind of cross-surface work that deserves a calmer integration pass instead of getting squeezed through a release harvest.

Hmbown avatar May 31 '26 08:05 Hmbown

Thanks @gordonlu. I still want this i18n work, but this branch is now conflicting against current main and the scope is too broad to merge during harvest.

The safest next step is a fresh narrower phase from current main: one UI surface at a time with locale fixtures. Two concrete items to carry forward are keeping /relay model-facing text pinned to English, and wiring FanoutCounts through the fanout card instead of leaving that row hardcoded. I’d keep #790 open until the broader i18n coverage is actually complete.

Hmbown avatar May 31 '26 10:05 Hmbown

Thanks @gordonlu. I re-checked this against current main today. The i18n work is still useful, but the branch is now conflicting and far enough behind that I do not think we should merge it as-is.

Concrete blockers: GitHub reports the PR as conflicting, a local merge simulation conflicts in the command/UI/localization surfaces, current main now ships Vietnamese locale coverage with completeness tests, and a couple of wiring issues still need to be carried forward: FanoutCounts should render through localization, and model/hook-facing mode labels should stay pinned to English.

I think the best path is a fresh narrow i18n branch from current main, one UI surface at a time, with all shipped locale arms covered. I’d be happy to review that smaller harvest. Thanks for pushing this surface forward.

Hmbown avatar May 31 '26 18:05 Hmbown

Really appreciate the i18n work here. This is the kind of surface that makes CodeWhale feel welcoming to more people, and it deserves a careful merge instead of a rushed one.

I am leaving it out of the 0.8.48 pass because the branch is dirty against main and the diff touches a broad user-facing area. Best next step is a fresh rebase plus a small smoke checklist in the PR body: language selection, default English paths, and any README/site strings that changed. Once that is current, we can review the user-facing copy with the same care as the code.

Hmbown avatar Jun 01 '26 02:06 Hmbown

Thanks again @gordonlu. One update from the current v0.9 stewardship pass: the FanoutCounts part of this PR has now effectively been harvested into the current branch. MessageId::FanoutCounts is present, FanoutCard::render_lines uses it, and the focused check passes:

cargo test -p codewhale-tui fanout_counts_are_localized --locked

I am still leaving this PR open rather than closing it, because the broader i18n wiring here remains useful but is too wide/dirty to merge as-is. The remaining shape I would want is still a fresh narrow branch from current main, one UI surface at a time, with model-facing text pinned to English and shipped-locale coverage kept complete. I will keep this PR credited as part of the i18n direction.

Hmbown avatar Jun 06 '26 02:06 Hmbown

I don't know why I haven't gotten this done yet. i'm so sorry @gordonlu ! will get this in version 0.8.61

Hmbown avatar Jun 15 '26 05:06 Hmbown

I don't know why I haven't gotten this done yet. i'm so sorry @gordonlu ! will get this in version 0.8.61

No worries at all, take your time. Really appreciate you keeping me updated. Happy to help however works best.

gordonlu avatar Jun 15 '26 09:06 gordonlu

Thanks @gordonlu — your contribution landed in 28bde4aa2926 on main:

feat(tui): localize /mode picker and composer Vim indicator

Closing this PR now that the code is on main. Credit lives in the commit message and (where applicable) the CHANGELOG.md entry for the next release. Apologies for not closing this at the time of the merge — the auto-close workflow is new in v0.8.31.

If you want to land more work and would prefer your future PRs merge cleanly without a harvest step, the CONTRIBUTING.md doc has a short note on what makes a contribution mergeable as-is.

github-actions[bot] avatar Jun 24 '26 03:06 github-actions[bot]