diff --git a/core/modules/locale/src/LocaleLookup.php b/core/modules/locale/src/LocaleLookup.php index 6bcb88c..4c46968 100644 --- a/core/modules/locale/src/LocaleLookup.php +++ b/core/modules/locale/src/LocaleLookup.php @@ -132,24 +132,48 @@ protected function getCid() { * {@inheritdoc} */ protected function resolveCacheMiss($offset) { - $translation = $this->stringStorage->findTranslation(array( - 'language' => $this->langcode, - 'source' => $offset, - 'context' => $this->context, - )); - - if ($translation) { - $value = !empty($translation->translation) ? $translation->translation : TRUE; + 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; } 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->requestStack->getCurrentRequest()->getRequestUri())->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 @@ -172,11 +196,6 @@ 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); }