Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: PluralRules for Czech locale #325

Merged
merged 3 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ public void Test_Russian()
});
}

[Test]
public void Test_Czech()
{
TestAllResults(
new CultureInfo("cs"),
"{0:plural:Nemáte zprávu|Máte {} zprávu|Přišly Vám {} zprávy|Přišlo Vám {} zpráv}!",
new ExpectedResults {
{ 0, "Nemáte zprávu!"},
{ 1, "Máte 1 zprávu!"},
{ 2, "Přišly Vám 2 zprávy!"},
{ 4, "Přišly Vám 4 zprávy!"},
{ 5, "Přišlo Vám 5 zpráv!"},
{ 6, "Přišlo Vám 6 zpráv!"},
});
}

[Test]
public void Test_Polish()
{
Expand Down
11 changes: 7 additions & 4 deletions src/SmartFormat/Utilities/PluralRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,12 @@ private static int GetWordsCount4Value(decimal n)
_ => 5 // other
};
private static PluralRuleDelegate Czech => (value, pluralWordsCount) =>
value == 1 ? 0 : // one
value.Between(2, 4) ? 1 : // few
2;
value == 0 ? 0 : // zero
value == 1 ? 1 : // one
value.Between(2, 4) ? 2 : // few
value % 1 == 0 ? 3 : // many
4; // other

private static PluralRuleDelegate Welsh => (value, pluralWordsCount) =>
value switch
{
Expand Down Expand Up @@ -371,4 +374,4 @@ private static bool Between(this decimal value, decimal min, decimal max)
}
#pragma warning restore S3358
#pragma warning restore S3776
}
}