Browse Source

recover more stuff

translation2
Colin Reeder 3 years ago
parent
commit
255e63a302
3 changed files with 32 additions and 4 deletions
  1. +1
    -0
      Cargo.toml
  2. +2
    -2
      src/build.rs
  3. +29
    -2
      src/build/build_translations.rs

+ 1
- 0
Cargo.toml View File

@@ -3,6 +3,7 @@ name = "radiate"
version = "0.2.0"
authors = ["Colin Reeder <colin@vpzom.click>"]
edition = "2018"
build = "src/build.rs"

[dependencies]
qmetaobject = "0.0.5"


build.rs → src/build.rs View File

@@ -1,8 +1,8 @@
mod build_qmo {
include!("./src/build/build_qmo.rs");
include!("./build/build_qmo.rs");
}
mod build_translations {
include!("./src/build/build_translations.rs");
include!("./build/build_translations.rs");
}

fn main() {

+ 29
- 2
src/build/build_translations.rs View File

@@ -1,18 +1,45 @@
pub fn main() {
let target_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
let translation_target_dir = target_dir.join("mo");

std::fs::create_dir_all(&translation_target_dir).expect("Failed to create target directory");

let mut languages = Vec::new();

for entry in std::fs::read_dir("./po").expect("Failed to read po directory") {
let entry = entry.expect("Failed to read po directory");
let name = entry.file_name();
let name = name.to_string_lossy();
if name.ends_with(".po") {
println!("{}", name);
std::process::Command::new("msgfmt")

let language = &name[..(name.len() - 3)];

let status =std::process::Command::new("msgfmt")
.arg(entry.path())
.arg("-o")
.arg(translation_target_dir.join(format!("{}.mo", &name[..(name.len() - 3)])))
.arg(translation_target_dir.join(format!("{}.mo", &language)))
.status()
.expect("Failed to compile po file");
if !status.success() {
panic!("Failed to compile po file");
}

languages.push(language.to_owned());
}
}

{
use std::io::Write;

let mut writer = std::fs::File::create(target_dir.join("mo.rs")).expect("Failed to create rust file");

writeln!(writer, "lazy_static! {{").unwrap();
writeln!(writer, "\tpub static ref MO_FILES: std::collections::HashMap<String, &'static [u8]> = vec![").unwrap();
for language in languages {
writeln!(writer, "\t\t(\"{0}\".to_owned(), &include_bytes!(concat!(env!(\"OUT_DIR\"), \"/mo/{0}.mo\"))[..]),", language).unwrap();
}
writeln!(writer, "\t].into_iter().collect();").unwrap();
writeln!(writer, "}}").unwrap();
}
}

Loading…
Cancel
Save