function locale_get_plural

cis7 locale.module locale_get_plural($count, $langcode = NULL)
cle7 locale.module locale_get_plural($count, $langcode = NULL)
elmsmedia7 locale.module locale_get_plural($count, $langcode = NULL)
icor7 locale.module locale_get_plural($count, $langcode = NULL)
meedjum_blog7 locale.module locale_get_plural($count, $langcode = NULL)
mooc7 locale.module 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.

Return value

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.

2 calls to locale_get_plural()
format_plural in includes/common.inc
Formats a string containing a count of items.
locale_test_plural_format_page in modules/locale/tests/locale_test.module
Returns markup for locale_get_plural testing.
1 string reference to 'locale_get_plural'
format_plural in includes/common.inc
Formats a string containing a count of items.

File

modules/locale/locale.module, line 782
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;

  // 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->language;

  if (!isset($plural_indexes[$langcode][$count])) {
    // Retrieve and statically cache the plural formulas for all languages.
    if (empty($plural_formulas)) {
      foreach (language_list() as $installed_language) {
        $plural_formulas[$installed_language->language] = $installed_language->formula;
      }
    }
    // 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] . ');');
    }
    // In case there is no plural formula for English (no imported translation
    // for English), use a default formula.
    elseif ($langcode == 'en') {
      $plural_indexes[$langcode][$count] = (int) ($count != 1);
    }
    // Otherwise, return -1 (unknown).
    else {
      $plural_indexes[$langcode][$count] = -1;
    }
  }
  return $plural_indexes[$langcode][$count];
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.