diff --git a/core/core.services.yml b/core/core.services.yml index 7b326eb..c3180cb 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -172,6 +172,7 @@ services: class: Drupal\Core\Language\LanguageManager string_translator.custom_strings: class: Drupal\Core\StringTranslation\Translator\CustomStrings + arguments: ['@settings'] tags: - { name: string_translator, priority: 30 } string_translation: diff --git a/core/lib/Drupal/Core/StringTranslation/Translator/CustomStrings.php b/core/lib/Drupal/Core/StringTranslation/Translator/CustomStrings.php index a1ed337..3debb1f 100644 --- a/core/lib/Drupal/Core/StringTranslation/Translator/CustomStrings.php +++ b/core/lib/Drupal/Core/StringTranslation/Translator/CustomStrings.php @@ -7,6 +7,8 @@ namespace Drupal\Core\StringTranslation\Translator; +use Drupal\Component\Utility\Settings; + /** * String translator using overrides from variables. * @@ -16,10 +18,28 @@ class CustomStrings extends StaticTranslation { /** + * The settings read only object. + * + * @var \Drupal\Component\Utility\Settings + */ + protected $settings; + + /** + * Constructs a CustomStrings object. + * + * @param \Drupal\Component\Utility\Settings $settings + * The settings read only object. + */ + public function __construct(Settings $settings) { + parent::__construct(); + $this->settings = $settings; + } + + /** * {@inheritdoc} */ protected function loadLanguage($langcode) { - return variable_get('locale_custom_strings_' . $langcode, array()); + return $this->settings->get('locale_custom_strings_' . $langcode, array()); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php index 118a059..cc3d4e8 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php @@ -45,13 +45,12 @@ function setUp() { ->set('formats.medium.pattern.php', 'j. F Y - G:i') ->set('formats.short.pattern.php', 'Y M j - g:ia') ->save(); + $this->refreshVariables(); - variable_set('locale_custom_strings_' . self::LANGCODE, array( + $this->settingsSet('locale_custom_strings_' . self::LANGCODE, array( '' => array('Sunday' => 'domingo'), 'Long month name' => array('March' => 'marzo'), )); - - $this->refreshVariables(); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php index eddcce0..d92845f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php @@ -7,13 +7,12 @@ namespace Drupal\system\Tests\Menu; -use PDO; -use Drupal\simpletest\WebTestBase; +use Drupal\system\Tests\System\CustomStringsTestBase; /** * Tests menu router and hook_menu() functionality. */ -class MenuRouterTest extends WebTestBase { +class MenuRouterTest extends CustomStringsTestBase { /** * Modules to enable. @@ -539,9 +538,12 @@ function testMenuItemTitlesCases() { foreach ($test_data as $case_no => $override) { $this->menuItemTitlesCasesHelper($case_no); - variable_set('locale_custom_strings_en', array('' => $override)); + $this->addCustomTranslations('en', array('' => $override)); + $this->writeCustomTranslations(); + $this->menuItemTitlesCasesHelper($case_no, TRUE); - variable_set('locale_custom_strings_en', array()); + $this->addCustomTranslations('en', array()); + $this->writeCustomTranslations(); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php index 23d01fa..57cf70b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/CacheDecoratorLanguageTest.php @@ -9,12 +9,12 @@ use Drupal\Core\Language\Language; use Drupal\plugin_test\Plugin\CachedMockBlockManager; -use Drupal\simpletest\WebTestBase; +use Drupal\system\Tests\System\CustomStringsTestBase; /** * Tests that the AlterDecorator fires and respects the alter hook. */ -class CacheDecoratorLanguageTest extends WebTestBase { +class CacheDecoratorLanguageTest extends CustomStringsTestBase { /** * Modules to enable. @@ -68,8 +68,10 @@ public function setUp() { foreach ($this->mockBlockExpectedDefinitions as $plugin_id => $definition) { $custom_strings[$definition['label']] = $langcode . ' ' . $definition['label']; } - variable_set('locale_custom_strings_' . $langcode, array('' => $custom_strings)); + $this->addCustomTranslations($langcode, array('' => $custom_strings)); } + // Write test settings.php with new translations. + $this->writeCustomTranslations(); } /** @@ -111,7 +113,8 @@ public function testCacheDecoratorLanguage() { foreach ($this->mockBlockExpectedDefinitions as $plugin_id => $definition) { $custom_strings[$definition['label']] = $definition['label'] . ' de'; } - variable_set('locale_custom_strings_de', array('' => $custom_strings)); + $this->addCustomTranslations('de', array('' => $custom_strings)); + $this->writeCustomTranslations(); $this->drupalGet('de/plugin_definition_test'); foreach ($this->mockBlockExpectedDefinitions as $plugin_id => $definition) { // Find our provided translations. diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index ab85646..9a882f8 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -460,6 +460,23 @@ # $settings['session_write_interval'] = 180; /** + * String overrides: + * + * To override specific strings on your site with or without enabling the Locale + * module, add an entry to this list. This functionality allows you to change + * a small number of your site's default English language interface strings. + * + * Remove the leading hash signs to enable. + * + * The "en" part of the variable name, is dynamic and can be any langcode of + * any enabled language. (eg locale_custom_strings_de for german). + */ +# $settings['locale_custom_strings_en'][''] = array( +# 'forum' => 'Discussion board', +# '@count min' => '@count minutes', +# ); + +/** * Base URL (optional). * * If Drupal is generating incorrect URLs on your site, which could @@ -586,20 +603,6 @@ # $conf['system.performance']['js']['gzip'] = FALSE; /** - * String overrides: - * - * To override specific strings on your site with or without enabling the Locale - * module, add an entry to this list. This functionality allows you to change - * a small number of your site's default English language interface strings. - * - * Remove the leading hash signs to enable. - */ -# $conf['locale_custom_strings_en'][''] = array( -# 'forum' => 'Discussion board', -# '@count min' => '@count minutes', -# ); - -/** * Fast 404 pages: * * Drupal can generate fully themed 404 pages. However, some of these responses