Pull requests / #2164
#2164 web: runtime i18n layer (English + Chinese), zero markup changes
open · @sdjger-xiaoniu · 0 commentaires · Sur GitHub
BenchmarksSetup & installServer & API
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.
Sur le site
Liens install, modèles, releases.