M7: localization layer (#128)

UI strings come from per-language TOML catalogs compiled in (English text as the key and fallback, named placeholders, one/other plurals, context suffixes); command labels are translated at display time while ids, CLI, MCP and control output stay English; accessibility names follow. Preferences > Language (System / English / Español, live; the system language from the OS or the browser), pref.language for scripts. A key check test guards the catalogs. The Spanish catalog is a machine draft awaiting native review; docs/translating.md explains adding a language.
This commit is contained in:
BFlat
2026-10-11 16:21:16 +07:00
committed by GitHub
parent 76df2d4136
commit a2e2012fdc
56 changed files with 5566 additions and 1461 deletions
+12
View File
@@ -241,6 +241,18 @@ pub fn specs() -> Vec<CommandSpec> {
s.prefs.user_name = if name.is_empty() { super::comment::DEFAULT_AUTHOR.into() } else { name };
Ok(json!({"name": s.prefs.user_name}))
}),
spec!("pref.language", "Interface language", "{language: system|en|es|… (a language code; no catalog: English)}", false, |s, p| {
let lang = req_string("pref.language", p, "language")?;
let lang = lang.trim();
// A BCP 47-style tag ("es", "pt-BR", "zh_Hans") or "system".
let tag = lang.len() <= 35
&& lang.split(['-', '_']).all(|part| !part.is_empty() && part.len() <= 8 && part.chars().all(|c| c.is_ascii_alphanumeric()));
if !tag {
return Err(bad("pref.language", format!("`{lang}` is not a language code")));
}
s.prefs.language = lang.to_string();
Ok(json!({"language": s.prefs.language}))
}),
spec!("app.preferences", "Preferences", "{}", false, |s, _| ui(s, "dialog.preferences")),
spec!("app.actions", "Actions", "{}", false, |s, _| ui(s, "palette.actions")),
spec!("help.shortcuts", "Keyboard shortcuts", "{}", false, |s, _| ui(s, "panel.shortcuts")),