Returns plural form index for a specific number.
The index is computed from the formula of this language.
$count: Number to return plural for.
$langcode: Optional language code to translate to a language other than what is used to display the page.
The numeric index of the plural variant to use for this $langcode and $count combination or -1 if the language was not found or does not have a plural formula.
function locale_get_plural($count, $langcode = NULL) {
$language_interface = language(LANGUAGE_TYPE_INTERFACE);
// Used to locally cache the plural formulas for all languages.
$plural_formulas =& drupal_static(__FUNCTION__, array());
// Used to store precomputed plural indexes corresponding to numbers
// individually for each language.
$plural_indexes =& drupal_static(__FUNCTION__ . ':plurals', array());
$langcode = $langcode ? $langcode : $language_interface->langcode;
if (!isset($plural_indexes[$langcode][$count])) {
// Retrieve and statically cache the plural formulas for all languages.
if (empty($plural_formulas)) {
$plural_formulas = variable_get('locale_translation_plurals', array());
}
// If there is a plural formula for the language, evaluate it for the given
// $count and statically cache the result for the combination of language
// and count, since the result will always be identical.
if (!empty($plural_formulas[$langcode])) {
// $n is used inside the expression in the eval().
$n = $count;
$plural_indexes[$langcode][$count] = @eval('return intval(' . $plural_formulas[$langcode]['formula'] . ');');
}
elseif ($langcode == 'en') {
$plural_indexes[$langcode][$count] = (int) ($count != 1);
}
else {
$plural_indexes[$langcode][$count] = -1;
}
}
return $plural_indexes[$langcode][$count];
}