Issue #1998088 by ParisLiakos, alexpott, ebrowet, plopesc, dawehner, Gábor Hojtsy: Convert locale_translate_english variable to CMI.
parent
d50a62fc3d
commit
fd6f4ff917
|
@ -1,4 +1,5 @@
|
||||||
cache_strings: true
|
cache_strings: true
|
||||||
|
translate_english: false
|
||||||
javascript:
|
javascript:
|
||||||
directory: languages
|
directory: languages
|
||||||
translation:
|
translation:
|
||||||
|
|
|
@ -7,6 +7,9 @@ locale.settings:
|
||||||
cache_strings:
|
cache_strings:
|
||||||
type: boolean
|
type: boolean
|
||||||
label: 'Cache strings'
|
label: 'Cache strings'
|
||||||
|
translate_english:
|
||||||
|
type: boolean
|
||||||
|
label: 'Enable English translation'
|
||||||
javascript:
|
javascript:
|
||||||
type: mapping
|
type: mapping
|
||||||
label: 'JavaScript settings'
|
label: 'JavaScript settings'
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\locale;
|
namespace Drupal\locale;
|
||||||
|
|
||||||
use Drupal\Core\Cache\CacheBackendInterface;
|
use Drupal\Core\Cache\CacheBackendInterface;
|
||||||
|
use Drupal\Core\Config\ConfigFactory;
|
||||||
use Drupal\Core\DestructableInterface;
|
use Drupal\Core\DestructableInterface;
|
||||||
use Drupal\Core\Language\Language;
|
use Drupal\Core\Language\Language;
|
||||||
use Drupal\Core\Lock\LockBackendAbstract;
|
use Drupal\Core\Lock\LockBackendAbstract;
|
||||||
|
@ -31,6 +32,13 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface {
|
||||||
*/
|
*/
|
||||||
protected $storage;
|
protected $storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration factory.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Config\ConfigFactory
|
||||||
|
*/
|
||||||
|
protected $configFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached translations
|
* Cached translations
|
||||||
*
|
*
|
||||||
|
@ -63,11 +71,14 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface {
|
||||||
* The cache backend.
|
* The cache backend.
|
||||||
* @param \Drupal\Core\Lock\LockBackendInterface $lock
|
* @param \Drupal\Core\Lock\LockBackendInterface $lock
|
||||||
* The lock backend.
|
* 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->storage = $storage;
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
$this->lock = $lock;
|
$this->lock = $lock;
|
||||||
|
$this->configFactory = $config_factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +86,8 @@ class LocaleTranslation implements TranslatorInterface, DestructableInterface {
|
||||||
*/
|
*/
|
||||||
public function getStringTranslation($langcode, $string, $context) {
|
public function getStringTranslation($langcode, $string, $context) {
|
||||||
// If the language is not suitable for locale module, just return.
|
// 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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
// Strings are cached by langcode, context and roles, using instances of the
|
// Strings are cached by langcode, context and roles, using instances of the
|
||||||
|
|
|
@ -818,7 +818,7 @@ function locale_form_language_admin_edit_form_alter(&$form, &$form_state) {
|
||||||
* Form submission handler for language_admin_edit_form().
|
* Form submission handler for language_admin_edit_form().
|
||||||
*/
|
*/
|
||||||
function locale_form_language_admin_edit_form_alter_submit($form, $form_state) {
|
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.
|
* Returns TRUE if content should be translated to English, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
function locale_translate_english() {
|
function locale_translate_english() {
|
||||||
return variable_get('locale_translate_english', FALSE);
|
return \Drupal::config('locale.settings')->get('translate_english');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,7 +12,7 @@ services:
|
||||||
arguments: ['@database']
|
arguments: ['@database']
|
||||||
string_translator.locale.lookup:
|
string_translator.locale.lookup:
|
||||||
class: Drupal\locale\LocaleTranslation
|
class: Drupal\locale\LocaleTranslation
|
||||||
arguments: ['@locale.storage', '@cache.cache', '@lock']
|
arguments: ['@locale.storage', '@cache.cache', '@lock', '@config.factory']
|
||||||
tags:
|
tags:
|
||||||
- { name: string_translator }
|
- { name: string_translator }
|
||||||
- { name: needs_destruction }
|
- { name: needs_destruction }
|
||||||
|
|
|
@ -46,7 +46,7 @@ class LocaleTranslationTest extends UnitTestCase {
|
||||||
* Tests for \Drupal\locale\LocaleTranslation::destruct()
|
* Tests for \Drupal\locale\LocaleTranslation::destruct()
|
||||||
*/
|
*/
|
||||||
public function testDestruct() {
|
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.
|
// Prove that destruction works without errors when translations are empty.
|
||||||
$this->assertAttributeEmpty('translations', $translation);
|
$this->assertAttributeEmpty('translations', $translation);
|
||||||
$translation->destruct();
|
$translation->destruct();
|
||||||
|
|
|
@ -79,12 +79,12 @@ abstract class UnitTestCase extends \PHPUnit_Framework_TestCase {
|
||||||
* @param array $configs
|
* @param array $configs
|
||||||
* An associative array of configuration settings whose keys are configuration
|
* An associative array of configuration settings whose keys are configuration
|
||||||
* object names and whose values are key => value arrays for the 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
|
* @return \PHPUnit_Framework_MockObject_MockBuilder
|
||||||
* A MockBuilder object for the ConfigFactory with the desired return values.
|
* A MockBuilder object for the ConfigFactory with the desired return values.
|
||||||
*/
|
*/
|
||||||
public function getConfigFactoryStub($configs) {
|
public function getConfigFactoryStub(array $configs = array()) {
|
||||||
$config_map = array();
|
$config_map = array();
|
||||||
// Construct the desired configuration object stubs, each with its own
|
// Construct the desired configuration object stubs, each with its own
|
||||||
// desired return map.
|
// desired return map.
|
||||||
|
|
Loading…
Reference in New Issue