mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
implement plural function
This commit is contained in:
parent
1f678d7a76
commit
18b380f5ec
@ -24,11 +24,12 @@ 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"]);
|
||||||
match current {
|
match current {
|
||||||
Some(position) => self
|
Some(position) => self
|
||||||
.label
|
.label
|
||||||
.set_label(&format!("{position} of {total} matches")),
|
.set_label(&format!("{position} of {total} {matches}")),
|
||||||
None => self.label.set_label(&format!("{total} matches")),
|
None => self.label.set_label(&format!("{total} {matches}")),
|
||||||
}
|
}
|
||||||
self.label.remove_css_class("error");
|
self.label.remove_css_class("error");
|
||||||
} else {
|
} else {
|
||||||
@ -37,3 +38,13 @@ 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…
x
Reference in New Issue
Block a user