diff --git a/.gitignore b/.gitignore index c51ce8066..2e3e76720 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,9 @@ AGENTS.md *.log +# Compiled gettext binaries — .po sources are tracked, .mo are build artifacts +# compiled from source at build time (see rog-control-center/build.rs). +*.mo + # Git should not follow this IN ANY CASE Cargo.lock diff --git a/rog-control-center/build.rs b/rog-control-center/build.rs index 8887c316c..da0571036 100644 --- a/rog-control-center/build.rs +++ b/rog-control-center/build.rs @@ -2,8 +2,45 @@ use std::path::PathBuf; use slint_build::CompilerConfiguration; +/// Compile .po source files to .mo binaries at build time so dev builds +/// have translations without committing binary artifacts to Git. +/// Silently skips if `msgfmt` is not installed (installed packages use +/// /usr/share/locale/ instead). +fn compile_locales() { + let root = env!("CARGO_MANIFEST_DIR"); + let translations_dir = PathBuf::from(root).join("translations"); + let Ok(entries) = std::fs::read_dir(&translations_dir) else { + return; + }; + for entry in entries.flatten() { + // Sources live at translations//rog-control-center.po; the + // compiled catalog goes to the gettext layout (/LC_MESSAGES/) + // that init_translations! resolves at runtime. + let po = entry.path().join("rog-control-center.po"); + if !po.exists() { + continue; + } + let mo = entry.path().join("LC_MESSAGES/rog-control-center.mo"); + // The LC_MESSAGES dir isn't tracked once the .mo are gitignored, so + // recreate it on a fresh checkout before msgfmt writes into it. + let _ = std::fs::create_dir_all(mo.parent().unwrap_or(entry.path().as_path())); + match std::process::Command::new("msgfmt").arg("-o").arg(&mo).arg(&po).status() { + Ok(status) if !status.success() => { + println!("cargo:warning=msgfmt failed for {} (status {status})", po.display()); + } + // msgfmt not installed (dev without gettext) — packaged builds use + // /usr/share/locale instead, so silently skip. + Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} + Err(e) => { + println!("cargo:warning=msgfmt could not run for {}: {e}", po.display()); + } + Ok(_) => {} + } + } +} + fn main() -> Result<(), Box> { - // write_locales(); + compile_locales(); let root = env!("CARGO_MANIFEST_DIR"); let mut main = PathBuf::from(root); main.push("ui/main_window.slint"); diff --git a/rog-control-center/translations/az/LC_MESSAGES/rog-control-center.mo b/rog-control-center/translations/az/LC_MESSAGES/rog-control-center.mo deleted file mode 100644 index 612944aac..000000000 Binary files a/rog-control-center/translations/az/LC_MESSAGES/rog-control-center.mo and /dev/null differ diff --git a/rog-control-center/translations/en/LC_MESSAGES/rog-control-center.mo b/rog-control-center/translations/en/LC_MESSAGES/rog-control-center.mo deleted file mode 100644 index a24bf450c..000000000 Binary files a/rog-control-center/translations/en/LC_MESSAGES/rog-control-center.mo and /dev/null differ diff --git a/rog-control-center/translations/fr/LC_MESSAGES/rog-control-center.mo b/rog-control-center/translations/fr/LC_MESSAGES/rog-control-center.mo deleted file mode 100644 index 31c52e225..000000000 Binary files a/rog-control-center/translations/fr/LC_MESSAGES/rog-control-center.mo and /dev/null differ diff --git a/rog-control-center/translations/it/LC_MESSAGES/rog-control-center.mo b/rog-control-center/translations/it/LC_MESSAGES/rog-control-center.mo deleted file mode 100644 index 3d9736ad3..000000000 Binary files a/rog-control-center/translations/it/LC_MESSAGES/rog-control-center.mo and /dev/null differ diff --git a/rog-control-center/translations/pt_BR/LC_MESSAGES/rog-control-center.mo b/rog-control-center/translations/pt_BR/LC_MESSAGES/rog-control-center.mo deleted file mode 100644 index b16ace057..000000000 Binary files a/rog-control-center/translations/pt_BR/LC_MESSAGES/rog-control-center.mo and /dev/null differ diff --git a/rog-control-center/translations/ru/LC_MESSAGES/rog-control-center.mo b/rog-control-center/translations/ru/LC_MESSAGES/rog-control-center.mo deleted file mode 100644 index 347657336..000000000 Binary files a/rog-control-center/translations/ru/LC_MESSAGES/rog-control-center.mo and /dev/null differ diff --git a/rog-control-center/translations/tr/LC_MESSAGES/rog-control-center.mo b/rog-control-center/translations/tr/LC_MESSAGES/rog-control-center.mo deleted file mode 100644 index ad28b73a8..000000000 Binary files a/rog-control-center/translations/tr/LC_MESSAGES/rog-control-center.mo and /dev/null differ diff --git a/rog-control-center/translations/uk_UA/LC_MESSAGES/rog-control-center.mo b/rog-control-center/translations/uk_UA/LC_MESSAGES/rog-control-center.mo deleted file mode 100644 index aae151c4f..000000000 Binary files a/rog-control-center/translations/uk_UA/LC_MESSAGES/rog-control-center.mo and /dev/null differ diff --git a/rog-control-center/translations/zh_CN/LC_MESSAGES/rog-control-center.mo b/rog-control-center/translations/zh_CN/LC_MESSAGES/rog-control-center.mo deleted file mode 100644 index 4f53eae70..000000000 Binary files a/rog-control-center/translations/zh_CN/LC_MESSAGES/rog-control-center.mo and /dev/null differ