diff --git a/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php index 6c1d4c9..80365ad 100644 --- a/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php +++ b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php @@ -150,7 +150,13 @@ public function render() { * @return int */ protected function getPluralIndex() { - if (function_exists('locale_get_plural')) { + // We have to test both if the function exists and the service since in certain + // certain situations it is possible that locale code might be loaded but + // the service does not exist. For example, where the parent test site has + // locale installed but the child site does not. + // @todo Refactor in https://www.drupal.org/node/2660338 so this code does + // not depend on knowing that the Locale module exists. + if (function_exists('locale_get_plural') && \Drupal::hasService('locale.plural.formula')) { return locale_get_plural($this->count, $this->getOption('langcode')); } return -1; diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index f9f5226..74b76ec 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -283,9 +283,7 @@ function locale_get_plural($count, $langcode = NULL) { if (!isset($plural_indexes[$langcode][$count])) { // Retrieve and statically cache the plural formulas for all languages. - if (\Drupal::hasService('locale.plural.formula')) { - $plural_formulas = \Drupal::service('locale.plural.formula')->getFormula($langcode); - } + $plural_formulas = \Drupal::service('locale.plural.formula')->getFormula($langcode); // 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