|
|
@@ -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(); |
|
|
|
} |
|
|
|
} |