-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild.rs
More file actions
42 lines (30 loc) · 978 Bytes
/
build.rs
File metadata and controls
42 lines (30 loc) · 978 Bytes
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
use std::{fs, path::Path, process::Command};
use anyhow::Result;
pub const GETTEXT_DOMAIN: &str = "stremio";
pub const GETTEXT_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/po");
fn main() -> Result<()> {
setup_po()?;
Ok(())
}
fn setup_po() -> Result<()> {
println!("cargo:rerun-if-changed={GETTEXT_DIR}");
let po_dir = Path::new(GETTEXT_DIR);
for entry in fs::read_dir(po_dir)? {
let entry = entry?;
let path = entry.path();
if let Some(extension) = path.extension()
&& extension == "po"
&& let Some(po_lang) = path.file_stem()
{
let mo_dir = po_dir.join(po_lang).join("LC_MESSAGES");
fs::create_dir_all(&mo_dir)?;
let mo_path = mo_dir.join(format!("{GETTEXT_DOMAIN}.mo"));
Command::new("msgfmt")
.arg("-o")
.arg(mo_path)
.arg(path)
.spawn()?;
}
}
Ok(())
}