[PR #2164] [CLOSED] web: runtime i18n layer (English + Chinese), zero markup changes #3895

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2164
Author: @sdjger-xiaoniu
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: webui-i18n


📝 Commits (3)

  • 8f3b290 web: load the runtime i18n script in index.html
  • 248fc92 web: load the runtime i18n script in monitor.html
  • 2539812 web: add a runtime i18n layer (en + zh), no markup changes

📊 Changes

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

View changed files

➕ serve/web/i18n.js (+435 -0)
📝 serve/web/index.html (+2 -0)
📝 serve/web/monitor.html (+2 -0)

📄 Description

What

The web UI is English-only. This adds a runtime translation layer so the interface
follows the browser language, with no changes to the existing markup or logic —
index.html and monitor.html each gain a single <script> line.

Why runtime translation instead of editing the strings

  1. Zero intrusion. The existing HTML and app.js are untouched, so this cannot
    change behaviour, layout or the English text (English is the identity locale:
    no entry means "show the source string as written").
  2. It also covers runtime strings. app.js builds a lot of the interface at
    runtime (statuses, metric labels, toasts, request rows). Those strings never
    appear in the static HTML, so a markup-level approach would miss them.
    A MutationObserver keeps translating as the page re-renders.
  3. Adding a language is one object. LOCALES in serve/web/i18n.js — copy zh
    and translate the values. Nothing else changes.

How it picks a language

navigator.language (zh* → Chinese, otherwise English), with a manual override
kept in localStorage:

StrataI18N.getLang()        // "en" | "zh"
StrataI18N.listLangs()      // ["en", "zh"]
StrataI18N.setLang('zh')    // remembers and reloads
StrataI18N.t('Chat')        // translate a string on demand

Matching order

  1. exact match against the locale table
  2. regex patterns for strings that carry numbers
    (Generating · 42.1 tok/s → 生成中 · 42.1 tok/s)
  3. a guarded partial pass, with word boundaries, for labels app.js assembles
    from fragments (Done, Speed, Power, 6 cores · 12 threads)

Technical terms stay in English on purpose: GPU, VRAM, PCIe, Gen3,
tok/s, MB/s, W, °C, and the product name Strata.

Scope

  • Chinese covers the whole chat view, the monitor view, the About/settings view,
    the sampling drawer and the API Monitor page (~300 entries).
  • English output is byte-identical to today's UI.

Testing

Loaded against a local 0.1.43.1 install: chat, monitor, sampling drawer and
/api-monitor all render in Chinese; switching back to English restores the
original strings.


🔄 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/2164 **Author:** [@sdjger-xiaoniu](https://github.com/sdjger-xiaoniu) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `webui-i18n` --- ### 📝 Commits (3) - [`8f3b290`](https://github.com/Niko1221/Strata/commit/8f3b290aafa34bc3f654bfa15d55c42688761b6c) web: load the runtime i18n script in index.html - [`248fc92`](https://github.com/Niko1221/Strata/commit/248fc922729fa7cdb928537b6bc1ecce882861ff) web: load the runtime i18n script in monitor.html - [`2539812`](https://github.com/Niko1221/Strata/commit/25398120b9a166c669f061ca82a72cc0134b4872) web: add a runtime i18n layer (en + zh), no markup changes ### 📊 Changes **3 files changed** (+439 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `serve/web/i18n.js` (+435 -0) 📝 `serve/web/index.html` (+2 -0) 📝 `serve/web/monitor.html` (+2 -0) </details> ### 📄 Description ## What The web UI is English-only. This adds a **runtime translation layer** so the interface follows the browser language, with **no changes to the existing markup or logic** — `index.html` and `monitor.html` each gain a single `<script>` line. ## Why runtime translation instead of editing the strings 1. **Zero intrusion.** The existing HTML and `app.js` are untouched, so this cannot change behaviour, layout or the English text (English is the identity locale: no entry means "show the source string as written"). 2. **It also covers runtime strings.** `app.js` builds a lot of the interface at runtime (statuses, metric labels, toasts, request rows). Those strings never appear in the static HTML, so a markup-level approach would miss them. A `MutationObserver` keeps translating as the page re-renders. 3. **Adding a language is one object.** `LOCALES` in `serve/web/i18n.js` — copy `zh` and translate the values. Nothing else changes. ## How it picks a language `navigator.language` (`zh*` → Chinese, otherwise English), with a manual override kept in `localStorage`: ```js StrataI18N.getLang() // "en" | "zh" StrataI18N.listLangs() // ["en", "zh"] StrataI18N.setLang('zh') // remembers and reloads StrataI18N.t('Chat') // translate a string on demand ``` ## Matching order 1. exact match against the locale table 2. regex patterns for strings that carry numbers (`Generating · 42.1 tok/s` → `生成中 · 42.1 tok/s`) 3. a guarded partial pass, with word boundaries, for labels `app.js` assembles from fragments (`Done`, `Speed`, `Power`, `6 cores · 12 threads`) Technical terms stay in English on purpose: `GPU`, `VRAM`, `PCIe`, `Gen3`, `tok/s`, `MB/s`, `W`, `°C`, and the product name `Strata`. ## Scope - Chinese covers the whole chat view, the monitor view, the About/settings view, the sampling drawer and the API Monitor page (~300 entries). - English output is **byte-identical** to today's UI. ## Testing Loaded against a local 0.1.43.1 install: chat, monitor, sampling drawer and `/api-monitor` all render in Chinese; switching back to English restores the original strings. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:31:30 +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#3895
No description provided.