diff --git a/core/modules/locale/lib/Drupal/locale/LocaleBundle.php b/core/modules/locale/lib/Drupal/locale/LocaleBundle.php new file mode 100644 index 0000000..811c1ce --- /dev/null +++ b/core/modules/locale/lib/Drupal/locale/LocaleBundle.php @@ -0,0 +1,30 @@ +register('locale.storage', 'Drupal\locale\StringDatabaseStorage') + ->addArgument(new Reference('database')) + ->addArgument(array('target' => 'default')); + } +} diff --git a/core/modules/locale/src/LocaleLookup.php b/core/modules/locale/src/LocaleLookup.php index 6bcb88c..0697d2f 100644 --- a/core/modules/locale/src/LocaleLookup.php +++ b/core/modules/locale/src/LocaleLookup.php @@ -132,24 +132,49 @@ protected function getCid() { * {@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->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,15 +197,10 @@ 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); } return $value; } - }