mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-26 12:00:35 +00:00
Use filters for gettext in Tera
This commit is contained in:
parent
1092ceba76
commit
657a0837e2
2 changed files with 4 additions and 4 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
{% endblock title %}
|
||||
|
||||
{% 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>
|
||||
<div class="cards">
|
||||
|
|
Loading…
Reference in a new issue