[PR #3293] [CLOSED] [GUI] serve: a Chinese / English language switch for the web app (adapted to 0.2.6) #4550

Closed
opened 2026-11-07 15:37:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3293
Author: @hogtinbao
Created: 10/19/2026
Status: ❌ Closed

Base: main ← Head: web-ui-zh


📝 Commits (1)

  • 87fbf2e serve: a Chinese / English language switch for the web app (adapted to 0.2.6)

📊 Changes

3 files changed (+747 additions, -0 deletions)

View changed files

➕ serve/web/i18n-zh.js (+745 -0)
📝 serve/web/index.html (+1 -0)
📝 serve/web/monitor.html (+1 -0)

📄 Description

Problem and result

The web UI in serve/web/ is English-only. On a Chinese Windows install the settings page, the sampling drawer, the monitor table and even the server's own validation errors are unreadable to the person running the model, and there is no hook to translate them without editing app.js / monitor.js — files upstream rewrites regularly.

This PR adds a self-contained translation layer that is opt-in at runtime: one new file serve/web/i18n-zh.js plus one <script> line in each page. A Language control in the header switches between English, 简体中文 and 中英文 (Chinese with the English original in small type beneath it). The default stays English, so anyone who never touches the control sees the current UI. Model output is never rewritten — chat bubbles, thinking, code blocks and tool-call payloads are in the skip list.

This replaces #1836 — the earlier revision of this change (adapted to v0.1.45), closed by the 0.2.0-beta tracker reset, not on merit. /reopen on that PR failed with Validation Failed after the branch was force-pushed to this revision, so this is a fresh pull request with the same change.

Current revision: rebased onto 4b9e05a2 (= tag v0.2.6) and re-checked against every serve/web, serve/runconfig.py, serve/telemetry.py and serve/frontend.py change since the 0.2.0-beta base e88ee39d (969 commits, four of them touching serve/web/).

Since the 0.2.0-beta revision

The upstream diff between e88ee39d and v0.2.6 adds exactly these user-visible strings, and all of them are covered now:

  • serve/web/app.js (#3435, "use an edited API key at once, even when browser storage is blocked"): two new toasts — API key used for this page only and Browser storage is unavailable. Enter it again after reloading. Both are dictionary entries. The other three serve/web/ commits in that range (#3594, #3601, #2971) only touch CSS and DOM structure and add no text; index.html and monitor.html are byte-identical to the base revision.
  • serve/runconfig.py: one new editable key, mtp (draft layer). Its help sentence is in the dictionary as data (like the other 15), and mtp has a gloss in the monospace key table (草稿层(MTP)).
  • serve/frontend.py: three client-visible rejections the page prints verbatim — a reasoning effort outside the family's list (… use none, low, medium, high, max or 1..100, both the numeric and the word form), an empty message list, and a whitespace tool name. All three are regex rules now. The rest of that file's new text is docstrings and comments, which no page shows.
  • serve/telemetry.py is unchanged since the base revision.
  • Re-added 0 · greedy: the readout app.js shows at temperature 0. It was in the v0.1.45 revision (#1836) and went missing when this file was rebuilt for 0.2.0-beta; app.js still renders that exact label, so the entry is back.

Approach

  • One new file, no build step, no edits to app.js, monitor.js or app.css; each page gets a single script tag. If the file is absent the pages behave exactly as today.
  • A dictionary for static strings plus regex rules for text that carries numbers (56.9 tok/s, 3,201 tokens · 12.3 tok/s, Saved (…); the earlier file is ….bak. Start the model again to use it.). A MutationObserver translates nodes the pages create later, and title / placeholder / aria-label / <option> text is translated too.
  • Both languages stay in the DOM and CSS picks one, so switching back to English restores the original page (attributes and option labels included).
  • Only user-visible chrome is translated; config values posted to /config remain English (only the option text is translated), so the layer cannot change what the server stores.
  • No new dependency, no network access, ~41 KB, MIT, same license header as the rest of the repo.

Validation

Passed:

  • python -m unittest discover -s serve -p 'test_*.py' on this branch — Windows 11, Python 3.12.10, revision 87fbf2e6 rebased on 4b9e05a2 (v0.2.6): Ran 1035 tests in 413.981s ... FAILED (failures=1, errors=1, skipped=21) (see Failed).
  • Real browser on the 0.2.6 pages: index.html and monitor.html from v0.2.6 with this layer attached (served statically on 127.0.0.1, Edge/Chromium engine): the script loads, <html data-lang> is set, the header gets the Language control, and the tabs read 聊天 / 图片 / 监控 / 关于 with the English original beneath in 中英文 mode; monitor.html translates its own headings; picking English sets data-lang="en" and stores strata.lang="en". The live API was not attached, so only the static chrome was exercised this way (see Not run).
  • node --check serve/web/i18n-zh.js — no syntax errors (re-run on this revision).
  • The file's own dictionary and rules, loaded and evaluated in node, were asked to translate 11 strings: the two new toasts, the new mtp help sentence exactly as runconfig.py concatenates it, the three new frontend.py rejections, and four controls from earlier revisions (0 · greedy, Sampling saved, Prefill t/s, the save-confirmation sentence). All 11 return a translation.
  • Static re-check of the upstream diff: every added/rewritten English string in serve/web, serve/runconfig.py, serve/telemetry.py and serve/frontend.py between e88ee39d and 4b9e05a2 was extracted with a small local script (HTML text nodes, title / placeholder / aria-label, <option>, JS string literals, the EDITABLE help sentences) and matched against the dictionary and the rules; the same diffs were also read by hand, since the extractor is line-based and can miss a string split across lines. What does not match is docstrings, comments, log-only text, DOM ids/classes and the literals that are data (strata. localStorage prefix) — nothing a person reads on the page. The only items deliberately left English are the proper nouns and symbols Strata, Top-p, Top-k.
  • Server error strings round-trip: the eight validation messages from serve/runconfig.py are matched by the layer's rules, plus the three new serve/frontend.py ones.
  • Real server on the 0.2.0-beta revision of this branch: serve/server.py started with the layer attached; /health returned {"status": "ok", "loaded": true, "images": true, "image_generation": true, ...}; a /v1/chat/completions request with reasoning_effort: "none" answered normally (18 tokens, finish_reason: "stop") — the API path is untouched.
  • curl / and curl /api-monitor returned the pages with the added script tag and curl /web/i18n-zh.js served HTTP 200 — recorded on the 0.2.0-beta revision of this branch against the live server; the two script lines are unchanged here and were re-checked by reading the served 0.2.6 pages in the browser pass above.
  • Manual use on this PC since v0.1.40: chat, monitor, image page and the settings page, in all three language modes, light and dark; switching back to English restores the original UI.

Failed:

  • serve/test_winjob.py::test_children_end_with_a_killed_server — TypeError: argument of type 'NoneType' is not iterable at test_winjob.py:32 (the job-object query returns nothing on this machine). Same as on the 0.2.0-beta revision of this branch: environmental, not caused by this change.
  • serve/test_parallel.py::ParallelService::test_benchmark_cancel_suite_releases_batch_queue_and_slots — the cancel_queued step reports target seen False. It reproduces identically on pristine 4b9e05a2 in a clean worktree without this branch (Ran 1 test in 36.7s ... FAILED (failures=1)), so it is base/machine timing behaviour. This branch adds no Python file: serve/web/i18n-zh.js plus one <script> line in each page.

Not run:

  • No browser pass with the live server on this revision. The chrome was checked in a real browser against the 0.2.6 pages served statically (see Passed), but the strings this revision added — the two API-key toasts, the mtp settings row, the three new rejections — only appear when the page talks to a 0.2.6 server, and this machine runs 0.2.0-beta, which does not contain them; they were verified against the exact literals the 0.2.6 files produce instead (node + the static re-check).
  • No automated browser test. Rendering was checked by eye (Edge and Chrome on Windows, 1366×768 and 1920×1080, light and dark, three language modes). Headless --dump-dom hangs against the live page on this machine because it streams /metrics, so there is no scripted UI check in this PR.
  • No Linux or macOS check of the pages. The file is plain DOM code with no platform branches, but I did not run it there.
  • No check of the desktop app (apps/host) — it has its own strings and is untouched here.

Limits

  • Covers the web UI only, not the Tauri app.
  • The translations live in one file that needs a refresh whenever upstream rewords a string; an unmatched string simply stays English (no runtime error). The file is organised by upstream version, so the diff for such a refresh is small.
  • Not a general i18n framework — no locale files, no plural rules. If upstream later wants first-class i18n, this should be replaced by it rather than extended.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3293 **Author:** [@hogtinbao](https://github.com/hogtinbao) **Created:** 10/19/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `web-ui-zh` --- ### 📝 Commits (1) - [`87fbf2e`](https://github.com/Niko1221/Strata/commit/87fbf2e6b5d682b595b2bd3ad9220f43a739d577) serve: a Chinese / English language switch for the web app (adapted to 0.2.6) ### 📊 Changes **3 files changed** (+747 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `serve/web/i18n-zh.js` (+745 -0) 📝 `serve/web/index.html` (+1 -0) 📝 `serve/web/monitor.html` (+1 -0) </details> ### 📄 Description ## Problem and result The web UI in `serve/web/` is English-only. On a Chinese Windows install the settings page, the sampling drawer, the monitor table and even the server's own validation errors are unreadable to the person running the model, and there is no hook to translate them without editing `app.js` / `monitor.js` — files upstream rewrites regularly. This PR adds a self-contained translation layer that is opt-in at runtime: one new file `serve/web/i18n-zh.js` plus one `<script>` line in each page. A `Language` control in the header switches between **English**, **简体中文** and **中英文** (Chinese with the English original in small type beneath it). The default stays English, so anyone who never touches the control sees the current UI. Model output is never rewritten — chat bubbles, thinking, code blocks and tool-call payloads are in the skip list. ## Related discussion This replaces #1836 — the earlier revision of this change (adapted to v0.1.45), closed by the 0.2.0-beta tracker reset, not on merit. `/reopen` on that PR failed with `Validation Failed` after the branch was force-pushed to this revision, so this is a fresh pull request with the same change. **Current revision:** rebased onto `4b9e05a2` (= tag `v0.2.6`) and re-checked against every `serve/web`, `serve/runconfig.py`, `serve/telemetry.py` and `serve/frontend.py` change since the 0.2.0-beta base `e88ee39d` (969 commits, four of them touching `serve/web/`). ## Since the 0.2.0-beta revision The upstream diff between `e88ee39d` and `v0.2.6` adds exactly these user-visible strings, and all of them are covered now: - `serve/web/app.js` (#3435, "use an edited API key at once, even when browser storage is blocked"): two new toasts — `API key used for this page only` and `Browser storage is unavailable. Enter it again after reloading.` Both are dictionary entries. The other three `serve/web/` commits in that range (#3594, #3601, #2971) only touch CSS and DOM structure and add no text; `index.html` and `monitor.html` are byte-identical to the base revision. - `serve/runconfig.py`: one new editable key, `mtp` (draft layer). Its help sentence is in the dictionary as data (like the other 15), and `mtp` has a gloss in the monospace key table (`草稿层(MTP)`). - `serve/frontend.py`: three client-visible rejections the page prints verbatim — a reasoning effort outside the family's list (`… use none, low, medium, high, max or 1..100`, both the numeric and the word form), an empty message list, and a whitespace tool name. All three are regex rules now. The rest of that file's new text is docstrings and comments, which no page shows. - `serve/telemetry.py` is unchanged since the base revision. - **Re-added `0 · greedy`:** the readout `app.js` shows at temperature 0. It was in the v0.1.45 revision (#1836) and went missing when this file was rebuilt for 0.2.0-beta; `app.js` still renders that exact label, so the entry is back. ## Approach - One new file, no build step, no edits to `app.js`, `monitor.js` or `app.css`; each page gets a single script tag. If the file is absent the pages behave exactly as today. - A dictionary for static strings plus regex rules for text that carries numbers (`56.9 tok/s`, `3,201 tokens · 12.3 tok/s`, `Saved (…); the earlier file is ….bak. Start the model again to use it.`). A `MutationObserver` translates nodes the pages create later, and `title` / `placeholder` / `aria-label` / `<option>` text is translated too. - Both languages stay in the DOM and CSS picks one, so switching back to English restores the original page (attributes and option labels included). - Only user-visible chrome is translated; config **values** posted to `/config` remain English (only the option text is translated), so the layer cannot change what the server stores. - No new dependency, no network access, ~41 KB, MIT, same license header as the rest of the repo. ## Validation **Passed:** - `python -m unittest discover -s serve -p 'test_*.py'` on this branch — Windows 11, Python 3.12.10, revision `87fbf2e6` rebased on `4b9e05a2` (`v0.2.6`): `Ran 1035 tests in 413.981s ... FAILED (failures=1, errors=1, skipped=21)` (see **Failed**). - Real browser on the 0.2.6 pages: `index.html` and `monitor.html` from `v0.2.6` with this layer attached (served statically on `127.0.0.1`, Edge/Chromium engine): the script loads, `<html data-lang>` is set, the header gets the `Language` control, and the tabs read 聊天 / 图片 / 监控 / 关于 with the English original beneath in 中英文 mode; `monitor.html` translates its own headings; picking `English` sets `data-lang="en"` and stores `strata.lang="en"`. The live API was not attached, so only the static chrome was exercised this way (see **Not run**). - `node --check serve/web/i18n-zh.js` — no syntax errors (re-run on this revision). - The file's own dictionary and rules, loaded and evaluated in node, were asked to translate 11 strings: the two new toasts, the new `mtp` help sentence exactly as `runconfig.py` concatenates it, the three new `frontend.py` rejections, and four controls from earlier revisions (`0 · greedy`, `Sampling saved`, `Prefill t/s`, the save-confirmation sentence). All 11 return a translation. - Static re-check of the upstream diff: every added/rewritten English string in `serve/web`, `serve/runconfig.py`, `serve/telemetry.py` and `serve/frontend.py` between `e88ee39d` and `4b9e05a2` was extracted with a small local script (HTML text nodes, `title` / `placeholder` / `aria-label`, `<option>`, JS string literals, the `EDITABLE` help sentences) and matched against the dictionary and the rules; the same diffs were also read by hand, since the extractor is line-based and can miss a string split across lines. What does not match is docstrings, comments, log-only text, DOM ids/classes and the literals that are data (`strata.` localStorage prefix) — nothing a person reads on the page. The only items deliberately left English are the proper nouns and symbols `Strata`, `Top-p`, `Top-k`. - Server error strings round-trip: the eight validation messages from `serve/runconfig.py` are matched by the layer's rules, plus the three new `serve/frontend.py` ones. - Real server on the 0.2.0-beta revision of this branch: `serve/server.py` started with the layer attached; `/health` returned `{"status": "ok", "loaded": true, "images": true, "image_generation": true, ...}`; a `/v1/chat/completions` request with `reasoning_effort: "none"` answered normally (18 tokens, `finish_reason: "stop"`) — the API path is untouched. - `curl /` and `curl /api-monitor` returned the pages with the added script tag and `curl /web/i18n-zh.js` served HTTP 200 — recorded on the 0.2.0-beta revision of this branch against the live server; the two script lines are unchanged here and were re-checked by reading the served 0.2.6 pages in the browser pass above. - Manual use on this PC since v0.1.40: chat, monitor, image page and the settings page, in all three language modes, light and dark; switching back to English restores the original UI. **Failed:** - `serve/test_winjob.py::test_children_end_with_a_killed_server` — `TypeError: argument of type 'NoneType' is not iterable` at `test_winjob.py:32` (the job-object query returns nothing on this machine). Same as on the 0.2.0-beta revision of this branch: environmental, not caused by this change. - `serve/test_parallel.py::ParallelService::test_benchmark_cancel_suite_releases_batch_queue_and_slots` — the `cancel_queued` step reports `target seen False`. It reproduces identically on pristine `4b9e05a2` in a clean worktree **without** this branch (`Ran 1 test in 36.7s ... FAILED (failures=1)`), so it is base/machine timing behaviour. This branch adds no Python file: `serve/web/i18n-zh.js` plus one `<script>` line in each page. **Not run:** - No browser pass with the live server on this revision. The chrome was checked in a real browser against the 0.2.6 pages served statically (see **Passed**), but the strings this revision added — the two API-key toasts, the `mtp` settings row, the three new rejections — only appear when the page talks to a 0.2.6 server, and this machine runs 0.2.0-beta, which does not contain them; they were verified against the exact literals the 0.2.6 files produce instead (node + the static re-check). - No automated browser test. Rendering was checked by eye (Edge and Chrome on Windows, 1366×768 and 1920×1080, light and dark, three language modes). Headless `--dump-dom` hangs against the live page on this machine because it streams `/metrics`, so there is no scripted UI check in this PR. - No Linux or macOS check of the pages. The file is plain DOM code with no platform branches, but I did not run it there. - No check of the desktop app (`apps/host`) — it has its own strings and is untouched here. ## Limits - Covers the web UI only, not the Tauri app. - The translations live in one file that needs a refresh whenever upstream rewords a string; an unmatched string simply stays English (no runtime error). The file is organised by upstream version, so the diff for such a refresh is small. - Not a general i18n framework — no locale files, no plural rules. If upstream later wants first-class i18n, this should be replaced by it rather than extended. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:37:21 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4550
No description provided.