git clone https://garage44.eu/jeroen/pinnacle.gitcartopolis-agent · 2026-11-30T19:32:18Z
test(locale): a counted text has its singular beside it
s948 had to fix "Delete the folder X and the 1 things in it" after it
landed, and the same mistake stands in the launcher ("1 apps installed")
and Settings ("1 devices"). every_counted_text_has_a_singular finds each
Dutch-table text with "{} <plural>" and wants "1 x", "one x" or
"One x" beside it. The two known cases are listed in NO_SINGULAR_YET
until they are given one; "{} contacts" never counts 1 and is excused in
NEVER_ONE. docs/text-and-access.md states the rule.docs/text-and-access.md | 6 +++++-
locale/src/lib.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/docs/text-and-access.md b/docs/text-and-access.md
index ecb62d0..e07a534 100644
--- a/docs/text-and-access.md
+++ b/docs/text-and-access.md
@@ -56,7 +56,11 @@ gives it in the language chosen in Settings → Language. The English text is
the key: a program reads as before, and a text with no translation shows in
English. The Dutch is `locale/src/nl.rs`, sorted. **A test fails for any
text a program passes to `t` or `tf` without its Dutch**, so a new text in
-English cannot land untranslated. Texts that arrive at run time (an app's
+English cannot land untranslated. **A text that counts has its singular
+beside it**: `"1 note"` (or `"One line"`, `"the one thing"`) next to `"{}
+notes"`, picked by a `match` on the count, since a blank cannot say "1
+notes"; `every_counted_text_has_a_singular` fails for a counted text without
+one (a count that is never 1 goes in its `NEVER_ONE`, with why). Texts that arrive at run time (an app's
title from its manifest) go through `tr`, and are listed in `RUN_TIME` so the
test checks them too.
diff --git a/locale/src/lib.rs b/locale/src/lib.rs
index b04e4c3..caa5d42 100644
--- a/locale/src/lib.rs
+++ b/locale/src/lib.rs
@@ -452,6 +452,56 @@ mod tests {
assert!(missing.is_empty(), "no Dutch for:\n{}", missing.join("\n"));
}
+ /// Counted texts whose count is never 1, so they need no singular.
+ const NEVER_ONE: [&str; 1] = [
+ // Settings names one or two contacts, and counts from three.
+ "{} contacts",
+ ];
+
+ /// Counted texts that can still say "1 apps": each to be given its
+ /// singular, then taken off this list.
+ const NO_SINGULAR_YET: [&str; 2] = ["{} apps installed", "{} devices"];
+
+ /// A text that counts ("{} notes") has its singular beside it ("1
+ /// note", "One line", "the one thing"), which the program picks with a
+ /// `match` on the count, so nobody reads "the 1 things" (s948).
+ #[test]
+ fn every_counted_text_has_a_singular() {
+ let keys: Vec<&str> = nl::TEXTS.iter().map(|(en, _)| *en).collect();
+ let mut without: Vec<&str> = Vec::new();
+ for &text in &keys {
+ if NEVER_ONE.contains(&text) {
+ continue;
+ }
+ for (at, _) in text.match_indices("{} ") {
+ let word = text[at + 3..]
+ .split(|c: char| !c.is_ascii_alphabetic())
+ .next()
+ .unwrap_or("");
+ // A plural noun after the count, not a verb ("{} is", "{} was").
+ if word.len() < 3 || !word.ends_with('s') || ["has", "was", "does"].contains(&word) {
+ continue;
+ }
+ let (before, after) = (&text[..at], &text[at + 3 + word.len()..]);
+ let singular = &word[..word.len() - 1];
+ let has = ["1 ", "one ", "One "].iter().any(|one| {
+ let form = std::format!("{before}{one}{singular}{after}");
+ keys.contains(&form.as_str())
+ });
+ if !has {
+ without.push(text);
+ }
+ }
+ }
+ without.sort();
+ without.dedup();
+ assert_eq!(
+ without, NO_SINGULAR_YET,
+ "counted texts with no singular beside them: add one (\"1 note\" beside \"{{}} notes\") \
+ and pick it by the count, as notes.rs does"
+ );
+ }
+
/// The string literals in `source` given to `t(`, `tf(` or `locale::t(`.
fn asked(source: &str) -> Vec<std::string::String> {
let mut out = Vec::new();