mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-18 16:26:26 +00:00
Inject ngettext into Tera templates
Fix .po updating (without the -U option, the result was written to stdout, not the .po file)
This commit is contained in:
parent
657a0837e2
commit
25ec318f3f
10 changed files with 61 additions and 3 deletions
1
build.rs
1
build.rs
|
@ -17,6 +17,7 @@ fn update_po() {
|
|||
println!("Updating {}", lang.clone());
|
||||
// Update it
|
||||
Command::new("msgmerge")
|
||||
.arg("-U")
|
||||
.arg(po_path.to_str().unwrap())
|
||||
.arg(pot_path.to_str().unwrap())
|
||||
.spawn()
|
||||
|
|
5
po/en.po
5
po/en.po
|
@ -14,3 +14,8 @@ msgstr ""
|
|||
|
||||
msgid "Welcome on {{ instance_name }}"
|
||||
msgstr "Welcome on {{ instance_name }}"
|
||||
|
||||
msgid "One follower"
|
||||
msgid_plural "{{ count }} followers"
|
||||
msgstr[0] "One follower"
|
||||
msgstr[1] "{{ count }} followers"
|
||||
|
|
16
po/en.po~
Normal file
16
po/en.po~
Normal file
|
@ -0,0 +1,16 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plume\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||
"PO-Revision-Date: 2018-06-15 16:33-0700\n"
|
||||
"Last-Translator: Automatically generated\n"
|
||||
"Language-Team: none\n"
|
||||
"Language: en\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
msgid "Welcome on {{ instance_name }}"
|
||||
msgstr "Welcome on {{ instance_name }}"
|
5
po/fr.po
5
po/fr.po
|
@ -14,3 +14,8 @@ msgstr ""
|
|||
|
||||
msgid "Welcome on {{ instance_name }}"
|
||||
msgstr "Bienvenue sur {{ instance_name }}"
|
||||
|
||||
msgid "One follower"
|
||||
msgid_plural "{{ count }} followers"
|
||||
msgstr[0] "{{ count }} abonné⋅e"
|
||||
msgstr[1] "{{ count }} abonné⋅e⋅s"
|
||||
|
|
16
po/fr.po~
Normal file
16
po/fr.po~
Normal file
|
@ -0,0 +1,16 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: plume\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2018-06-15 16:33-0700\n"
|
||||
"PO-Revision-Date: 2018-06-15 16:33-0700\n"
|
||||
"Last-Translator: Automatically generated\n"
|
||||
"Language-Team: none\n"
|
||||
"Language: fr\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
|
||||
msgid "Welcome on {{ instance_name }}"
|
||||
msgstr "Bienvenue sur {{ instance_name }}"
|
|
@ -14,3 +14,8 @@ msgstr ""
|
|||
|
||||
msgid "Welcome on {{ instance_name }}"
|
||||
msgstr ""
|
||||
|
||||
msgid "One follower"
|
||||
msgid_plural "{{ count }} followers"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
|
|
14
src/i18n.rs
14
src/i18n.rs
|
@ -58,6 +58,16 @@ fn tera_gettext(msg: serde_json::Value, ctx: HashMap<String, serde_json::Value>)
|
|||
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_filter("_", tera_gettext)
|
||||
fn tera_ngettext(msg: serde_json::Value, ctx: HashMap<String, serde_json::Value>) -> Result<serde_json::Value, TeraError> {
|
||||
let trans = ngettext(
|
||||
ctx.get("singular").unwrap().as_str().unwrap(),
|
||||
msg.as_str().unwrap(),
|
||||
ctx.get("count").unwrap().as_u64().unwrap() as u32
|
||||
);
|
||||
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_filter("_", tera_gettext);
|
||||
t.register_filter("_n", tera_ngettext);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<a href="followers/">{{ n_followers }} follower{{ n_followers | pluralize }}</a>
|
||||
<a href="followers/">{{ "{{ count }} followers" | _n(singular="One follower", count=n_followers) }}</a>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue