function LocaleTranslation::getStringTranslation

Same name in other branches
  1. 9 core/modules/locale/src/LocaleTranslation.php \Drupal\locale\LocaleTranslation::getStringTranslation()
  2. 8.9.x core/modules/locale/src/LocaleTranslation.php \Drupal\locale\LocaleTranslation::getStringTranslation()
  3. 10 core/modules/locale/src/LocaleTranslation.php \Drupal\locale\LocaleTranslation::getStringTranslation()

Overrides TranslatorInterface::getStringTranslation

File

core/modules/locale/src/LocaleTranslation.php, line 111

Class

LocaleTranslation
String translator using the locale module.

Namespace

Drupal\locale

Code

public function getStringTranslation($langcode, $string, $context) {
    // If the language is not suitable for locale module, just return.
    if ($langcode == LanguageInterface::LANGCODE_SYSTEM || $langcode == 'en' && !$this->canTranslateEnglish()) {
        return FALSE;
    }
    // Strings are cached by langcode, context and roles, using instances of the
    // LocaleLookup class to handle string lookup and caching.
    if (!isset($this->translations[$langcode][$context])) {
        $this->translations[$langcode][$context] = new LocaleLookup($langcode, $context, $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack);
    }
    $translation = $this->translations[$langcode][$context]
        ->get($string);
    // If the translation is TRUE, no translation exists, but that string needs
    // to be stored in the persistent cache for performance reasons (so for
    // example, we don't have hundreds of queries to locale tables on each
    // request). That cache is persisted when the request ends, and the lookup
    // service is destroyed.
    return $translation === TRUE ? FALSE : $translation;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.