Repository navigation
Commit 70a0af5
Translate the Terminal and Logs output (#646)
## Why
The Terminal and the Logs were plain English in a translated window: the
terminal's help and refusals, every line the setup, update and apply
chains write there, the build watch and dev server lines, the Logs' tabs
and empty-pane notes, and main's own lines from the trunk update, the
pull request switch, the npm runner and the server start. This is the
#627 batch of #622.
## What changes
- **Every line written to the Terminal or a Logs pane** goes through
`__`/`_n`/`sprintf`, with commands, paths, keys and file names passed in
as `%s`. Each line is one or more whole sentences, so the terminal can
show a translated line on its own.
- **Sentences that were spliced together are written whole.** The apply
chain built "The ${noun} is ${verb}" and "${verb} — …" from five verb
and noun pairs; it is now a table of whole sentences per pair
(`applyLines` in `watch-activity.cjs`), the way `applyDoneMessage` in
`confirmations.cjs` works. `applyFinishMessage` used to regex the
English "— open the site to try it out." out of a line; the caller now
passes the line without it. The switch progress (`switch-progress.cjs`),
the setup's `Status: ${phase}`, main's `Update failed during ${stage}`
and the npm "letting go" line each get one sentence per case.
- **Inline markup** (the hints under the terminal, the empty Logs panes)
uses `createInterpolateElement`, with `npm run build`, `help`, `Ctrl+C`,
`package.json`, `src/`, `build/` and `error_log()` passed in as
elements.
- **The dev server's "see Help → Open App Log"** takes the menu item as
`%s`, from the same `__('Open App Log')` the menu uses (left over from
#634).
- **Module-level constants became functions:** `COPY_BUTTON_LABELS`,
`SETUP_END_MESSAGES` and the setup status line move from `index.jsx` to
`confirmations.cjs` as `copyButtonLabel`, `setupEndMessage` and
`setupStatusLine`, where the suite can reach them; `STALE_ASSETS` and
main's `ENGINE_RETRY_NOTICE` become functions too.
110 new strings. Not wrapped, per #622 or because the text is not ours:
Git's own progress phases (`Updating files 3/10`), npm's and the
server's output, the stub `appendNpm` buffer nothing shows, the `42%`
progress figure, and the lines owned by sibling batches
(`SKIP_INSTALL_MESSAGE` and the dirty-tree errors are #626's in #636;
the patch apply lines in main are #628's; the blocked-site errors are
#629's).
## How to test this
The new journeys cover both trays in the pseudo-locale. Run them from
the repository root, on either platform:
```
npx playwright test --project=journeys tests/e2e/journeys/i18n.spec.js -g "Terminal is fully|Logs are fully"
```
Both fail without this change (checked by stashing `src/` and
rebuilding). The Terminal journey opens the tray on a built site, reads
the help printed at start, types `help` and an unknown command, joins
the terminal's rows into whole lines and checks every printed line
starts with `[`, then scans the hints under it. The Logs journey scans
the empty Build watch and Debug.log panes, starts the dev server with
stubbed handlers so the watch starts and the server refuses, and scans
the server's failure line, the watch's start and exit lines and the tab
titles as they change.
What the journeys cannot reach: they stub IPC, so main's lines (trunk
update, PR switch, npm runner, server start) never reach the screen in
them, and neither do the apply, update and setup chains, which need a
real install and build. Unit tests cover those in the pseudo-locale
instead: `watch-activity`, `update-handoff`, `dev-server-command`,
`switch-progress`, `confirmations`, `trunk-update-fetch.integration` and
three in `ipc-wiring` (the server's start failure, the trunk update's
failure lines and the engine retry notice). To see the chains on screen
by hand (either platform, current head):
1. From the repository root, run `npx electron . --lang=en-XA`.
2. Open a built Core site, open the **Terminal** tray and type `help`.
- Expected: every line except the `$` prompt is accented and in
brackets, and the help's descriptions still start in one column.
3. Click **Update to latest trunk** (in its pseudo-localised form) and
let it run.
- Expected: the lines the app writes ("Fetching latest trunk…", "Now on
trunk as of …", "Running npm run build…", "Update complete — …") are
bracketed; Git's and npm's own output is not.
**What must not have happened:** no English an English speaker sees has
changed, apart from the one line break and the one plural named in
Risks. All 132 journeys pass with their exact English strings, including
`terminal.spec.js`, `tray.spec.js`, `logs.spec.js`,
`build-watch.spec.js` and `dev-server.spec.js`.
## Risks and limitations
- Two changes to the English, both forced by the rules: the help's last
paragraph was one sentence broken over two lines with a `\n`, which a
translated string cannot hold, so it is now two sentences on two lines
("…npm run build once." / "Run them here whenever…");
`LONGEST_HELP_LINE` in `terminal.spec.js` follows it. And the switch
progress said "1 files"; with `_n` it says "1 file".
- Merge conflicts with the other open batches: #643, #636 and the
parallel #628 and #629 all append tests to the end of `i18n.spec.js`
(#635 did too; this branch is rebased on it). #636 also adds `import {
__ }` to `use-dev-server.jsx` and `sprintf` to `index.jsx`'s import,
where this branch adds `sprintf` too; those lines will need a one-line
resolution, whichever merges second.
- Main's PR-switch lines and `npmLetGoLine` in `main.js` are covered
only by `npm run i18n:pot` extracting them and lint checking their
comments; the trunk update, server start and engine retry lines have
`ipc-wiring` tests.
- Still English in the terminal during an apply: the lines owned by #628
(main's "Applying …" and the `patch-apply.js` lines) and #626's
`SKIP_INSTALL_MESSAGE` (in #636). They land with those batches.
- The diff is about 870 lines, over the ~800 guideline. Most of it is
the per-case sentence table and tests; it is one tray's worth of strings
and did not split cleanly.
- Review: 3 [fix here], all fixed; 3 [follow-up], deferred (see the
review outcome).
## Related
Fixes #627. Part of #622. Follows #634 and #635.
---
<details>
<summary>Design decisions and alternatives considered</summary>
- **The help's columns.** Each help line is one string, `%s Show this
help text`, with the command padded into `%s`, so every printed line
opens with the translated string's bracket and the descriptions still
line up after the command column. The alternative, a translated
description after an untranslated command, would leave each line
starting in English.
- **The apply sentences as a table**, not a frame like "%1$s but the
build failed": a translation cannot rely on "The patch is applied"
fitting in front of "but". The two `Restored` lines share their English
but have a `_x` context per noun, so a language with gendered
participles can say them differently.
- **"Start the build watch, or run %s in the Terminal."** is its own
sentence after the one saying the site still runs the old assets,
instead of being copied into ten strings.
- **Setup status per phase:** main sends only `cloning` and `done`; each
gets its own line and anything else says "Status update", where it used
to print the code.
- **`Debug.log` and `Debug.log (%d)`** are wrapped so a translator can
name the tab in their language; the file name in sentences is left as
is.
</details>
<details>
<summary>Review outcome (required — see AGENTS.md)</summary>
3 [fix here] · 3 [follow-up]. All 3 [fix here] findings are fixed.
- 🟡 `copyButtonLabel`, `setupStatusLine` and `setupEndMessage` were
branches choosing user-facing sentences inside `index.jsx`, which the
suite cannot load. Fixed: moved to `confirmations.cjs` with a test in
English and in the pseudo-locale.
- 🔵 `engineRetryNotice` was made a function so it is translated when
shown, and nothing checked it. Fixed: an `ipc-wiring` test drives the
engine retry in the pseudo-locale.
- 🔵 The Terminal journey dropped any line starting with `[`, so
translated text followed by English would pass. Fixed: each line must be
one bracketed string from its first character to its last.
- Follow-up: the apply flow in the terminal is still partly English
(main's "Applying …" line, `patch-apply.js`, `SKIP_INSTALL_MESSAGE`).
Those belong to #628 and #626 (#636), not this batch.
- Follow-up: the five `compiling` sentences in `applyLines` repeat
`compilingMessage()`'s text, on purpose, so each can be translated
whole; the test now pins all five against `compilingMessage()`.
- Follow-up: `npmLetGoLine` reads `process.platform`, so only one
platform's branch runs in a test. The split was already inline before
this branch; injecting the platform is a separate change.
- One review note was checked and not taken: it said the renderer no
longer imports `switch-progress.cjs`, but `index.jsx` still does, so
that module's header comment stays.
- **Review:** completed. Fresh agent context (Explore subagent given the
diff and the review instructions), head `c7a1ba8` / base `9fd167e`. Lint
clean, `npm test` passing, read-only, so it did not run the journeys.
- **Since review:** `c7a1ba8 → 274bb2d`. The review fixes above, then a
rebase onto trunk `e94f507` after #635 merged (only `i18n.spec.js`
conflicted: both appended tests). Checked by the authoring session, not
re-reviewed by a fresh context: `npm run lint` clean, `npm test` 2044
pass / 0 fail, all 132 journeys pass, `npm run i18n:pot` clean.
- **After CI:** `274bb2d → 6179bd9`. The Terminal journey failed on CI's
macOS runner: it waited for the help's first line, which on that window
had scrolled out of the rows xterm draws, because pseudo-locale lines
are longer and wrap. It now waits for the help's last line. Reproduced
locally at 1024×640 (failed before, passes after). Test-only change,
checked by the authoring session, not re-reviewed: the i18n and terminal
journeys pass (20).
</details>
<details>
<summary>Screenshots or recording</summary>
None. Nothing changes on screen in English beyond the help's line break,
and the pseudo-locale journeys are the check for the translated state.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Francesco Bigiarini <francesco.bigiarini@gmail.com>1 parent fbb96c6 commit 70a0af5
24 files changed
Lines changed: 875 additions & 173 deletions
File tree
- src
- renderer
- components
- hooks
- tests
- e2e/journeys
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
2075 | 2075 | | |
2076 | 2076 | | |
2077 | 2077 | | |
2078 | | - | |
| 2078 | + | |
| 2079 | + | |
2079 | 2080 | | |
2080 | 2081 | | |
2081 | 2082 | | |
| |||
2160 | 2161 | | |
2161 | 2162 | | |
2162 | 2163 | | |
2163 | | - | |
| 2164 | + | |
| 2165 | + | |
2164 | 2166 | | |
2165 | 2167 | | |
2166 | 2168 | | |
| |||
2199 | 2201 | | |
2200 | 2202 | | |
2201 | 2203 | | |
2202 | | - | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
2203 | 2216 | | |
2204 | 2217 | | |
2205 | 2218 | | |
| |||
2209 | 2222 | | |
2210 | 2223 | | |
2211 | 2224 | | |
2212 | | - | |
2213 | | - | |
2214 | | - | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
2215 | 2234 | | |
2216 | 2235 | | |
2217 | 2236 | | |
| |||
2327 | 2346 | | |
2328 | 2347 | | |
2329 | 2348 | | |
2330 | | - | |
| 2349 | + | |
2331 | 2350 | | |
2332 | 2351 | | |
2333 | 2352 | | |
| |||
2340 | 2359 | | |
2341 | 2360 | | |
2342 | 2361 | | |
2343 | | - | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
2344 | 2366 | | |
2345 | 2367 | | |
2346 | 2368 | | |
| |||
2360 | 2382 | | |
2361 | 2383 | | |
2362 | 2384 | | |
2363 | | - | |
| 2385 | + | |
2364 | 2386 | | |
2365 | 2387 | | |
2366 | 2388 | | |
| |||
2602 | 2624 | | |
2603 | 2625 | | |
2604 | 2626 | | |
2605 | | - | |
| 2627 | + | |
2606 | 2628 | | |
2607 | 2629 | | |
2608 | 2630 | | |
| |||
3609 | 3631 | | |
3610 | 3632 | | |
3611 | 3633 | | |
3612 | | - | |
| 3634 | + | |
| 3635 | + | |
| 3636 | + | |
| 3637 | + | |
| 3638 | + | |
| 3639 | + | |
| 3640 | + | |
| 3641 | + | |
| 3642 | + | |
| 3643 | + | |
| 3644 | + | |
| 3645 | + | |
| 3646 | + | |
| 3647 | + | |
| 3648 | + | |
| 3649 | + | |
| 3650 | + | |
| 3651 | + | |
| 3652 | + | |
| 3653 | + | |
| 3654 | + | |
| 3655 | + | |
3613 | 3656 | | |
3614 | 3657 | | |
3615 | 3658 | | |
| |||
3654 | 3697 | | |
3655 | 3698 | | |
3656 | 3699 | | |
3657 | | - | |
| 3700 | + | |
| 3701 | + | |
3658 | 3702 | | |
3659 | 3703 | | |
3660 | 3704 | | |
| |||
3693 | 3737 | | |
3694 | 3738 | | |
3695 | 3739 | | |
3696 | | - | |
| 3740 | + | |
| 3741 | + | |
| 3742 | + | |
| 3743 | + | |
| 3744 | + | |
3697 | 3745 | | |
3698 | 3746 | | |
3699 | 3747 | | |
| |||
3727 | 3775 | | |
3728 | 3776 | | |
3729 | 3777 | | |
3730 | | - | |
| 3778 | + | |
3731 | 3779 | | |
3732 | 3780 | | |
3733 | 3781 | | |
| |||
3753 | 3801 | | |
3754 | 3802 | | |
3755 | 3803 | | |
3756 | | - | |
| 3804 | + | |
3757 | 3805 | | |
3758 | 3806 | | |
3759 | 3807 | | |
| |||
3999 | 4047 | | |
4000 | 4048 | | |
4001 | 4049 | | |
4002 | | - | |
| 4050 | + | |
| 4051 | + | |
| 4052 | + | |
| 4053 | + | |
| 4054 | + | |
| 4055 | + | |
| 4056 | + | |
| 4057 | + | |
| 4058 | + | |
4003 | 4059 | | |
4004 | 4060 | | |
4005 | 4061 | | |
| |||
4025 | 4081 | | |
4026 | 4082 | | |
4027 | 4083 | | |
4028 | | - | |
| 4084 | + | |
| 4085 | + | |
| 4086 | + | |
4029 | 4087 | | |
4030 | 4088 | | |
4031 | 4089 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| |||
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
48 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
49 | 59 | | |
50 | 60 | | |
51 | 61 | | |
| |||
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
57 | | - | |
| 67 | + | |
58 | 68 | | |
59 | | - | |
| 69 | + | |
60 | 70 | | |
61 | | - | |
| 71 | + | |
62 | 72 | | |
63 | 73 | | |
64 | 74 | | |
| |||
0 commit comments