diff --git a/core/modules/locale/config/locale.settings.yml b/core/modules/locale/config/locale.settings.yml index 11c964ac289..740961bfe82 100644 --- a/core/modules/locale/config/locale.settings.yml +++ b/core/modules/locale/config/locale.settings.yml @@ -1,4 +1,5 @@ cache_strings: true +translate_english: false 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 029a179cf2a..a5e1a853cc4 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 ac2b6303924..b0983deb603 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; @@ -31,6 +32,13 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface { */ protected $storage; + /** + * The configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + /** * Cached translations * @@ -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 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface { */ 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 5817e1b7164..ae37daf800a 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 f63270474fe..776cb3bb501 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 f66024ec488..e82d0e01bad 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 @@ class LocaleTranslationTest extends UnitTestCase { * 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()); // Prove that destruction works without errors when translations are empty. $this->assertAttributeEmpty('translations', $translation); $translation->destruct(); diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 9c366032eec..2917318d11b 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -79,12 +79,12 @@ abstract class UnitTestCase extends \PHPUnit_Framework_TestCase { * @param array $configs * An associative array of configuration settings whose keys are configuration * object names and whose values are key => value arrays for the configuration - * object in question. + * object in question. Defaults to an empty array. * * @return \PHPUnit_Framework_MockObject_MockBuilder * A MockBuilder object for the ConfigFactory with the desired return values. */ - public function getConfigFactoryStub($configs) { + public function getConfigFactoryStub(array $configs = array()) { $config_map = array(); // Construct the desired configuration object stubs, each with its own // desired return map.