From 125cfd5849ae4c6d1189ad8ed734e4053c7d8442 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Tue, 4 Mar 2014 13:32:29 -0800 Subject: [PATCH] Issue #2202143 by alexpott, benjy: Multiple calls to ConfigFactory::get() inside t() is unnecessary. --- .../lib/Drupal/locale/LocaleTranslation.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/core/modules/locale/lib/Drupal/locale/LocaleTranslation.php b/core/modules/locale/lib/Drupal/locale/LocaleTranslation.php index 2c4590fd97c3..e6a7ac93cc21 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleTranslation.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleTranslation.php @@ -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(); } -- GitLab