storage = $storage; $this->cache = $cache; $this->lock = $lock; $this->configFactory = $config_factory; $this->languageManager = $language_manager; $this->requestStack = $request_stack; } /** * {@inheritdoc} */ 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); return $translation === TRUE ? FALSE : $translation; } /** * Gets translate english configuration value. * * @return bool * TRUE if english should be translated, FALSE if not. */ protected function canTranslateEnglish() { if (!isset($this->translateEnglish)) { $this->translateEnglish = $this->configFactory->get('locale.settings')->get('translate_english'); } return $this->translateEnglish; } /** * {@inheritdoc} */ public function reset() { unset($this->translateEnglish); $this->translations = []; } /** * {@inheritdoc} */ public function destruct() { foreach ($this->translations as $context) { foreach ($context as $lookup) { if ($lookup instanceof DestructableInterface) { $lookup->destruct(); } } } } }