Class PluralRules
Utility class used to determine the plural number to be used for a variable based on the locale.
Property Summary
-
$_rulesMap protected static
array<string, int>A map of locale => plurals group used to determine which plural rules apply to the language
-
$callableRulesMap protected static
array<string, \Closure(int): int>A map of locale => function that overrides the above map. Such functions directly resolve the plural form number.
Method Summary
-
calculate() public static
Returns the plural form number for the passed locale corresponding to the countable provided in $n.
-
resetRules() public static
Remove any custom rule previously set.
-
setRule() public static
Set a custom plural rule.
Method Detail
calculate() ¶ public static
calculate(string $locale, int $n): int
Returns the plural form number for the passed locale corresponding to the countable provided in $n.
Parameters
-
string$locale The locale to get the rule calculated for.
-
int$n The number to apply the rules to.
Returns
intThe plural rule number that should be used.
Links
setRule() ¶ public static
setRule(string $locale, Closure(int): int $resolver): void
Set a custom plural rule.
Parameters
-
string$locale The locale on which the plural rule is applied.
-
Closure(int): int$resolver A function that takes a plural number and returns the plural form number for $locale.
Returns
voidThrows
InvalidArgumentExceptionIf $locale is invalid.
Property Detail
$_rulesMap ¶ protected static
A map of locale => plurals group used to determine which plural rules apply to the language
Type
array<string, int>$callableRulesMap ¶ protected static
A map of locale => function that overrides the above map. Such functions directly resolve the plural form number.
Type
array<string, \Closure(int): int>