Detects which plural form to take.

@param int $n count of objects

@return int array index of the right plural form
188297
private function selectString($n)
    {
        if (is_null($this->pluralexpression)) {
            $this->pluralexpression = new ExpressionLanguage();
        }
        try {
            $plural = $this->pluralexpression->evaluate(
                $this->getPluralForms(),
                ['n' => $n]
            );
        } catch (\Exception $e) {
            $plural = 0;
        }

        if ($plural >= $this->pluralcount) {
            $plural = $this->pluralcount - 1;
        }

        return $plural;
    }
984997
protected function toWords($number)
    {
        $ret = '';

        if ($number === 0) {
            return $this->zero;
        }

        if ($number < 0) {
            $ret = $this->minus . $this->wordSeparator;
        }

        $numberGroups = $this->splitNumber(abs($number));
        $sizeOfNumberGroups = count($numberGroups);

        foreach ($numberGroups as $i => $numb) {
            $power = $sizeOfNumberGroups - $i;

            if ($numb !== 0) {
                if ($numb !== 1 || $power !== 2) {
                    $ret .= $this->showDigitsGroup(
                        $numb,
                        $i + 1 === $sizeOfNumberGroups || $power > 2
                    ) . $this->wordSeparator;
                }

                $ret .= self::$exponent[($power - 1) * 3];

                if ($power > 2 && $numb > 1) {
                    $ret .= $this->pluralSuffix;
                }

                $ret .= $this->wordSeparator;
            }
        }

        return rtrim($ret, $this->wordSeparator);
    }
581640
function ( number, pluralRules ) {
			var i,
				pluralForms = [ 'zero', 'one', 'two', 'few', 'many', 'other' ],
				pluralFormIndex = 0;

			for ( i = 0; i < pluralForms.length; i++ ) {
				if ( pluralRules[pluralForms[i]] ) {
					if ( pluralRuleParser( pluralRules[pluralForms[i]], number ) ) {
						return pluralFormIndex;
					}

					pluralFormIndex++;
				}
			}

			return pluralFormIndex;
		}
968530
public function txts($string, $n)
	{
		$args  = func_get_args();
		$count = count($args);

		if ($count > 1)
		{
			// Try the key from the language plural potential suffixes
			$found = false;
			$suffixes = $this->getPluralSuffixes((int) $n);
			array_unshift($suffixes, (int) $n);
			foreach ($suffixes as $suffix)
			{
				$key = $string . '_' . $suffix;
				if ($this->hasKey($key))
				{
					$found = true;
					break;
				}
			}
			if (!$found)
			{
				// Not found so revert to the original.
				$key = $string;
			}
			if (is_array($args[$count - 1]))
			{
				$args[0] = $this->translate(
					$key, array_key_exists('jsSafe', $args[$count - 1]) ? $args[$count - 1]['jsSafe'] : false,
					array_key_exists('interpretBackSlashes', $args[$count - 1]) ? $args[$count - 1]['interpretBackSlashes'] : true
				);
			}
			else
			{
				$args[0] = $this->translate($key);
			}
			return call_user_func_array('sprintf', $args);
		}
		elseif ($count > 0)
		{

			// Default to the normal sprintf handling.
			$args[0] = $this->translate($string);
			return call_user_func_array('sprintf', $args);
		}

		return '';
	}
771201
public function pluralize()
    {
        if($this->getParameter('upperCaseFirst') == 'true')
            return ucfirst(StringUtils::pluralize($this->getParameter('value')));

        return StringUtils::pluralize($this->getParameter('value'));
    }
468290
public function plural_name()
    {
        if ($name = $this->config()->get('plural_name')) {
            return $name;
        }
        $name = $this->singular_name();
        //if the penultimate character is not a vowel, replace "y" with "ies"
        if (preg_match('/[^aeiou]y$/i', $name)) {
            $name = substr($name, 0, -1) . 'ie';
        }
        return ucfirst($name . 's');
    }
524873
public function pluralize($word, $count = 0)
	{
		$result = strval($word);

		// If a counter is provided, and that equals 1
		// return as singular.
		if ($count === 1)
		{
			return $result;
		}

		if ( ! $this->isCountable($result))
		{
			return $result;
		}

		foreach ($this->pluralRules as $rule => $replacement)
		{
			if (preg_match($rule, $result))
			{
				$result = preg_replace($rule, $replacement, $result);
				break;
			}
		}

		return $result;
	}
13415
public function getSigFigs($n)
    {
        $n = ltrim($n, '0+-');
        $dp = strpos($n, '.'); // decimal position
        if ($dp === false) {
            $sigfigs = strlen(rtrim($n, '0'));
        } else {
            $sigfigs = strlen(ltrim($n, '0.')); // eliminate extra decimal character
            if ($dp !== 0) {
                $sigfigs--;
            }
        }
        return $sigfigs;
    }
