mirror of
https://github.com/storytold/soundcraft.git
synced 2026-12-02 10:37:29 -06:00
* 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 <153173854+FredApps@users.noreply.github.com>
121 lines
6.3 KiB
Markdown
121 lines
6.3 KiB
Markdown
# Localization
|
|
|
|
SoundCraft's interface ships in English and 简体中文 (Simplified Chinese), and English source text
|
|
is the key: the strings in the code are what the catalogs translate, so a missing translation falls
|
|
back to readable English instead of an empty label. Catalogs are compiled into the binary; a
|
|
release has no catalog files to install or find, and the web build carries them too.
|
|
|
|
This page describes the mechanism. For the Chinese catalog itself see
|
|
[`localization-zh-hans.md`](localization-zh-hans.md); for terminology see
|
|
[`i18n/glossary.md`](i18n/glossary.md); for coverage against the incumbent see
|
|
[`localization-parity.md`](localization-parity.md).
|
|
|
|
## Supported languages
|
|
|
|
| Language | Code | Catalog | Notes |
|
|
|---|---|---|---|
|
|
| English (source) | `en` | — (the strings live in the code) | fallback for every catalog |
|
|
| 简体中文 — Simplified Chinese | `zh-Hans` | [`crates/ui-egui/locales/zh-Hans/mod.rs`](../crates/ui-egui/locales/zh-Hans/mod.rs) | generated from [`zh-hans.tsv`](../crates/ui-egui/src/i18n/zh-hans.tsv) |
|
|
| Português (Brasil) — Portuguese (Brazil) | `pt-BR` | [`crates/ui-egui/locales/pt-BR/mod.rs`](../crates/ui-egui/locales/pt-BR/mod.rs) | hand-written |
|
|
|
|
The registry is the `Language` enum in
|
|
[`crates/ui-egui/src/localization.rs`](../crates/ui-egui/src/localization.rs): `ALL` is the order
|
|
the Appearance window offers, `id()` is the tag stored in preferences, and `native_name()` is the
|
|
English source name the menu draws through the catalog.
|
|
|
|
## How a string is localized
|
|
|
|
- `localization::text("English source")` returns the translation for the language entered for the
|
|
current frame, or the source when the catalog has no entry.
|
|
- `localized_format!("{name} send level", name = …)` translates the template and then fills it; the
|
|
translation keeps the same placeholders (a test enforces that).
|
|
- `localization::error_text(message)` matches an engine error against the catalog's error templates
|
|
and carries the embedded values over, so a low-level library error stays in English rather than
|
|
turning into a half-translated sentence.
|
|
- A catalog module exposes `pub(super) fn translate(source: &str) -> Option<&'static str>` and, if
|
|
it translates engine errors, `pub(super) const ERROR_TEMPLATES`.
|
|
|
|
Values built at run time (file, track and device names), command ids, menu paths used for lookup,
|
|
preference keys and values, file formats, the control protocol and third-party plugin names are
|
|
never translated. Engine diagnostics are English in the zh-Hans catalog by design; pt-BR carries
|
|
error templates.
|
|
|
|
The zh-Hans module is generated: edit
|
|
[`crates/ui-egui/src/i18n/zh-hans.tsv`](../crates/ui-egui/src/i18n/zh-hans.tsv) (one row per
|
|
string, `context<TAB>English<TAB>translation`) and rerun
|
|
|
|
```sh
|
|
python3 docs/i18n/tools/gen_zh_hans_locale.py # rewrite the locale module
|
|
python3 docs/i18n/tools/gen_zh_hans_locale.py --check # fail when it is out of date
|
|
```
|
|
|
|
The TSV is also the file `storytold/craft-i18n`'s `tools/sync_app.py` reads, so the catalog can move
|
|
to the shared repository when SoundCraft takes that step.
|
|
|
|
## Choosing the language
|
|
|
|
`Setup ▸ Appearance ▸ Language` (or the `ui.language` command) selects it while the app runs, and
|
|
the choice is a global preference saved with the UI state:
|
|
|
|
```sh
|
|
soundcraft-cli run --demo --cmd 'ui.language={"language":"zh-Hans"}'
|
|
```
|
|
|
|
With no parameter, `ui.language` reports the current language; an unknown tag is an error. In the
|
|
browser the language starts from `navigator.language` and follows the saved preference once one
|
|
exists.
|
|
|
|
## Fonts
|
|
|
|
egui's bundled faces carry no Han glyphs, so the interface needs a CJK fallback
|
|
([`crates/ui-egui/src/fonts.rs`](../crates/ui-egui/src/fonts.rs)):
|
|
|
|
- Native builds append the operating system's own Han face after every family, resolved through
|
|
fontconfig (`lang=zh-cn`) with a list of per-platform candidates; nothing is redistributed.
|
|
- The web build cannot reach system fonts, so it embeds `assets/fonts/NotoSansSC-SoundCraftSubset.ttf`,
|
|
a Noto Sans SC (OFL-1.1) subset at weight 400 covering the UI glyph set. Regenerate it after a
|
|
catalog change with
|
|
|
|
```sh
|
|
# <font>: a Noto Sans SC variable font from a noto-cjk release — any file whose family is
|
|
# "Noto Sans SC" and that carries a wght axis
|
|
python3 docs/i18n/tools/subset_web_font.py <font>
|
|
python3 docs/i18n/tools/subset_web_font.py --check
|
|
```
|
|
|
|
and keep [`ATTRIBUTION.md`](../ATTRIBUTION.md) in step; `cargo xtask assets` enforces that.
|
|
- Han comes before the Hangul fallback for every interface language except Korean, so a Chinese
|
|
interface and Chinese names draw Chinese shapes even where fontconfig would resolve the Korean
|
|
face of Noto Sans CJK first.
|
|
|
|
## Tests and gates
|
|
|
|
`cargo test -p soundcraft-ui-egui` covers the catalog and the fonts:
|
|
|
|
- every catalog entry parses, keys are unique and translations keep the English placeholders;
|
|
- every string passed to `localization::text` / `localized_format!` in `crates/ui-egui/src` has an
|
|
entry in every shipped catalog, and every reference menu label is translated;
|
|
- the bundled web face draws the whole zh-Hans catalog in every family and stays inside its 2 MiB
|
|
budget;
|
|
- with a system Han font installed, every family draws Chinese text.
|
|
|
|
`cargo xtask ci` runs those with the rest of the gates (fmt, clippy, assets, layers, wasm).
|
|
|
|
## Adding another language
|
|
|
|
1. Add a `locales/<tag>/mod.rs` with `translate` (and `ERROR_TEMPLATES` when engine errors should be
|
|
translated), plus the `#[path]` module declaration in `localization.rs`.
|
|
2. Add the `Language` variant: `ALL`, `id()`, `native_name()`, `text()`, and the `error_text`
|
|
template arm.
|
|
3. Translate `every_localized_source_string_has_a_catalog_entry`'s set (the test lists what is
|
|
missing by file and string) and the menu labels.
|
|
4. Add a font fallback for the script, and for the web build either bundle a subset or document the
|
|
gap; extend `ATTRIBUTION.md` when a file is added.
|
|
5. Update [`localization-parity.md`](localization-parity.md), `ROADMAP.md` and `docs/gaps.md`.
|
|
|
|
## Relation to `storytold/craft-i18n`
|
|
|
|
The org keeps shared translations in `craft-i18n` and reads them through an optional `CRAFT_I18N_DIR`
|
|
build input. SoundCraft has not cut over (roadmap stage 3d): like pt-BR, this catalog lives in the
|
|
repository, and its TSV is the pre-cutover file the sync script consumes, so a later migration only
|
|
moves data. |