diff --git a/core/modules/locale/config/locale.settings.yml b/core/modules/locale/config/locale.settings.yml index 16b08ff..bca6562 100644 --- a/core/modules/locale/config/locale.settings.yml +++ b/core/modules/locale/config/locale.settings.yml @@ -1,4 +1,5 @@ cache_strings: '1' +translate_english: 0 javascript: directory: 'languages' translation: diff --git a/core/modules/locale/config/schema/locale.schema.yml b/core/modules/locale/config/schema/locale.schema.yml index 029a179..a5e1a85 100644 --- a/core/modules/locale/config/schema/locale.schema.yml +++ b/core/modules/locale/config/schema/locale.schema.yml @@ -7,6 +7,9 @@ locale.settings: cache_strings: type: boolean label: 'Cache strings' + translate_english: + type: boolean + label: 'Enable English translation' javascript: type: mapping label: 'JavaScript settings' diff --git a/core/modules/locale/lib/Drupal/locale/LocaleTranslation.php b/core/modules/locale/lib/Drupal/locale/LocaleTranslation.php index ac2b630..b0983de 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleTranslation.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleTranslation.php @@ -8,6 +8,7 @@ namespace Drupal\locale; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Config\ConfigFactory; use Drupal\Core\DestructableInterface; use Drupal\Core\Language\Language; use Drupal\Core\Lock\LockBackendAbstract; @@ -32,6 +33,13 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface { protected $storage; /** + * The configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** * Cached translations * * @var array @@ -63,11 +71,14 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface { * The cache backend. * @param \Drupal\Core\Lock\LockBackendInterface $lock * The lock backend. + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The config factory. */ - public function __construct(StringStorageInterface $storage, CacheBackendInterface $cache, LockBackendInterface $lock) { + public function __construct(StringStorageInterface $storage, CacheBackendInterface $cache, LockBackendInterface $lock, ConfigFactory $config_factory) { $this->storage = $storage; $this->cache = $cache; $this->lock = $lock; + $this->configFactory = $config_factory; } /** @@ -75,7 +86,8 @@ public function __construct(StringStorageInterface $storage, CacheBackendInterfa */ public function getStringTranslation($langcode, $string, $context) { // If the language is not suitable for locale module, just return. - if ($langcode == Language::LANGCODE_SYSTEM || ($langcode == 'en' && !variable_get('locale_translate_english', FALSE))) { + $translate_english = $this->configFactory->get('locale.settings')->get('translate_english'); + if ($langcode == Language::LANGCODE_SYSTEM || ($langcode == 'en' && !$translate_english)) { return FALSE; } // Strings are cached by langcode, context and roles, using instances of the diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 1e605fe..ded8a09 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -818,7 +818,7 @@ function locale_form_language_admin_edit_form_alter(&$form, &$form_state) { * Form submission handler for language_admin_edit_form(). */ function locale_form_language_admin_edit_form_alter_submit($form, $form_state) { - variable_set('locale_translate_english', $form_state['values']['locale_translate_english']); + Drupal::config('locale.settings')->set('translate_english', intval($form_state['values']['locale_translate_english']))->save(); } /** @@ -828,7 +828,7 @@ function locale_form_language_admin_edit_form_alter_submit($form, $form_state) { * Returns TRUE if content should be translated to English, FALSE otherwise. */ function locale_translate_english() { - return variable_get('locale_translate_english', FALSE); + return Drupal::config('locale.settings')->get('translate_english'); } /** diff --git a/core/modules/locale/locale.services.yml b/core/modules/locale/locale.services.yml index f632704..776cb3b 100644 --- a/core/modules/locale/locale.services.yml +++ b/core/modules/locale/locale.services.yml @@ -12,7 +12,7 @@ services: arguments: ['@database'] string_translator.locale.lookup: class: Drupal\locale\LocaleTranslation - arguments: ['@locale.storage', '@cache.cache', '@lock'] + arguments: ['@locale.storage', '@cache.cache', '@lock', '@config.factory'] tags: - { name: string_translator } - { name: needs_destruction } diff --git a/core/modules/locale/tests/Drupal/locale/Tests/LocaleTranslationTest.php b/core/modules/locale/tests/Drupal/locale/Tests/LocaleTranslationTest.php index f66024e..602ccdd 100644 --- a/core/modules/locale/tests/Drupal/locale/Tests/LocaleTranslationTest.php +++ b/core/modules/locale/tests/Drupal/locale/Tests/LocaleTranslationTest.php @@ -46,7 +46,7 @@ protected function setUp() { * Tests for \Drupal\locale\LocaleTranslation::destruct() */ public function testDestruct() { - $translation = new LocaleTranslation($this->storage, $this->cache, $this->lock); + $translation = new LocaleTranslation($this->storage, $this->cache, $this->lock, $this->getConfigFactoryStub(array())); // Prove that destruction works without errors when translations are empty. $this->assertAttributeEmpty('translations', $translation); $translation->destruct();