reverted: --- b/core/modules/locale/lib/Drupal/locale/LocaleLookup.php +++ a/core/modules/locale/lib/Drupal/locale/LocaleLookup.php @@ -54,49 +54,39 @@ * Overrides DrupalCacheArray::resolveCacheMiss(). */ protected function resolveCacheMiss($offset) { + $translation = $this->stringStorage->findTranslation(array( + // These are the search conditions. + 'language' => $this->langcode, + 'source' => $offset, + 'context' => $this->context + ), array( + // Search options. We just need this limited set of fields. + 'fields' => array('lid', 'version', 'translation'), + )); - if (isset($this->stringStorage)) { - $translation = $this->stringStorage->findTranslation(array( - // These are the search conditions. - 'language' => $this->langcode, - 'source' => $offset, - 'context' => $this->context - ), array( - // Search options. We just need this limited set of fields. - 'fields' => array('lid', 'version', 'translation'), - )); + if ($translation) { + $this->stringStorage->checkVersion($translation, VERSION); + $value = !empty($translation->translation) ? $translation->translation : TRUE; - if ($translation) { - $this->stringStorage->checkVersion($translation, VERSION); - $value = !empty($translation->translation) ? $translation->translation : TRUE; - } - else { - // We don't have the source string, update the {locales_source} table to - // indicate the string is not translated. - $this->stringStorage->createString(array( - 'source' => $offset, - 'context' => $this->context, - 'location' => request_uri(), - 'version' => VERSION - ))->save(); - $value = TRUE; - } - $this->storage[$offset] = $value; - // Disabling the usage of string caching allows a module to watch for - // the exact list of strings used on a page. From a performance - // perspective that is a really bad idea, so we have no user - // interface for this. Be careful when turning this option off! - if (variable_get('locale_cache_strings', 1)) { - $this->persist($offset); - } - return $value; } else { + // We don't have the source string, update the {locales_source} table to + // indicate the string is not translated. + $this->stringStorage->createString(array( + 'source' => $offset, + 'context' => $this->context, + 'location' => request_uri(), + 'version' => VERSION + ))->save(); + $value = TRUE; - // We are running without a locale storage so all we've got are cached - // strings. We must return a valid value anyway, but we shouldn't make - // it persistent. - $this->storage[$offset] = TRUE; - return TRUE; } + $this->storage[$offset] = $value; + // Disabling the usage of string caching allows a module to watch for + // the exact list of strings used on a page. From a performance + // perspective that is a really bad idea, so we have no user + // interface for this. Be careful when turning this option off! + if (variable_get('locale_cache_strings', 1)) { + $this->persist($offset); + } + return $value; - } } reverted: --- b/core/modules/locale/locale.module +++ a/core/modules/locale/locale.module @@ -13,9 +13,9 @@ use Drupal\locale\LocaleLookup; use Drupal\locale\LocaleConfigSubscriber; use Drupal\locale\SourceString; +use Drupal\locale\StringDatabaseStorage; use Drupal\locale\TranslationsStream; +use Drupal\Core\Database\Database; -use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; /** * Regular expression pattern used to localize JavaScript strings. @@ -294,17 +294,12 @@ * @return Drupal\locale\StringStorageInterface */ function locale_storage() { + $storage = &drupal_static(__FUNCTION__); + if (!isset($storage)) { + $options = array('target' => 'default'); + $storage = new StringDatabaseStorage(Database::getConnection($options['target']), $options); - try { - return drupal_container()->get('locale.storage'); - } - catch (InvalidArgumentException $e) { - // Running locale functions when the storage is not initialized is a bad - // symptom of something gone really wrong. This happens though under some - // race conditions (like locale module just disabled but printing some - // message during the same request. Since this code may be invoked - // to localize and display exceptions we do need to handle this case. - return NULL; } + return $storage; } /** only in patch2: unchanged: --- a/core/modules/locale/src/LocaleLookup.php +++ b/core/modules/locale/src/LocaleLookup.php @@ -104,24 +104,49 @@ public function __construct($langcode, $context, StringStorageInterface $string_ * {@inheritdoc} */ protected function resolveCacheMiss($offset) { - $translation = $this->stringStorage->findTranslation(array( - 'language' => $this->langcode, - 'source' => $offset, - 'context' => $this->context, - )); - - if ($translation) { + if (isset($this->stringStorage)) { + $translation = $this->stringStorage->findTranslation(array( + // These are the search conditions. + 'language' => $this->langcode, + 'source' => $offset, + 'context' => $this->context + ), array( + // Search options. We just need this limited set of fields. + 'fields' => array('lid', 'version', 'translation'), + )); + + if ($translation) { + $this->stringStorage->checkVersion($translation, VERSION); + $value = !empty($translation->translation) ? $translation->translation : TRUE; + } + else { + // We don't have the source string, update the {locales_source} table to + // indicate the string is not translated. + $this->stringStorage->createString(array( + 'source' => $offset, + 'context' => $this->context, + 'location' => request_uri(), + 'version' => VERSION + ))->save(); + $value = TRUE; + } + $this->storage[$offset] = $value; + // Disabling the usage of string caching allows a module to watch for + // the exact list of strings used on a page. From a performance + // perspective that is a really bad idea, so we have no user + // interface for this. Be careful when turning this option off! + if (variable_get('locale_cache_strings', 1)) { + $this->persist($offset); + } + return $value; $value = !empty($translation->translation) ? $translation->translation : TRUE; } else { - // We don't have the source string, update the {locales_source} table to - // indicate the string is not translated. - $this->stringStorage->createString(array( - 'source' => $offset, - 'context' => $this->context, - 'version' => \Drupal::VERSION - ))->addLocation('path', $this->requestUri())->save(); - $value = TRUE; + // We are running without a locale storage so all we've got are cached + // strings. We must return a valid value anyway, but we shouldn't make + // it persistent. + $this->storage[$offset] = TRUE; + return TRUE; } // If there is no translation available for the current language then use @@ -144,11 +169,7 @@ protected function resolveCacheMiss($offset) { } } - $this->storage[$offset] = $value; - // Disabling the usage of string caching allows a module to watch for - // the exact list of strings used on a page. From a performance - // perspective that is a really bad idea, so we have no user - // interface for this. Be careful when turning this option off! + if ($this->configFactory->get('locale.settings')->get('cache_strings')) { $this->persist($offset); }