using System; using System.Collections.Generic; using System.Globalization; using System.Text; using Jeffijoe.MessageFormat; namespace WinWARP.Ui.Helpers; /// /// Provides methods to determine the plural category of a number based on the specified locale and whether it is an ordinal or cardinal number. /// public static class PluralCategory { private static readonly MessageFormatter Formatter = new(); private static readonly string CardinalPattern = "{n, plural, zero{zero} one{one} two{two} few{few} many{many} other{other}}"; private static readonly string OrdinalPattern = "{n, selectordinal, zero{zero} one{one} two{two} few{few} many{many} other{other}}"; public static string GetCategory(double number, CultureInfo locale, bool isOrdinal = false) { var pattern = isOrdinal ? OrdinalPattern : CardinalPattern; var args = new Dictionary { { "n", number } }; // Formatter resolves the logic and returns the matched keyword block literal return Formatter.FormatMessage(pattern, args, locale); } }