You are here

function locale_get_plural in Drupal 6

Same name and namespace in other branches
  1. 8 core/modules/locale/locale.module \locale_get_plural()
  2. 4 modules/locale.module \locale_get_plural()
  3. 5 modules/locale/locale.module \locale_get_plural()
  4. 7 modules/locale/locale.module \locale_get_plural()
  5. 9 core/modules/locale/locale.module \locale_get_plural()
  6. 10 core/modules/locale/locale.module \locale_get_plural()

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.

1 call to locale_get_plural()
format_plural in includes/common.inc
Format a string containing a count of items.
1 string reference to 'locale_get_plural'
format_plural in includes/common.inc
Format a string containing a count of items.

File

modules/locale/locale.module, line 411
Add language handling functionality and enables the translation of the user interface to languages other than English.

Code

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];
}