Neos\Flow\I18n\Cldr\Reader\PluralsReader::getPluralForm PHP Méthode

getPluralForm() public méthode

Plural form is one of following: zero, one, two, few, many, other. Last one (other) is returned when number provided doesn't match any of the rules, or there is no rules for given locale.
public getPluralForm ( mixed $quantity, Locale $locale ) : string
$quantity mixed A number to find plural form for (float or int)
$locale Neos\Flow\I18n\Locale
Résultat string One of plural form constants
    public function getPluralForm($quantity, Locale $locale)
    {
        if (!isset($this->rulesetsIndices[$locale->getLanguage()])) {
            return self::RULE_OTHER;
        }
        $ruleset = $this->rulesets[$locale->getLanguage()][$this->rulesetsIndices[$locale->getLanguage()]];
        if ($ruleset === null) {
            return self::RULE_OTHER;
        }
        foreach ($ruleset as $form => $rule) {
            foreach ($rule as $subrule) {
                $subrulePassed = false;
                if ($subrule['modulo'] !== false) {
                    $quantity = fmod($quantity, $subrule['modulo']);
                }
                if ($quantity == floor($quantity)) {
                    $quantity = (int) $quantity;
                }
                $condition = $subrule['condition'];
                switch ($condition[0]) {
                    case 'is':
                    case 'isnot':
                        if (is_int($quantity) && $quantity === $condition[1]) {
                            $subrulePassed = true;
                        }
                        if ($condition[0] === 'isnot') {
                            $subrulePassed = !$subrulePassed;
                        }
                        break;
                    case 'in':
                    case 'notin':
                        if (is_int($quantity) && $quantity >= $condition[1] && $quantity <= $condition[2]) {
                            $subrulePassed = true;
                        }
                        if ($condition[0] === 'notin') {
                            $subrulePassed = !$subrulePassed;
                        }
                        break;
                    case 'within':
                    case 'notwithin':
                        if ($quantity >= $condition[1] && $quantity <= $condition[2]) {
                            $subrulePassed = true;
                        }
                        if ($condition[0] === 'notwithin') {
                            $subrulePassed = !$subrulePassed;
                        }
                        break;
                }
                if ($subrulePassed && $subrule['logicalOperator'] === 'or' || !$subrulePassed && $subrule['logicalOperator'] === 'and') {
                    break;
                }
            }
            if ($subrulePassed) {
                return $form;
            }
        }
        return self::RULE_OTHER;
    }

Usage Example

 /**
  * Get the plural form to be used.
  *
  * If $quantity is numeric and non-NULL, the plural form for provided $locale will be
  * chosen according to it.
  *
  * In all other cases, NULL is returned.
  *
  * @param mixed $quantity
  * @param Locale $locale
  * @return string
  */
 protected function getPluralForm($quantity, Locale $locale)
 {
     if (!is_numeric($quantity)) {
         return null;
     } else {
         return $this->pluralsReader->getPluralForm($quantity, $locale);
     }
 }
All Usage Examples Of Neos\Flow\I18n\Cldr\Reader\PluralsReader::getPluralForm