locale_get_plural

Versions
4.6 – 5
locale_get_plural($count)
6 – 7
locale_get_plural($count, $langcode = NULL)

Returns plural form index for a specific number.

The index is computed from the formula of this language.

Parameters

$count Number to return plural for.

$langcode Optional language code to translate to a language other than what is used to display the page.

Code

modules/locale/locale.module, line 401

<?php
function locale_get_plural($count, $langcode = NULL) {
  global $language;
  static $locale_formula, $plurals = array();

  $langcode = $langcode ? $langcode : $language->language;

  if (!isset($plurals[$langcode][$count])) {
    if (!isset($locale_formula)) {
      $language_list = language_list();
      $locale_formula[$langcode] = $language_list[$langcode]->formula;
    }
    if ($locale_formula[$langcode]) {
      $n = $count;
      $plurals[$langcode][$count] = @eval('return intval('. $locale_formula[$langcode] .');');
      return $plurals[$langcode][$count];
    }
    else {
      $plurals[$langcode][$count] = -1;
      return -1;
    }
  }
  return $plurals[$langcode][$count];
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.