935364
public static function pluralize($word)
    {
        //Get the cached noun of it exists
        if(isset(self::$_cache['pluralized'][$word])) {
            return self::$_cache['pluralized'][$word];
        }

        //Create the plural noun
        if (in_array($word, self::$_rules['countable'])) {
            self::$_cache['pluralized'][$word] = $word;
            return $word;
        }

        foreach (self::$_rules['pluralization'] as $regexp => $replacement)
        {
            $matches = null;
            $plural = preg_replace($regexp, $replacement, $word, -1, $matches);
            if ($matches > 0) {
                self::$_cache['pluralized'][$word] = $plural;
                return $plural;
            }
        }

        return $word;
    }
162465
public static function plural($n, $one, $two = NULL, $five = NULL)
	{
		if (is_array($one)) {
			$values = [Kohana_Arr::get($one, 0)];
			$values[1] = Kohana_Arr::get($one, 1, $values[0]);
			$values[2] = Kohana_Arr::get($one, 2, $values[1]);
		} else {
			$values = [$one];
			$values[1] = NULL !== $two ? $two : $one;
			$values[2] = NULL !== $five ? $five : $values[1];
		}

		$idx = $n % 10 == 1 && $n % 100 != 11
			? 0
			: ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20)
				? 1
				: 2
			);

		return $values[$idx];
	}
321118
protected function getPluralIndex($domain, $n, $fallback)
    {
        //Not loaded domain or translation, use a fallback
        if (!isset($this->plurals[$domain]) || $fallback === true) {
            return $n == 1 ? 0 : 1;
        }

        if (!isset($this->plurals[$domain]['function'])) {
            $code = self::fixTerseIfs($this->plurals[$domain]['code']);
            $this->plurals[$domain]['function'] = eval("return function (\$n) { $code };");
        }

        if ($this->plurals[$domain]['count'] <= 2) {
            return call_user_func($this->plurals[$domain]['function'], $n) ? 1 : 0;
        }

        return call_user_func($this->plurals[$domain]['function'], $n);
    }
172787
public static function pluralize($word) {
        foreach(self::$_exceptions as $exception) {
			if($exception['singular'] == $word){
				return $exception['plural'];
			}
        }

        return parent::pluralize($word);
	}
775846
public function left($n)
    {
        if ($n < 0 || $n > $this->size()) {
            return new MString($this->text);
        }

        $result = substr($this->text, 0, $n);

        if ($result === false) {
            return null;
        }

        return new MString($result);
    }
1085284
public static function pluralToSingular($pluralWordToCheck) {
        $listOfSingular = [
            'categories'    => 'category',
            'kb_item'       => 'knowledge base item',
            'list_email'    => 'email list',
            'listlist'      => 'list',
            'people'        => 'person',
            'peoples'       => 'person',
            'social'        => 'social site',
            'todo_item'     => 'to do item',
            'email_message' => 'email message',
        ];

        foreach ($listOfSingular as $plural => $singular) {

            if (strtolower($pluralWordToCheck) == strtolower($plural)) {
                return $singular;
            }
        }

        return $pluralWordToCheck;
    }
15096
public static function pluralize($string) {
        $g11n = G11n::registry();

        if (!$g11n->isEnabled()) {
            return $string;
        }

        return static::cache([__METHOD__, $string], function() use ($string, $g11n) {
            $string = mb_strtolower($string);
            $result = null;
            $inflections = $g11n->current()->getInflectionRules();

            if (!$inflections) {
                return $string;

            } else if (!empty($inflections['uninflected']) && in_array($string, $inflections['uninflected'])) {
                $result = $string;

            } else if (!empty($inflections['irregular']) && isset($inflections['irregular'][$string])) {
                $result = $inflections['irregular'][$string];

            } else if (!empty($inflections['irregular']) && in_array($string, $inflections['irregular'])) {
                $result = $string;

            } else if (!empty($inflections['plural'])) {
                foreach ($inflections['plural'] as $pattern => $replacement) {
                    if (preg_match($pattern, $string)) {
                        $result = preg_replace($pattern, $replacement, $string);
                        break;
                    }
                }
            }

            if (empty($result)) {
                $result = $string;
            }

            return $result;
        });
    }
94696
public function look($n, $o = 0)
    {
        if (!isset($this->bev)) {
            return false;
        }
        if ($this->bev->input->length <= $o) {
            return '';
        }
        return $this->bev->input->substr($o, $n);
    }
