diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php index 782d590..0161844 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php @@ -337,6 +337,7 @@ function testJSTranslation() { $this->enableModules(array('locale')); $this->installSchema('locale', 'locales_source'); $this->installSchema('locale', 'locales_location'); + $this->installConfig(array('locale')); $editor = entity_load('editor', 'filtered_html'); $this->ckeditor->getJSSettings($editor); $localeStorage = $this->container->get('locale.storage'); diff --git a/core/modules/locale/config/locale.settings.yml b/core/modules/locale/config/locale.settings.yml index 02e8af0..31458f2 100644 --- a/core/modules/locale/config/locale.settings.yml +++ b/core/modules/locale/config/locale.settings.yml @@ -1,4 +1,6 @@ cache_strings: '1' +disable_translation: + - 'en' 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..fce449f 100644 --- a/core/modules/locale/config/schema/locale.schema.yml +++ b/core/modules/locale/config/schema/locale.schema.yml @@ -7,6 +7,12 @@ locale.settings: cache_strings: type: boolean label: 'Cache strings' + disable_translation: + type: sequence + label: 'Disable translation' + sequence: + - type: string + label: 'Language' 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..a1c6f29 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))) { + $disable_translation = $this->configFactory->get('locale.settings')->get('disable_translation'); + if ($langcode == Language::LANGCODE_SYSTEM || ($langcode == 'en' && is_null($disable_translation)) || (is_array($disable_translation) && in_array($langcode, $disable_translation))) { return FALSE; } // Strings are cached by langcode, context and roles, using instances of the diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index 1e62cd4..65e24ab 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -971,6 +971,21 @@ function locale_update_8017() { } /** + * Moves locale translate english setting from variable to config. + * + * @ingroup config_upgrade + */ +function locale_update_8018() { + if (update_variable_get('locale_translate_english') == TRUE) { + $disable_translation = Drupal::config('locale.settings')->get('disable_translation'); + if(($key = array_search('en', $disable_translation)) !== false) { + unset($disable_translation[$key]); + } + Drupal::config('locale.settings')->set('disable_translation', $disable_translation)->save(); + } +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 72070f8..5d0f1f7 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -827,7 +827,18 @@ 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']); + $disable_translation = Drupal::config('locale.settings')->get('disable_translation'); + if ($form_state['values']['locale_translate_english']) { + if(($key = array_search('en', $disable_translation)) !== FALSE) { + unset($disable_translation[$key]); + } + } + else { + if(($key = array_search('en', $disable_translation)) == FALSE) { + $disable_translation[] = 'en'; + } + } + Drupal::config('locale.settings')->set('disable_translation', $disable_translation)->save(); } /** @@ -837,7 +848,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 !in_array('en', Drupal::config('locale.settings')->get('disable_translation')); } /** 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(); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 00ba41a..b665552 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -772,6 +772,7 @@ protected function setUp() { 'path.temporary' => $this->temp_files_directory, ), 'locale.settings' => array( + 'disable_translation' => array('en'), 'translation.path' => $this->translation_files_directory, ), ); diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 9c36603..2917318 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -79,12 +79,12 @@ protected function getRandomGenerator() { * @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.