Use filters for gettext in Tera

This commit is contained in:
Bat
2018-06-17 10:38:59 +01:00
parent 1092ceba76
commit 657a0837e2
2 changed files with 4 additions and 4 deletions
+3 -3
View File
@@ -53,11 +53,11 @@ impl Fairing for I18n {
}
}
fn tera_gettext(ctx: HashMap<String, serde_json::Value>) -> Result<serde_json::Value, TeraError> {
let trans = gettext(ctx.get("t").unwrap().as_str().unwrap());
fn tera_gettext(msg: serde_json::Value, ctx: HashMap<String, serde_json::Value>) -> Result<serde_json::Value, TeraError> {
let trans = gettext(msg.as_str().unwrap());
Ok(serde_json::Value::String(Tera::one_off(trans.as_ref(), &ctx, false).unwrap_or(String::from(""))))
}
pub fn tera(t: &mut Tera) {
t.register_global_function("_", Box::new(tera_gettext))
t.register_filter("_", tera_gettext)
}