protected function LocaleLookup::resolveCacheMiss

Implements CacheArray::resolveCacheMiss().

Overrides CacheArray::resolveCacheMiss

File

drupal/core/modules/locale/lib/Drupal/locale/LocaleLookup.php, line 56
Definition of LocaleLookup

Class

LocaleLookup
Extends CacheArray to allow for dynamic building of the locale cache.

Namespace

Drupal\locale

Code

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;
  }
  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' => VERSION,
    ))
      ->addLocation('path', request_uri())
      ->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;
}