pluralLogic method
Internal: Implements the logic for plural selection - use plural for normal messages.
Implementation
static pluralLogic(int howMany,
{zero, one, two, few, many, other, String locale, String meaning}) {
if (other == null) {
throw new ArgumentError("The 'other' named argument must be provided");
}
if (howMany == null) {
throw new ArgumentError("The howMany argument to plural cannot be null");
}
// If there's an explicit case for the exact number, we use it. This is not
// strictly in accord with the CLDR rules, but it seems to be the
// expectation. At least I see e.g. Russian translations that have a zero
// case defined. The rule for that locale will never produce a zero, and
// treats it as other. But it seems reasonable that, even if the language
// rules treat zero as other, we might want a special message for zero.
if (howMany == 0 && zero != null) return zero;
if (howMany == 1 && one != null) return one;
if (howMany == 2 && two != null) return two;
var pluralRule = _pluralRule(locale, howMany);
var pluralCase = pluralRule();
switch (pluralCase) {
case plural_rules.PluralCase.ZERO:
return zero ?? other;
case plural_rules.PluralCase.ONE:
return one ?? other;
case plural_rules.PluralCase.TWO:
return two ?? few ?? other;
case plural_rules.PluralCase.FEW:
return few ?? other;
case plural_rules.PluralCase.MANY:
return many ?? other;
case plural_rules.PluralCase.OTHER:
return other;
default:
throw new ArgumentError.value(
howMany, "howMany", "Invalid plural argument");
}
}