diff --git a/src/app/browser/window/tab/item/page/search/form/result.rs b/src/app/browser/window/tab/item/page/search/form/result.rs index c85ea770..ea4a248d 100644 --- a/src/app/browser/window/tab/item/page/search/form/result.rs +++ b/src/app/browser/window/tab/item/page/search/form/result.rs @@ -24,11 +24,12 @@ impl Result { pub fn update(&self, current: Option, total: usize) { if total > 0 { + let matches = plural(total, &["match", "matches", "matches"]); match current { Some(position) => self .label - .set_label(&format!("{position} of {total} matches")), - None => self.label.set_label(&format!("{total} matches")), + .set_label(&format!("{position} of {total} {matches}")), + None => self.label.set_label(&format!("{total} {matches}")), } self.label.remove_css_class("error"); } 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)] + }] +}