496209
private static function PluralLangGetForm($lang, $n)
    {
        switch ($lang) {
            case 'ach':
            case 'ak':
            case 'am':
            case 'arn':
            case 'br':
            case 'fil':
            case 'fr':
            case 'ln':
            case 'mfe':
            case 'mg':
            case 'mi':
            case 'oc':
            case 'ti':
            case 'tr':
            case 'wa':
                return (int)($n > 1);
            case 'af':
            case 'an':
            case 'ast':
            case 'az':
            case 'bg':
            case 'bn':
            case 'ca':
            case 'da':
            case 'de':
            case 'el':
            case 'en':
            case 'eo':
            case 'es':
            case 'et':
            case 'eu':
            case 'fi':
            case 'fo':
            case 'fur':
            case 'fy':
            case 'gl':
            case 'gu':
            case 'ha':
            case 'he':
            case 'hi':
            case 'hu':
            case 'ia':
            case 'it':
            case 'kn':
            case 'ku':
            case 'lb':
            case 'mai':
            case 'ml':
            case 'mn':
            case 'mr':
            case 'nah':
            case 'nap':
            case 'nb':
            case 'ne':
            case 'nl':
            case 'se':
            case 'nn':
            case 'no':
            case 'nso':
            case 'or':
            case 'ps':
            case 'pa':
            case 'pap':
            case 'pms':
            case 'pt':
            case 'rm':
            case 'sco':
            case 'si':
            case 'so':
            case 'son':
            case 'sq':
            case 'sw':
            case 'sv':
            case 'ta':
            case 'te':
            case 'tk':
            case 'ur':
            case 'yo':
                return (int)($n != 1);
            case 'jv':
                return (int)($n != 0);
            case 'ay':
            case 'bo':
            case 'cgg':
            case 'dz':
            case 'fa':
            case 'hy':
            case 'id':
            case 'ja':
            case 'jbo':
            case 'ka':
            case 'kk':
            case 'km':
            case 'ko':
            case 'ky':
            case 'lo':
            case 'ms':
            case 'sah':
            case 'su':
            case 'tg':
            case 'th':
            case 'tt':
            case 'ug':
            case 'uz':
            case 'vi':
            case 'wo':
            case 'zh':
                return (int)(0);

            case 'be':
            case 'bs':
            case 'hr':
            case 'ru':
            case 'sr':
            case 'uk':
                return (int)($n % 10 == 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2));
            case 'lt':
                return (int)($n % 10 == 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && ($n % 100 < 10 or $n % 100 >= 20) ? 1 : 2));
            case 'lv':
                return (int)($n % 10 == 1 && $n % 100 != 11 ? 0 : ($n != 0 ? 1 : 2));
            case 'mt':
                return (int)($n == 1 ? 0 : ($n == 0 || ($n % 100 > 1 && $n % 100 < 11) ? 1 : (($n % 100 > 10 && $n % 100 < 20) ? 2 : 3)));
            case 'pl':
                return (int)($n == 1 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2));
            case 'ar':
                return (int)($n == 0 ? 0 : ($n == 1 ? 1 : ($n == 2 ? 2 : ($n % 100 >= 3 && $n % 100 <= 10 ? 3 : ($n % 100 >= 11 ? 4 : 5)))));
            case 'gd':
                return (int)(($n == 1 || $n == 11) ? 0 : (($n == 2 || $n == 12) ? 1 : (($n > 2 && $n < 20) ? 2 : 3)));
            case 'is':
                return (int)($n % 10 != 1 || $n % 100 == 11);

            case 'cs':
            case 'sk':
                return (int)(($n == 1) ? 0 : (($n >= 2 && $n <= 4) ? 1 : 2));
            case 'cy':
                return (int)(($n == 1) ? 0 : (($n == 2) ? 1 : (($n != 8 && $n != 11) ? 2 : 3)));
            case 'ga':
                return (int)(($n == 1) ? 0 : (($n == 2) ? 1 : ($n < 7 ? 2 : ($n < 11 ? 3 : 4))));
            case 'kw':
                return (int)(($n == 1) ? 0 : (($n == 2) ? 1 : (($n == 3) ? 2 : 3)));

            case 'mk':
                return (int)(($n == 1 || $n % 10 == 1) ? 0 : 1);
            case 'mnk':
                return (int)($n == 0 ? 0 : ($n == 1 ? 1 : 2));

            case 'ro':
                return (int)($n == 1 ? 0 : (($n == 0 || ($n % 100 > 0 && $n % 100 < 20)) ? 1 : 2));
            case 'sl':
                return (int)($n % 100 == 1 ? 1 : ($n % 100 == 2 ? 2 : ($n % 100 == 3 || $n % 100 == 4 ? 3 : 0)));
            default:
                return 0;
        }
    }