forked from tsukinaha/tsukimi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
53 lines (44 loc) · 1.54 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const LINGUAS: &str = include_str!("po/LINGUAS");
use std::path::Path;
#[cfg(any(target_os = "linux", target_os = "windows"))]
use std::process::Command;
fn main() {
glib_build_tools::compile_resources(
&["resources"],
"resources/resources.gresource.xml",
"tsukimi.gresource",
);
#[cfg(any(target_os = "linux", target_os = "windows"))]
{
let po_files: Vec<String> = LINGUAS
.lines()
.filter(|line| !line.is_empty())
.map(|line| format!("po/{}.po", line))
.collect();
for po_file in &po_files {
let po_path = Path::new(po_file);
let locale = po_path.file_stem().unwrap().to_str().unwrap();
let mo_file = format!("i18n/locale/{}/LC_MESSAGES/tsukimi.mo", locale);
let mo_path = Path::new(&mo_file);
if !mo_path.exists() {
std::fs::create_dir_all(mo_path.parent().unwrap()).unwrap();
}
let status = Command::new("msgfmt")
.args([po_file, "-o", &mo_file])
.status()
.expect("Failed to compile po file");
if status.success() {
println!("{}: OK", po_file);
} else {
println!("{}: FAILED", po_file);
}
}
}
#[cfg(windows)]
{
println!("cargo:rerun-if-changed=tsukimi-manifest.rc");
embed_resource::compile("./tsukimi_manifest.rc", embed_resource::NONE)
.manifest_optional()
.unwrap();
}
}