i18n: a catalog for the interface below the menu bar

The menu bar has had a catalog since #229 (keyed by `(command, English label)`); everything below
it - panel labels, buttons, field names, tooltips, the sentences a panel draws itself - was written
straight into the code and stayed English in every language (#333).

This adds `crates/ui-egui/src/i18n/ui.rs`:

- Rows are keyed by the English source string, so a panel wraps a literal it already has instead of
  inventing an id, and a row that is missing falls back to English rather than to an empty label.
- `tr("Rename")` translates a plain string; `tr_args("Proxy Use: {}", &[&quality])` fills the values
  of a row that carries them. `tr_args` writes into its own buffer, so it cannot panic on a mismatch,
  and a test keeps every row's placeholder count equal to its English source.
- The language in force is set once per frame from the resolved interface language - the same value
  the CJK fonts are installed for - and kept in a thread-local, so the panels do not have to thread
  it through every function. The render threads never draw interface text.
- Simplified and Traditional Chinese are complete (384 strings); the Japanese rows are still open,
  and the catalog takes them without any other change.

Tests: the two Chinese catalogs must list the same source strings, no empty or duplicated rows, every
row must be asked for by a converted panel, and a converted panel that gains a hard-coded string in a
common call shape fails the build.
This commit is contained in:
FeiLiuEM 2026-10-09 20:17:05 +08:00
parent d5f78f3fc0
commit cceaba0452
6 changed files with 1076 additions and 2 deletions

View File

@ -1,5 +1,6 @@
# Roadmap
- 2026-10-09: Settings ▸ General ▸ Language now translates the interface below the menu bar as well: panels, dialogs, buttons and tooltips read their text through `crates/ui-egui/src/i18n/ui.rs`, keyed by the English source string. Simplified and Traditional Chinese are complete (384 strings); Japanese rows can follow in the same file. A test fails when a converted panel gains a hard-coded string, and another keeps the catalog free of unused rows.
- 2026-10-08: `effectcraft-cli render --out` resolves a relative path against the working directory, like `--project` (it used the project's folder, which doubled a path that already named it). Render Queue outputs set in a project are unchanged.
- 2026-10-08: Long-press a grouped toolbar button to choose its tools, including Horizontal/Vertical Type; releasing the hold keeps the menu open. Existing point/paragraph text creation is unchanged.

View File

@ -4,7 +4,11 @@
//! plug-in names remain verbatim; these catalogs only translate the fixed menu tree.
use crate::EffectcraftApp;
/// Translations for the panels, tooltips and dialogs below the menu bar (see the module docs).
mod ui;
use effectcraft_engine::menus::MenuEntry;
pub(crate) use ui::{set_current, tr, tr_args};
/// Every language with a catalog, in the order Settings ▸ General ▸ Language lists them.
const CATALOG_CODES: [&str; 3] = ["ja", "zh-hans", "zh-hant"];

File diff suppressed because it is too large Load Diff

View File

@ -1573,6 +1573,8 @@ impl eframe::App for EffectcraftApp {
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
self.apply_gpu_failure(ctx);
// The panels read the interface language from here (see `crate::i18n::ui`).
crate::i18n::set_current(crate::i18n::language(self));
if !self.styled {
theme::install(ctx, &self.tokens);
fit_window(ctx);

File diff suppressed because one or more lines are too long

View File

@ -29,7 +29,7 @@ Commands (CLI, MCP, control channel):
### Settings that change behaviour
- `general.language`: interface language (`system` / `en` / `ja` / `zh-hans` / `zh-hant`), Settings ▸ General ▸ Language; menu labels change immediately. `system` (Match System, the default) follows the operating system's interface language where EffectCraft has a translation and is English otherwise: a Simplified Chinese locale (`zh`, `zh-CN`, `zh_CN.UTF-8`, `zh-Hans-CN`, `zh-SG`) selects `zh-hans`, a Traditional one (`zh-TW`, `zh-HK`, `zh-Hant`, `zh_MO`) selects `zh-hant`; the browser build stays in English with it. Native Japanese, Simplified and Traditional Chinese UI uses installed system fonts; the web host must supply a Japanese font.
- `general.language`: interface language (`system` / `en` / `ja` / `zh-hans` / `zh-hant`), Settings ▸ General ▸ Language; menu labels change immediately. `system` (Match System, the default) follows the operating system's interface language where EffectCraft has a translation and is English otherwise: a Simplified Chinese locale (`zh`, `zh-CN`, `zh_CN.UTF-8`, `zh-Hans-CN`, `zh-SG`) selects `zh-hans`, a Traditional one (`zh-TW`, `zh-HK`, `zh-Hant`, `zh_MO`) selects `zh-hant`; the browser build stays in English with it. Native Japanese, Simplified and Traditional Chinese UI uses installed system fonts; the web host must supply a Japanese font. Two catalogs back the text: the menus are keyed by `(command, English label)` (`crates/ui-egui/src/i18n.rs`), and the rest of the interface - panels, dialogs, buttons, tooltips - is keyed by its English source string (`crates/ui-egui/src/i18n/ui.rs`), where a panel writes `tr("Rename")`, or `tr_args("Proxy Use: {}", &[&quality])` when the row carries a value. A row that is missing falls back to English, so a new string shows up untranslated rather than empty; the tests in that module fail on an unused row and on a hard-coded string in a converted panel.
- `general.undoLevels`: Levels of Undo
- `general.pathPointSize`: Path Point and Handle Size
- `general.recentItems`: Recent Projects Shown