Files
codewhale/crates
Hunter Bown d62facafac feat(translate): opt-in /translate command localises model replies
Two-layer design for users whose UI locale is not English:

1. **System-prompt directive (primary)**: when the user enables
   translation via `/translate`, a `## Language Output Requirement`
   block is appended to the system prompt instructing the model to
   reply in the resolved session locale (Simplified Chinese,
   Traditional Chinese, Japanese, or Brazilian Portuguese). Code
   identifiers, technical terms without an established translation,
   and code blocks the user explicitly requests in English are
   exempt. The block is gated on `PromptSessionContext.translation_
   enabled`, so it adds zero tokens for installs that don't opt in.

2. **Post-hoc heuristic (fallback)**: a lightweight detector in
   `tui::translation` compares Latin-letter count against weighted
   CJK characters (CJK chars carry ~3× the information per glyph,
   so the ratio comparison stays fair across mixed code+prose).
   When a reply still surfaces English despite the directive, the
   detector flags it and a focused per-message `client.translate()`
   call renders the localised version before display. The dedicated
   translation request runs without conversation history, tool
   calls, or streaming — the only role is translate-and-return.

Adds the `/translate` slash command, locale strings for the new UI
states, the post-hoc fallback module, the per-message
`TranslationStatus`, and threading through `core::ops`,
`core::engine`, `runtime_threads`, and the TUI app/UI surface.

Trust-boundary check: opt-in only — `translation_enabled` defaults
to false everywhere, so English-locale installs see zero behaviour
change. The system prompt addition is conditional on the runtime
flag, not the contributor's earlier always-on form. Threaded the
new `Locale::ZhHant` arm through the v0.8.32 `/change` slash
command match to keep the pattern exhaustiveness check passing.

Harvested from PR #1462 by @YaYII

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 00:46:50 -05:00
..
2026-05-11 23:07:02 -05:00
2026-05-11 23:07:02 -05:00
2026-05-11 23:07:02 -05:00
2026-05-11 23:07:02 -05:00
2026-05-11 23:07:02 -05:00
2026-05-11 23:07:02 -05:00