Files
soundcraft/docs/localization-zh-hans.md
SuperiorandFredApps 60950ba884 Localization: Simplified Chinese catalogs on the shared localization module (#783)
* Add the Simplified Chinese catalog to the shared localization module

English source text stays the key: crates/ui-egui/locales/zh-Hans/mod.rs is generated from
crates/ui-egui/src/i18n/zh-hans.tsv (1,383 strings) by docs/i18n/tools/gen_zh_hans_locale.py, so a
translator edits one TSV row per string and the module follows. The TSV is also the file
storytold/craft-i18n's sync script reads, so the catalog can move there when SoundCraft cuts over.

The catalog covers every string passed to localization::text / localized_format! in the crate and
every reference menu label (crates/engine/catalog/menus.txt). Tests compare placeholders against the
English source, reject duplicate keys and name any untranslated string by file. Engine diagnostics
stay English by design: a half-translated error reads worse than a whole one.

Language::SimplifiedChinese ("zh-Hans") joins the enum, the Appearance menu and the ui.language
command, and the choice is saved with the UI state like the theme. AI-authored from the English
source; native-speaker review is still pending.

* Add a Han font fallback for Chinese on the desktop and the web

egui's bundled faces carry no Han glyphs, so a Chinese interface and Chinese session, track and clip
names would draw boxes. fonts.rs now appends a Han fallback to every family:

- desktop: the operating system's own face, resolved through fontconfig with lang=zh-cn plus a list
  of per-platform candidates (PingFang, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, WenQuanYi,
  ...). Nothing is redistributed.
- web: the browser cannot reach system fonts, so the build embeds assets/fonts/NotoSansSC-SoundCraftSubset.ttf,
  a 1.1 MiB Open Font License subset of Noto Sans SC pinned at weight 400.

Han is ordered before the Hangul fallback for every interface language except Korean: the first face
with a glyph wins, and on Linux fontconfig often resolves Noto Sans CJK's Korean face, whose Han
glyphs are Korean-styled. Tests check the ordering, that every family draws Han when a system font
is present, that the bundled face draws the whole zh-Hans catalog in every family, and that it stays
inside its 2 MiB budget. ATTRIBUTION.md records the font and its OFL text; cargo xtask assets
enforces that.

* Document the zh-Hans catalog and refresh the localization numbers

docs/localization.md now describes what ships today (the Language enum, locales/<tag>/mod.rs,
text / localized_format! / error_text, the TSV-to-module step, the Han fallback, the tests) instead
of the packed-catalog design the branch carried before upstream landed the shared localization
module. docs/localization-zh-hans.md is the translator workflow; docs/i18n/glossary.md records the
wording decisions without citing another product's catalogs, and the earlier cross-corpus research
files are gone: the repository's clean-room rule forbids reading GPL translation sources, so the
terminology stands on its own reasoning.

ROADMAP.md, docs/roadmap.md, docs/localization-parity.md and docs/gaps.md move zh-Hans from "none"
to shipped-for-fixed-strings with native review pending, note the CJK fallback, and lower the
localization estimate from 70-110 h to 55-90 h.

* Align the localization numbers and the catalog-editing guidance

The localization row in docs/target-app-parity.md still listed pt-BR only, ~12 % and 70-110 h; the
G-09 row kept the old 20-40 h. Both now match ROADMAP.md, docs/roadmap.md and
docs/localization-parity.md: two shipped catalogs, ~19 %, 55-90 h to the target's eight languages.

Also, docs/localization-parity.md no longer tells a reader to add a Rust arm for every catalog: pt-BR
is hand-written, zh-Hans is generated from its TSV, and the two are now described separately. The
font regeneration commands in docs/localization.md and docs/localization-zh-hans.md name the input
the subset script requires (a Noto Sans SC variable font) instead of implying it runs with no
argument.

* zh-Hans: keep the slot and track order in "Insert {} for {}"

---------

Co-authored-by: FredApps <[email protected]>
2026-11-28 23:40:00 +01:00

5.6 KiB

Simplified Chinese UI

SoundCraft's interface can be shown in 简体中文. The catalog is compiled into the binary (crates/ui-egui/locales/zh-Hans/mod.rs), so there is nothing to install and no locale files to find at run time. It covers every string the UI looks up literally — menu items and path segments, command labels, dialogs, window titles, tooltips, status-bar and accessibility text and the formatted messages — and every reference menu label in crates/engine/catalog/menus.txt. Engine diagnostics and machine-facing surfaces stay English (see What is translated).

The mechanism is described in localization.md; wording decisions are in i18n/glossary.md.

Selecting the language

Setup ▸ Appearance ▸ Language lists English and 简体中文. Choosing a language applies immediately — menus, panels, dialogs and window titles switch on the next frame, no restart.

Without the window, use the command:

soundcraft-cli run --demo --cmd 'ui.language={"language":"zh-Hans"}'

ui.language with no parameter reports the current language ({"language":"en"}), and an unknown tag is an error. The choice is a global preference saved with the UI state (like the theme), so it survives a restart; recalling a saved window configuration never changes it. In the browser the interface starts from navigator.language, and the saved preference wins once one exists.

What is translated

English source strings stay in the code and are the lookup keys; the catalog maps them at draw time. Command ids, menu paths used for lookup, preference keys and values, file formats, the control protocol, the CLI and MCP never see translated text, and neither do values built at run time (file, track and device names) or third-party plugin names.

Engine error messages stay English: a half-translated diagnostic is worse than a whole one, and the error_text templates pt-BR carries are deliberately omitted here.

Files

Path What
crates/ui-egui/src/i18n/zh-hans.tsv the translator-facing catalog: context<TAB>English<TAB>translation, escapes \n, \t, \\
crates/ui-egui/locales/zh-Hans/mod.rs generated from the TSV; the UI reads this
docs/i18n/tools/gen_zh_hans_locale.py regenerates the module (--check fails when stale)
assets/fonts/NotoSansSC-SoundCraftSubset.ttf web-only Han font subset, OFL-1.1
docs/i18n/tools/subset_web_font.py regenerates the subset from the catalog's glyphs

Editing translations

# 1. edit crates/ui-egui/src/i18n/zh-hans.tsv (one row per string)
python3 docs/i18n/tools/gen_zh_hans_locale.py   # 2. regenerate the module
cargo test -p soundcraft-ui-egui --lib          # 3. catalog and font tests

Keep the English placeholders ({name}, {}, {ms:.1}) exactly as they are: a test compares them. Rows are keyed by the English source, so rewording English text requires updating the row with it. @plural rows pair singular|plural on one row because Chinese has no plural inflection.

Look the result up, don't guess: cargo run -p soundcraft-ui-egui --example ui_shot -- out.png with a script that sets the language, then read the PNG (and the accessibility tree) before claiming a screen is right.

Terminology

The short table; the reasoning is in i18n/glossary.md.

English 中文 Note
Session 会话
Track 轨道 audio and MIDI alike; 音轨 reads as audio only
Clip 片段
Bus 总线
Transport 走带 standard audio-engineering word
Pan 声像 规范 acoustics term
Bypass 旁通
Record 录音 Record Enable = 启用录音
Preferences 首选项
Bounce 导出
Slip / Spot 滑动 / 定位
Meter (level) / Meter (time signature) 电平表 / 拍号 two senses, two words
Undo / Redo 撤销 / 重做

Fonts

egui's bundled faces carry no Han glyphs, so crates/ui-egui/src/fonts.rs appends a Han fallback in every family: the operating system's own face on the desktop (fontconfig lang=zh-cn, plus per-platform candidates), and the bundled Noto Sans SC subset in the browser, which has no system fonts. Han is ordered before the Hangul fallback for every language except Korean, so Chinese text never draws Korean-styled shapes on Linux where fontconfig resolves Noto Sans CJK's Korean face first.

The web subset is 1.1 MiB and must stay under 2 MiB (test-enforced). After a catalog change, rebuild it from a Noto Sans SC variable font (a noto-cjk release, Sans/Variable/OTF) and check the result:

# <font>: a Noto Sans SC variable font (family "Noto Sans SC", wght axis) from a noto-cjk release
python3 docs/i18n/tools/subset_web_font.py <font>   # writes assets/fonts/…
python3 docs/i18n/tools/subset_web_font.py --check  # fails on drift

The test that draws the whole catalog in every family fails until the subset covers the new characters.

Validation

  • every localized source string has a zh-Hans entry (test lists what is missing);
  • placeholders match the English source, keys are unique, every menu label is covered;
  • the bundled web face draws the whole catalog in every family and fits its budget;
  • with a system Han font installed, every family draws 轨道片段混音.

Known gaps

  • Engine diagnostics stay English.
  • No native-speaker review yet; the catalog is AI-authored and should be read by a Chinese-speaking audio engineer before it is called finished.
  • Traditional Chinese (zh-Hant) is not shipped; the Han face list is Simplified-first.
  • No IME testing beyond what the platform provides, and no complex-script shaping (egui has none).