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
+4
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
+2
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);