mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
implement plural helper as the plurify library
This commit is contained in:
parent
18b380f5ec
commit
f5eb9a1280
2 changed files with 4 additions and 11 deletions
|
|
@ -45,6 +45,9 @@ version = "0.9.1"
|
||||||
package = "sourceview5"
|
package = "sourceview5"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
|
|
||||||
|
[dependencies.plurify]
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
# development
|
# development
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
# ggemini = { git = "https://github.com/YGGverse/ggemini.git" }
|
# ggemini = { git = "https://github.com/YGGverse/ggemini.git" }
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ impl Result {
|
||||||
|
|
||||||
pub fn update(&self, current: Option<usize>, total: usize) {
|
pub fn update(&self, current: Option<usize>, total: usize) {
|
||||||
if total > 0 {
|
if total > 0 {
|
||||||
let matches = plural(total, &["match", "matches", "matches"]);
|
let matches = plurify::ns(total, &["match", "matches", "matches"]);
|
||||||
match current {
|
match current {
|
||||||
Some(position) => self
|
Some(position) => self
|
||||||
.label
|
.label
|
||||||
|
|
@ -38,13 +38,3 @@ impl Result {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tools
|
|
||||||
|
|
||||||
fn plural<'a>(n: usize, s: &[&'a str]) -> &'a str {
|
|
||||||
s[if (n % 100) > 4 && (n % 100) < 20 {
|
|
||||||
2
|
|
||||||
} else {
|
|
||||||
[2, 0, 1, 1, 1, 2][std::cmp::min(n % 10, 5)]
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue