From 657a0837e22adbb213a63a3b57d69b68112f06a0 Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 17 Jun 2018 10:38:59 +0100 Subject: [PATCH] Use filters for gettext in Tera --- src/i18n.rs | 6 +++--- templates/instance/index.html.tera | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/i18n.rs b/src/i18n.rs index 2cf5f427..96c699f4 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -53,11 +53,11 @@ impl Fairing for I18n { } } -fn tera_gettext(ctx: HashMap) -> Result { - let trans = gettext(ctx.get("t").unwrap().as_str().unwrap()); +fn tera_gettext(msg: serde_json::Value, ctx: HashMap) -> Result { + 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) } diff --git a/templates/instance/index.html.tera b/templates/instance/index.html.tera index 28cbe06a..b859fc8c 100644 --- a/templates/instance/index.html.tera +++ b/templates/instance/index.html.tera @@ -6,7 +6,7 @@ {% endblock title %} {% block content %} -

{{ _(t="Welcome on {{ instance_name }}", instance_name=instance.name) }}

+

{{ "Welcome on {{ instance_name }}" | _(instance_name=instance.name) }}

Latest articles