Commit 125cfd58 authored by webchick's avatar webchick

Issue #2202143 by alexpott, benjy: Multiple calls to ConfigFactory::get()...

Issue #2202143 by alexpott, benjy: Multiple calls to ConfigFactory::get() inside t() is unnecessary.
parent 5d5ccc49
......@@ -62,6 +62,13 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface {
*/
protected $lock;
/**
* The translate english configuration value.
*
* @var bool
*/
protected $translateEnglish;
/**
* Constructs a translator using a string storage.
*
......@@ -86,8 +93,7 @@ public function __construct(StringStorageInterface $storage, CacheBackendInterfa
*/
public function getStringTranslation($langcode, $string, $context) {
// If the language is not suitable for locale module, just return.
$translate_english = $this->configFactory->get('locale.settings')->get('translate_english');
if ($langcode == Language::LANGCODE_SYSTEM || ($langcode == 'en' && !$translate_english)) {
if ($langcode == Language::LANGCODE_SYSTEM || ($langcode == 'en' && !$this->canTranslateEnglish())) {
return FALSE;
}
// Strings are cached by langcode, context and roles, using instances of the
......@@ -99,10 +105,24 @@ public function getStringTranslation($langcode, $string, $context) {
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 = array();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment