fix(i18n): Restrict Polish plural One to n == 1 per CLDR rules

Polish integer plural rules use Plural::One strictly for n == 1, while
higher counts ending in 1 (e.g. 21, 101) use Plural::Many.
Also adds unit tests for Polish integer plural coverage.

Co-Authored-By: Antigravity <noreply@google.com>
This commit is contained in:
LucasandAntigravity committed 2026-10-18 14:45:19 +02:00
1 parent 9ae3223d22
commit 32bc822451
2 files changed
+24 -2

No files matched your search

+2 -1
View File
@@ -171,7 +171,8 @@ fn plural(code: &str, n: usize) -> Plural {
"cs" if n == 1 => Plural::One,
"cs" if (2..=4).contains(&n) => Plural::Few,
"cs" => Plural::Other,
"ru" | "pl" if n % 10 == 1 && n % 100 != 11 => Plural::One,
"pl" if n == 1 => Plural::One,
"ru" if n % 10 == 1 && n % 100 != 11 => Plural::One,
"ru" | "pl" if (2..=4).contains(&(n % 10)) && !(12..=14).contains(&(n % 100)) => Plural::Few,
"ru" | "pl" => Plural::Many,
"ja" | "ko" | "zh-Hans" => Plural::Other,
+22 -1
View File
@@ -400,7 +400,7 @@ fn french_and_portuguese_count_zero_as_singular() {
for code in ["fr", "pt-BR"] {
assert!(one(code, 0) && one(code, 1) && !one(code, 2), "{code}");
}
for code in ["en", "es", "de", "cs"] {
for code in ["en", "es", "de", "cs", "pl"] {
for n in [0, 1, 2, 3, 4, 5, 21] {
assert_eq!(one(code, n), n == 1, "{code}: {n}");
}
@@ -493,6 +493,27 @@ fn russian_language_tags_and_integer_plurals() {
}
}
#[test]
fn polish_integer_plurals() {
let pl = LANGS.iter().position(|l| l.code == "pl").unwrap();
assert_eq!(LANGS[pl].name, "Polski");
assert_eq!(plural("pl", 1), Plural::One);
assert_eq!(fill(counted(pl, "{n} layers", 1), &[("n", &1)]), "1 warstwa");
for n in [2, 3, 4, 22, 23, 24, 102, 104, 1_002] {
assert_eq!(plural("pl", n), Plural::Few, "{n}");
assert_eq!(fill(counted(pl, "{n} layers", n), &[("n", &n)]), format!("{n} warstwy"));
}
for n in [0, 5, 10, 11, 12, 13, 14, 19, 20, 21, 25, 31, 100, 101, 111, 112, 114, 1_000_000] {
assert_eq!(plural("pl", n), Plural::Many, "{n}");
assert_eq!(fill(counted(pl, "{n} layers", n), &[("n", &n)]), format!("{n} warstw"));
}
for (key, text) in LANGS[pl].ui {
if let Text::Plural { one, few, many, .. } = text {
assert!(one.is_some() && few.is_some() && many.is_some(), "{key}: missing Polish plural forms");
}
}
}
#[test]
fn plural_fallback_uses_the_language_of_its_catalog() {
let la = LANGS.iter().position(|l| l.code == "es-419").unwrap();