Skip to content

Format count in context plural strings and use FormatProvider for context strings - #61

Merged
perpetualKid merged 1 commit into
perpetualKid:mainfrom
vtxe02023274:fix/particular-plural-format
Nov 26, 2026
Merged

perpetualKid merged 1 commit into
perpetualKid:mainfrom
vtxe02023274:fix/particular-plural-format

Conversation

@vtxe02023274

Copy link
Copy Markdown

GetPluralString(text, pluralText, n) formats the result with n, but its context counterpart GetParticularPluralString(context, text, pluralText, n) returns the raw string:

var t = new Catalog(new CultureInfo("en-US"));
t.GetPluralString("{0} apple", "{0} apples", 2);                       // "2 apples"
t.GetParticularPluralString("ctx", "{0} apple", "{0} apples", 2);      // "{0} apples"

This also shows up in the WPF Gettext markup extension: with Count and no context it goes through GetPluralString and shows 3 items, adding Context sends it to GetParticularPluralString and it shows {0} items.

GetParticularString(context, text, args) also formats with CultureInfo while every other formatting overload uses FormatProvider, so a custom FormatProvider is ignored only there.

Changes:

  • GetParticularPluralString(context, text, pluralText, n) formats with n, same as GetPluralString(text, pluralText, n)
  • GetParticularString(context, text, args) uses FormatProvider

Tests: two new tests in CatalogTest fail before the change and pass after. All test projects pass on net10.0 and net48.

@perpetualKid
perpetualKid merged commit 1a311dc into perpetualKid:main Nov 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants