Use the choosen domain when compiling templates

This commit is contained in:
Bat 2018-06-17 11:37:24 +01:00
parent a8f27a71b9
commit 23982d00fc

View File

@ -32,8 +32,8 @@ impl Fairing for I18n {
} }
fn on_attach(&self, rocket: Rocket) -> Result<Rocket, Rocket> { fn on_attach(&self, rocket: Rocket) -> Result<Rocket, Rocket> {
update_po(); update_po(self.domain);
compile_po(); compile_po(self.domain);
bindtextdomain(self.domain, fs::canonicalize(&PathBuf::from("./translations/")).unwrap().to_str().unwrap()); bindtextdomain(self.domain, fs::canonicalize(&PathBuf::from("./translations/")).unwrap().to_str().unwrap());
textdomain(self.domain); textdomain(self.domain);
@ -58,9 +58,8 @@ impl Fairing for I18n {
} }
} }
fn update_po(domain: &str) {
fn update_po() { let pot_path = Path::new("po").join(format!("{}.pot", domain));
let pot_path = Path::new("po").join("plume.pot");
for lang in get_locales() { for lang in get_locales() {
let po_path = Path::new("po").join(format!("{}.po", lang.clone())); let po_path = Path::new("po").join(format!("{}.po", lang.clone()));
@ -88,14 +87,14 @@ fn update_po() {
} }
} }
fn compile_po() { fn compile_po(domain: &str) {
for lang in get_locales() { for lang in get_locales() {
let po_path = Path::new("po").join(format!("{}.po", lang.clone())); let po_path = Path::new("po").join(format!("{}.po", lang.clone()));
let mo_dir = Path::new("translations") let mo_dir = Path::new("translations")
.join(lang.clone()) .join(lang.clone())
.join("LC_MESSAGES"); .join("LC_MESSAGES");
fs::create_dir_all(mo_dir.clone()).expect("Couldn't create MO directory"); fs::create_dir_all(mo_dir.clone()).expect("Couldn't create MO directory");
let mo_path = mo_dir.join("plume.mo"); let mo_path = mo_dir.join(format!("{}.mo", domain));
Command::new("msgfmt") Command::new("msgfmt")
.arg(format!("--output-file={}", mo_path.to_str().unwrap())) .arg(format!("--output-file={}", mo_path.to_str().unwrap()))