Issues / #1230
#1230 serve/web: add English / Simplified Chinese (zh-CN) UI localization
open · @btc1000w · 2 Kommentare · Auf GitHub
Beschreibung
## Summary / 概述
Adds a lightweight, dependency-free i18n layer to the Strata web control panel (`serve/web/`), so the UI can render in **English** or **Simplified Chinese (zh-CN)**.
为 Strata 网页控制面板(`serve/web/`)加入一套轻量、无依赖的国际化层,界面可显示 **英文** 或 **简体中文(zh-CN)**。
- Default language is auto-detected: `localStorage["strata.lang"]`, else `navigator.language` starting with `zh` → zh-CN, otherwise English.
- A toggle button in the header (next to the theme button) switches languages at runtime; the choice is remembered.
- **English output is byte-identical to before** — English strings are kept as the fallback text, so nothing changes for existing users.
## Files / 改动文件
| File | Change |
|---|---|
| `serve/web/i18n.js` | new — runtime (`t`, `apply`, `setLang`, `onChange`) |
| `serve/web/i18n.en.js` | new — English dictionary |
| `serve/web/i18n.zh-CN.js` | new — Simplified Chinese dictionary |
| `serve/web/index.html` | `data-i18n*` attributes, script tags, language button |
| `serve/web/app.js` | dynamic strings via `t()`; `/config` help via `about.cfg.help.<key>` |
| `serve/web/monitor.html` | `data-i18n*` attributes + script tags |
| `serve/web/monitor.js` | dynamic strings via `t()` |
`tokens.css`, `components.css`, `app.css`, `sprite.svg` are **untouched** (SHA-256 identical to upstream).
## Runtime API
```js
window.StrataI18N = {
lang, // "en" | "zh-CN"
available: ["en", "zh-CN"],
t(key, vars), // current dict -> en fallback -> key; {name} interpolation
apply(root = document), // data-i18n / -html / -title / -placeholder / -aria; sets <html lang>
setLang(lang), // persists to localStorage, applies, dispatches "strata:lang"
onChange(cb) // document listener for "strata:lang"
};
```
## Verification / 验证
- Playwright (Chromium): `document.documentElement.lang === "zh-CN"`; header tabs, chat, monitor, about and the runtime-generated **Model settings** form all render Chinese; English still renders exactly as before.
- `node --check` clean on all five JS files.
- Only console message is a pre-existing `favicon.ico` 404.
- All 90 element ids in `index.html` preserved; one id added (`lang-btn`); no class changes, so no layout regression.
## Patch
A `git format-patch` patch (against `main` `82f46a8c8f475f001ad76d92f58f4a4f8ffb0253`, v0.1.40.1) is available — 7 files changed, +1227 / -269.
```sh
git checkout -b i18n-zh-cn 82f46a8c8f475f001ad76d92f58f4a4f8ffb0253
git am 0001-serve-web-add-en-zh-CN-i18n-with-automatic-language-.patch
git push -u origin i18n-zh-cn
```
I can attach the patch file here or open a PR if you prefer.
---
Happy to adjust naming, split the dictionaries, or add more languages if you want.Mehr auf der Site
Links zu Install, Modellen, Releases.