PluralFormula::getNumberOfPlurals

public PluralFormula::getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

null|string $langcode: (optional) The language code. If not provided, the current language will be used.

Return value

int Number of plural variants supported by the given language.

Overrides PluralFormulaInterface::getNumberOfPlurals

File

core/modules/locale/src/PluralFormula.php, line 70

Class

PluralFormula
Manages the storage of plural formula per language in state.

Namespace

Drupal\locale

Code

public function getNumberOfPlurals($langcode = NULL) {
  // Ensure that the formulae are loaded.
  $this->loadFormulae();

  // Set the langcode to use.
  $langcode = $langcode ? : $this->languageManager->getCurrentLanguage()->getId();

  // We assume 2 plurals if there is no explicit information yet.
  if (!isset($this->formulae[$langcode]['plurals'])) {
    return 2;
  }
  return $this->formulae[$langcode]['plurals'];
}
doc_Drupal
2016-10-29 09:34:15
Comments
Leave a Comment

Please login to continue.