Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

#218: System Language follows the operating system's language

txiki73943e3d2682355
diff --git a/Cargo.lock b/Cargo.lock
index 2ea9902a8..9650b4c9b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1681,6 +1681,7 @@ dependencies = [
"objc2-foundation 0.3.2",
"rfd",
"serde_json",
+ "sys-locale",
"winit",
"winresource",
]
@@ -5782,6 +5783,15 @@ dependencies = [
"syn 3.0.6",
]
+[[package]]
+name = "sys-locale"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8eab9a99a024a169fe8a903cf9d4a3b3601109bcc13bd9e3c6fff259138626c4"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "sysctl"
version = "0.6.0"
diff --git a/ROADMAP.md b/ROADMAP.md
index 858d84e4d..e77e6ee0d 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -205,4 +205,4 @@ Status: ✅ done · 🟡 in progress · ⬜ not started. Estimates are remaining
### Interface localization
-Edit > Language switches English/Japanese/Spanish/Portuguese (Brazilian) and persists across restarts through `general.interfaceLanguage` (also available in Settings > General). Commands `app.language.english`, `app.language.japanese`, `app.language.spanish` and `app.language.portuguese` are reachable through the control channel. Translations live in one catalog per language (`crates/ui-egui/src/i18n/<code>.tsv`); UI code wraps its strings in `tl!("…")` / `tlf!("…{name}", name)`, and names that come from registries (effects and their parameters, settings, commands, panels, workspaces, presets) are translated where they are drawn. **Spanish covers the whole interface**: menus, panels, dialogs, the Settings pages, the Effects/Effect Controls registry, the Keyboard Shortcuts dialog and status messages; tests fail when a `tl!` literal, a menu label or a registry name has no Spanish entry. Searches match the displayed labels as well as English sources. Japanese and Brazilian Portuguese cover the core menus; untranslated labels use English. Engine error messages, the control channel, the CLI and MCP stay in English. Japanese text uses the Japanese fonts from [craft-fonts](https://github.com/storytold/craft-fonts) when FilmCraft is built with them (`CRAFT_FONTS_DIR`; all official releases, including the web build), otherwise a Japanese font already installed on the system; with neither, switching to Japanese is refused with a message. Existing vertical text support is preserved.
+Edit > Language switches English/Japanese/Spanish/Portuguese (Brazilian) and persists across restarts through `general.interfaceLanguage` (also available in Settings > General). Until a language is chosen, System Language (the default) follows the operating system's or browser's preferred languages and falls back to English. Commands `app.language.english`, `app.language.japanese`, `app.language.spanish` and `app.language.portuguese` are reachable through the control channel. Translations live in one catalog per language (`crates/ui-egui/src/i18n/<code>.tsv`); UI code wraps its strings in `tl!("…")` / `tlf!("…{name}", name)`, and names that come from registries (effects and their parameters, settings, commands, panels, workspaces, presets) are translated where they are drawn. **Spanish covers the whole interface**: menus, panels, dialogs, the Settings pages, the Effects/Effect Controls registry, the Keyboard Shortcuts dialog and status messages; tests fail when a `tl!` literal, a menu label or a registry name has no Spanish entry. Searches match the displayed labels as well as English sources. Japanese and Brazilian Portuguese cover the core menus; untranslated labels use English. Engine error messages, the control channel, the CLI and MCP stay in English. Japanese text uses the Japanese fonts from [craft-fonts](https://github.com/storytold/craft-fonts) when FilmCraft is built with them (`CRAFT_FONTS_DIR`; all official releases, including the web build), otherwise a Japanese font already installed on the system; with neither, switching to Japanese is refused with a message. Existing vertical text support is preserved.
diff --git a/apps/filmcraft-web/src/lib.rs b/apps/filmcraft-web/src/lib.rs
index 469d2107a..beafbbd98 100644
--- a/apps/filmcraft-web/src/lib.rs
+++ b/apps/filmcraft-web/src/lib.rs
@@ -177,6 +177,9 @@ pub async fn start(canvas_id: String) -> Result<(), JsValue> {
}
let mut app = FilmcraftApp::new(session);
import::install_hooks(&mut app);
+ // Settings ▸ General ▸ Interface Language ▸ System Language (#218): the browser's languages.
+ app.hooks.system_languages =
+ Some(Box::new(|| web_sys::window().map(|w| w.navigator().languages().iter().filter_map(|v| v.as_string()).collect()).unwrap_or_default()));
let (tx, rx) = std::sync::mpsc::channel();
api::set_sender(tx);
app = app.with_control(rx);
diff --git a/apps/filmcraft/Cargo.toml b/apps/filmcraft/Cargo.toml
index 8095c787a..9e43d1dc2 100644
--- a/apps/filmcraft/Cargo.toml
+++ b/apps/filmcraft/Cargo.toml
@@ -26,6 +26,7 @@ log = { workspace = true }
rfd = { workspace = true }
cpal = "0.16"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
+sys-locale = "0.3"
[target.'cfg(target_os = "macos")'.dependencies]
muda = "0.21"
diff --git a/apps/filmcraft/src/main.rs b/apps/filmcraft/src/main.rs
index 5967b98bd..3b769d5d1 100644
--- a/apps/filmcraft/src/main.rs
+++ b/apps/filmcraft/src/main.rs
@@ -196,6 +196,8 @@ fn main() -> eframe::Result {
}));
app.hooks.pick_folder = Some(Box::new(|| rfd::FileDialog::new().pick_folder().map(|p| p.to_string_lossy().to_string())));
app.hooks.open_path = Some(Box::new(open_path));
+ // Settings ▸ General ▸ Interface Language ▸ System Language (#218).
+ app.hooks.system_languages = Some(Box::new(|| sys_locale::get_locales().collect()));
app.hooks.raise_without_focus = Some(Box::new(|| {
window_raise::raise_without_focus();
}));
diff --git a/crates/engine/src/settings.rs b/crates/engine/src/settings.rs
index c3b2fbc36..cbb2b7b73 100644
--- a/crates/engine/src/settings.rs
+++ b/crates/engine/src/settings.rs
@@ -33,7 +33,9 @@ pub const PREFS_VERSION: u32 = 2;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", default)]
pub struct GeneralPrefs {
- /// Interface language (persisted independently of projects): `en`, `ja`, `es` or `pt-br`.
+ /// Interface language (persisted independently of projects): `en`, `ja`, `es`, `pt-br`, or
+ /// `system` (the default: the operating system's preferred language when the interface has it,
+ /// otherwise English).
pub interface_language: String,
/// "At Startup": `showHome` (FilmCraft: the demo project), `openMostRecent`, `emptyProject`.
pub at_startup: String,
@@ -61,7 +63,7 @@ pub struct GeneralPrefs {
impl Default for GeneralPrefs {
fn default() -> Self {
Self {
- interface_language: "en".into(),
+ interface_language: "system".into(),
at_startup: "showHome".into(),
when_opening_project: "showOpenDialog".into(),
bins_double_click: "openInPlace".into(),
@@ -678,7 +680,7 @@ static CATEGORIES: &[Category] = &[
f(
"general.interfaceLanguage",
"Interface Language",
- Kind::Choice(&[("en", "English"), ("ja", "日本語"), ("es", "Español"), ("pt-br", "Português (Brasil)")]),
+ Kind::Choice(&[("system", "System Language"), ("en", "English"), ("ja", "日本語"), ("es", "Español"), ("pt-br", "Português (Brasil)")]),
true,
),
f("general.atStartup", "At Startup", Kind::Choice(STARTUP), true),
diff --git a/crates/engine/src/settings_tests.rs b/crates/engine/src/settings_tests.rs
index b7f662913..d706e4a19 100644
--- a/crates/engine/src/settings_tests.rs
+++ b/crates/engine/src/settings_tests.rs
@@ -34,6 +34,21 @@ fn interface_language_persists_and_rejects_hostile_values() {
assert_eq!(s.prefs.general.interface_language, "es");
}
assert_eq!(Preferences::load(&path).general.interface_language, "es");
+ // back to following the operating system (#218)
+ set(&mut s, "general.interfaceLanguage", json!("system"));
+ assert_eq!(Preferences::load(&path).general.interface_language, "system");
+ std::fs::remove_dir_all(dir).unwrap();
+}
+
+/// A new installation follows the operating system's language (#218); a saved choice is kept.
+#[test]
+fn interface_language_defaults_to_the_system_language() {
+ assert_eq!(Preferences::default().general.interface_language, "system");
+ let dir = tmp_dir("interface-language-default");
+ let path = dir.join("preferences.json");
+ assert_eq!(Preferences::load(&path).general.interface_language, "system", "no preferences file yet");
+ std::fs::write(&path, r#"{"general":{"interfaceLanguage":"en"}}"#).unwrap();
+ assert_eq!(Preferences::load(&path).general.interface_language, "en");
std::fs::remove_dir_all(dir).unwrap();
}
diff --git a/crates/ui-egui/README.md b/crates/ui-egui/README.md
index 75c11e1b2..dcc629e90 100644
--- a/crates/ui-egui/README.md
+++ b/crates/ui-egui/README.md
@@ -7,6 +7,10 @@ Interactive controls keep stable automation ids regardless of the interface lang
Edit > Language offers English, Japanese and Spanish. The language is stored in the engine's
`general.interfaceLanguage` preference, restored on startup, and also available in Settings > General.
+Its default, System Language (`system`), follows the operating system: the first of the user's
+preferred languages that the interface has (the host supplies them through
+`HostHooks::system_languages`: `sys-locale` on the desktop, `navigator.languages` on the web),
+otherwise English.
The `app.language.*` UI commands and `prefs.set` reach it through the control channel.
Japanese requires a craft-fonts build or a suitable installed font.
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 144386497..5bc68b488 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -3312,6 +3312,7 @@
Zoom Tool Herramienta Zoom
with: por:
Interface Language Idioma de la interfaz
+ System Language Idioma del sistema
Cinematic Cinematográfico
Film Emulation Emulación de película
Technical Técnico
diff --git a/crates/ui-egui/src/i18n/mod.rs b/crates/ui-egui/src/i18n/mod.rs
index 750d5fe7d..c04416c6a 100644
--- a/crates/ui-egui/src/i18n/mod.rs
+++ b/crates/ui-egui/src/i18n/mod.rs
@@ -62,6 +62,19 @@ impl Language {
}
}
+ /// Interface Language ▸ System Language (#218): the first of the user's preferred languages
+ /// (BCP 47 or POSIX locale tags such as `es-419`, `pt_BR.UTF-8`, most preferred first) that the
+ /// interface has, else English. Any Portuguese gets the Brazilian catalog, the only one there is.
+ pub fn from_locales(tags: &[String]) -> Self {
+ const PRIMARY: [(&str, Language); 4] = [("en", Language::En), ("ja", Language::Ja), ("es", Language::Es), ("pt", Language::PtBr)];
+ tags.iter()
+ .find_map(|tag| {
+ let primary = tag.split(['-', '_', '.', '@']).next().unwrap_or_default();
+ PRIMARY.iter().find(|(code, _)| primary.eq_ignore_ascii_case(code)).map(|(_, l)| *l)
+ })
+ .unwrap_or_default()
+ }
+
/// Stable code: the `general.interfaceLanguage` preference value (`Language::parse` reads it back).
pub fn code(self) -> &'static str {
match self {
@@ -616,6 +629,59 @@ mod tests {
set_current(Language::En);
}
+ /// #218: System Language picks the first of the user's preferred languages the interface has.
+ #[test]
+ fn system_language_follows_the_preferred_locales() {
+ let l = |tags: &[&str]| Language::from_locales(&tags.iter().map(|t| t.to_string()).collect::<Vec<_>>());
+ assert_eq!(l(&["es_ES.UTF-8"]), Language::Es);
+ assert_eq!(l(&["es-419"]), Language::Es);
+ assert_eq!(l(&["ES"]), Language::Es);
+ assert_eq!(l(&["ja-JP"]), Language::Ja);
+ assert_eq!(l(&["pt-BR"]), Language::PtBr);
+ assert_eq!(l(&["pt_PT.UTF-8@euro"]), Language::PtBr);
+ assert_eq!(l(&["fr-FR", "de", "es-MX", "ja"]), Language::Es, "the first one the interface has");
+ assert_eq!(l(&["en-GB", "es"]), Language::En);
+ for none in [&[][..], &["fr"], &["C"], &["POSIX"], &[""], &["e"], &["esp"], &["-es"]] {
+ assert_eq!(l(none), Language::En, "{none:?}");
+ }
+ assert_eq!(l(&[&"x".repeat(1 << 20), "es"]), Language::Es);
+ }
+
+ /// #218: the `system` preference (the default) asks the host for the system's languages; an
+ /// explicit choice does not, and without a host hook System Language is English.
+ #[test]
+ fn system_language_preference_uses_the_host_languages() {
+ let ctx = egui::Context::default();
+ let session = filmcraft_engine::Session::default();
+ assert_eq!(session.prefs.general.interface_language, "system");
+ let mut app = crate::FilmcraftApp::new(session);
+ app.apply_prefs(&ctx);
+ assert_eq!(app.ui.language, Language::En, "no host hook");
+
+ let mut app = crate::FilmcraftApp::new(filmcraft_engine::Session::default());
+ let asked = std::rc::Rc::new(std::cell::Cell::new(0));
+ let count = asked.clone();
+ app.hooks.system_languages = Some(Box::new(move || {
+ count.set(count.get() + 1);
+ vec!["fr-FR".into(), "es-ES".into()]
+ }));
+ app.apply_prefs(&ctx);
+ assert_eq!(app.ui.language, Language::Es);
+ assert_eq!(current(), Language::Es);
+ crate::menus::invoke(&mut app, &ctx, "app.language.english", serde_json::json!({})).unwrap();
+ app.apply_prefs(&ctx);
+ assert_eq!((app.ui.language, app.session.prefs.general.interface_language.as_str()), (Language::En, "en"));
+ let asked_before = asked.get();
+ app.session.execute("prefs.set", serde_json::json!({"key": "general.interfaceLanguage", "value": "ja"})).unwrap();
+ app.apply_prefs(&ctx);
+ assert_eq!(asked.get(), asked_before, "an explicit language does not ask the system");
+ app.session.execute("prefs.set", serde_json::json!({"key": "general.interfaceLanguage", "value": "system"})).unwrap();
+ app.apply_prefs(&ctx);
+ assert_eq!(app.ui.language, Language::Es);
+ assert_eq!(asked.get(), asked_before + 1);
+ set_current(Language::En);
+ }
+
#[test]
fn japanese_needs_an_installed_font() {
let mut app = crate::FilmcraftApp::new(filmcraft_engine::Session::default());
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 8e25a7a70..76f1f28c2 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -108,6 +108,9 @@ pub struct HostHooks {
pub pick_save_as: Option<Box<dyn FnMut(&str, &[&str], &str) -> Option<String>>>,
/// The active keyboard shortcuts changed: update native menu key equivalents.
pub shortcuts_changed: Option<Box<dyn FnMut(&[menus::MenuItem])>>,
+ /// The user's preferred languages (locale tags, most preferred first) for Interface Language ▸
+ /// System Language. Without it, System Language is English.
+ pub system_languages: Option<Box<dyn Fn() -> Vec<String>>>,
/// Open dialog for a JSON file (shortcut preset import): filter name, extensions → path.
pub pick_open_file: Option<Box<dyn FnMut(&str, &[&str]) -> Option<String>>>,
/// Folder picker (Link Media search, proxy and Project Manager destinations).
@@ -501,7 +504,13 @@ impl FilmcraftApp {
self.set_theme(ctx, ThemeKind::from_pref(&p.appearance.color_theme));
}
if prev.as_ref().is_none_or(|q| q.general.interface_language != p.general.interface_language) {
- let language = i18n::Language::parse(&p.general.interface_language).unwrap_or_default();
+ let language = match i18n::Language::parse(&p.general.interface_language) {
+ Some(l) => l,
+ None if p.general.interface_language == "system" => {
+ i18n::Language::from_locales(&self.hooks.system_languages.as_ref().map(|f| f()).unwrap_or_default())
+ }
+ None => i18n::Language::default(),
+ };
if language == i18n::Language::Ja && !i18n::install_japanese_font(ctx) {
self.ui.language = i18n::Language::En;
self.ui.status = tl!("no Japanese font is installed on this system; the interface stays in English").into();