Use filters for gettext in Tera
This commit is contained in:
parent
1092ceba76
commit
657a0837e2
@ -53,11 +53,11 @@ impl Fairing for I18n {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tera_gettext(ctx: HashMap<String, serde_json::Value>) -> Result<serde_json::Value, TeraError> {
|
fn tera_gettext(msg: serde_json::Value, ctx: HashMap<String, serde_json::Value>) -> Result<serde_json::Value, TeraError> {
|
||||||
let trans = gettext(ctx.get("t").unwrap().as_str().unwrap());
|
let trans = gettext(msg.as_str().unwrap());
|
||||||
Ok(serde_json::Value::String(Tera::one_off(trans.as_ref(), &ctx, false).unwrap_or(String::from(""))))
|
Ok(serde_json::Value::String(Tera::one_off(trans.as_ref(), &ctx, false).unwrap_or(String::from(""))))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tera(t: &mut Tera) {
|
pub fn tera(t: &mut Tera) {
|
||||||
t.register_global_function("_", Box::new(tera_gettext))
|
t.register_filter("_", tera_gettext)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
{% endblock title %}
|
{% endblock title %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ _(t="Welcome on {{ instance_name }}", instance_name=instance.name) }}</h1>
|
<h1>{{ "Welcome on {{ instance_name }}" | _(instance_name=instance.name) }}</h1>
|
||||||
|
|
||||||
<h2>Latest articles</h2>
|
<h2>Latest articles</h2>
|
||||||
<div class="cards">
|
<div class="cards">
|
||||||
|
Loading…
Reference in New Issue
Block a user