Chris@0: storage = $storage; Chris@0: $this->cache = $cache; Chris@0: $this->lock = $lock; Chris@0: $this->configFactory = $config_factory; Chris@0: $this->languageManager = $language_manager; Chris@0: $this->requestStack = $request_stack; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getStringTranslation($langcode, $string, $context) { Chris@0: // If the language is not suitable for locale module, just return. Chris@0: if ($langcode == LanguageInterface::LANGCODE_SYSTEM || ($langcode == 'en' && !$this->canTranslateEnglish())) { Chris@0: return FALSE; Chris@0: } Chris@0: // Strings are cached by langcode, context and roles, using instances of the Chris@0: // LocaleLookup class to handle string lookup and caching. Chris@0: if (!isset($this->translations[$langcode][$context])) { Chris@0: $this->translations[$langcode][$context] = new LocaleLookup($langcode, $context, $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack); Chris@0: } Chris@0: $translation = $this->translations[$langcode][$context]->get($string); Chris@0: return $translation === TRUE ? FALSE : $translation; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets translate english configuration value. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if english should be translated, FALSE if not. Chris@0: */ Chris@0: protected function canTranslateEnglish() { Chris@0: if (!isset($this->translateEnglish)) { Chris@0: $this->translateEnglish = $this->configFactory->get('locale.settings')->get('translate_english'); Chris@0: } Chris@0: return $this->translateEnglish; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function reset() { Chris@0: unset($this->translateEnglish); Chris@0: $this->translations = []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function destruct() { Chris@0: foreach ($this->translations as $context) { Chris@0: foreach ($context as $lookup) { Chris@0: if ($lookup instanceof DestructableInterface) { Chris@0: $lookup->destruct(); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }