diff --git a/.gitignore b/.gitignore index c51ce8066..1c2dcddb0 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ AGENTS.md /reference *.log +*.mo # Git should not follow this IN ANY CASE Cargo.lock diff --git a/Makefile b/Makefile index 96eea57f2..0e0b19082 100644 --- a/Makefile +++ b/Makefile @@ -101,6 +101,7 @@ install-data-rog_gui: $(INSTALL_DATA) "./rog-control-center/data/$(BIN_ROG).png" "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/$(BIN_ROG).png" $(INSTALL_DATA) "./rog-control-center/data/$(APP_ID).metainfo.xml" "$(DESTDIR)$(datarootdir)/metainfo/$(APP_ID).metainfo.xml" cd rog-aura/data/layouts && find . -type f -name "*.ron" -exec $(INSTALL_DATA) "{}" "$(DESTDIR_REALPATH)$(datarootdir)/rog-gui/layouts/{}" \; + cd rog-control-center/translations && find . -type f -name "*.mo" -exec $(INSTALL_DATA) "{}" "$(DESTDIR_REALPATH)$(datarootdir)/locale/{}" \; $(INSTALL_DATA) "./data/icons/asus_notif_yellow.png" "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/asus_notif_yellow.png" $(INSTALL_DATA) "./data/icons/asus_notif_green.png" "$(DESTDIR)$(datarootdir)/icons/hicolor/512x512/apps/asus_notif_green.png" @@ -164,6 +165,7 @@ uninstall: rm -rf "$(DESTDIR)$(datarootdir)/asusd" rm -rf "$(DESTDIR)$(datarootdir)/asusctl" rm -rf "$(DESTDIR)$(datarootdir)/rog-gui" + cd rog-control-center/translations && find . -type f -name "*.mo" -exec rm -f "$(DESTDIR_REALPATH)$(datarootdir)/locale/{}" \; update: cargo update diff --git a/rog-control-center/build.rs b/rog-control-center/build.rs index 8887c316c..eafd49168 100644 --- a/rog-control-center/build.rs +++ b/rog-control-center/build.rs @@ -1,14 +1,61 @@ -use std::path::PathBuf; +use std::fs; +use std::path::{Path, PathBuf}; +use std::process::Command; use slint_build::CompilerConfiguration; +fn compile_translations(manifest_dir: &Path) -> Result<(), Box> { + let translations_dir = manifest_dir.join("translations"); + if !translations_dir.exists() { + return Ok(()); + } + + println!("cargo:rerun-if-changed={}", translations_dir.display()); + + for entry in fs::read_dir(&translations_dir)? { + let entry = entry?; + let path = entry.path(); + if path.is_dir() { + let po_file = path.join("rog-control-center.po"); + let lc_messages_dir = path.join("LC_MESSAGES"); + let mo_file = lc_messages_dir.join("rog-control-center.mo"); + + if po_file.exists() { + println!("cargo:rerun-if-changed={}", po_file.display()); + println!("cargo:rerun-if-changed={}", mo_file.display()); + fs::create_dir_all(&lc_messages_dir)?; + + let status = Command::new("msgfmt") + .arg(&po_file) + .arg("-o") + .arg(&mo_file) + .status() + .map_err(|e| format!("Failed to execute msgfmt: {}", e))?; + + if !status.success() { + return Err(format!( + "msgfmt failed for {}: exit status {}", + po_file.display(), + status + ) + .into()); + } + } else if mo_file.exists() { + fs::remove_file(&mo_file)?; + } + } + } + Ok(()) +} + fn main() -> Result<(), Box> { - // write_locales(); - let root = env!("CARGO_MANIFEST_DIR"); - let mut main = PathBuf::from(root); + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + compile_translations(&root)?; + + let mut main = root.clone(); main.push("ui/main_window.slint"); - let mut include = PathBuf::from(root); + let mut include = root.clone(); include.push("ui"); slint_build::print_rustc_flags()?; 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