select<T extends Object?> method

T select<T extends Object?>(
  1. num count, {
  2. T? zero,
  3. T? one,
  4. T? two,
  5. T? few,
  6. T? many,
  7. required T other,
})

Returns the appropriate plural form for count among the options.

Evaluates the locale's plural category for count and returns the corresponding value (zero, one, two, few, many), falling back to other if that category value is not specified.

Example for English (en-US):

final rules = PluralRules(locale: Locale.parse('en-US'));
print(rules.select(2, one: 'message', other: 'messages')); // messages
print(rules.select(1, one: 'message', other: 'messages')); // message
print(rules.select(0, one: 'message', other: 'messages')); // messages

Implementation

T select<T extends Object?>(
  num count, {
  T? zero,
  T? one,
  T? two,
  T? few,
  T? many,
  required T other,
}) => isInTest
    ? other
    : switch (_pluralRulesImpl.selectImpl(count)) {
        PluralCategory.zero => zero ?? other,
        PluralCategory.one => one ?? other,
        PluralCategory.two => two ?? other,
        PluralCategory.few => few ?? other,
        PluralCategory.many => many ?? other,
        PluralCategory.other => other,
      };