diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index 5aa2866..a170603 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -402,6 +402,16 @@ public function translateString($name, $langcode, $source, $context) { } /** + * Reset static cache of configuration string translations. + * + * @return $this + */ + public function reset() { + $this->translations = array(); + return $this; + } + + /** * Get the translation object for the given source/context and language. * * @param string $name diff --git a/core/modules/locale/src/Tests/LocaleConfigSubscriberTest.php b/core/modules/locale/src/Tests/LocaleConfigSubscriberTest.php index 4ed11cd..c5063bd 100644 --- a/core/modules/locale/src/Tests/LocaleConfigSubscriberTest.php +++ b/core/modules/locale/src/Tests/LocaleConfigSubscriberTest.php @@ -94,7 +94,7 @@ public function testLocaleCreateTranslation() { $config_name = 'locale_test.no_translation'; $this->setUpNoTranslation($config_name, 'test', 'Test'); - $this->saveLocaleTranslationData($config_name, 'test', 'Test (German)'); + $this->saveLocaleTranslationData($config_name, 'test', 'Test', 'Test (German)'); $this->assertTranslation($config_name, 'Test (German)', FALSE); } @@ -116,7 +116,7 @@ public function testLocaleUpdateTranslation() { $config_name = 'locale_test.translation'; $this->setUpTranslation($config_name, 'test', 'English test', 'German test'); - $this->saveLocaleTranslationData($config_name, 'test', 'Updated German test'); + $this->saveLocaleTranslationData($config_name, 'test', 'English test', 'Updated German test'); $this->assertTranslation($config_name, 'Updated German test', FALSE); } @@ -142,7 +142,7 @@ public function testLocaleDeleteTranslation() { $this->setUpTranslation($config_name, 'test', 'English test', 'German test'); $this->deleteLocaleTranslationData($config_name, 'test', 'English test'); - $this->assertNoTranslation($config_name, 'English test', FALSE); + $this->assertNoTranslation($config_name); } /** @@ -192,23 +192,18 @@ protected function setUpNoTranslation($config_name, $key, $source) { protected function setUpTranslation($config_name, $key, $source, $translation) { // Create source and translation strings for the configuration value and add // the configuration name as a location. This would be performed by - // locale_translate_batch_import() and + // locale_translate_batch_import() invoking // LocaleConfigManager::updateConfigTranslations() normally. - $source_object = $this->stringStorage->createString([ - 'source' => $source, - 'context' => '', - ])->save(); - $this->stringStorage->createTranslation([ - 'lid' => $source_object->getId(), - 'language' => $this->langcode, - 'translation' => $translation, - ])->save(); - $this->localeConfigManager->translateString($config_name, $this->langcode, $source, ''); + $this->localeConfigManager->reset(); + $this->localeConfigManager + ->getStringTranslation($config_name, $this->langcode, $source, '') + ->setString($translation) + ->save(); $this->languageManager ->setConfigOverrideLanguage(ConfigurableLanguage::load($this->langcode)); $this->assertConfigValue($config_name, $key, $translation); - $this->assertTranslation($config_name, $translation, FALSE); + $this->assertTranslation($config_name, $translation, TRUE); } /** @@ -254,12 +249,16 @@ protected function saveLanguageOverride($config_name, $key, $value) { * @param string $value * The configuration value to save. */ - protected function saveLocaleTranslationData($config_name, $key, $value) { + protected function saveLocaleTranslationData($config_name, $key, $source, $translation) { $this->localeConfigManager - ->saveTranslationOverride($config_name, $this->langcode, [$key => $value]); + ->getStringTranslation($config_name, $this->langcode, $source, '') + ->setString($translation) + ->save(); + $this->localeConfigManager + ->saveTranslationOverride($config_name, $this->langcode, [$key => $translation]); $this->configFactory->reset($config_name); - $this->assertConfigValue($config_name, $key, $value); + $this->assertConfigValue($config_name, $key, $translation); } /** @@ -308,6 +307,9 @@ protected function deleteLanguageOverride($config_name, $key, $source_value) { * from the configuration factory after the deletion. */ protected function deleteLocaleTranslationData($config_name, $key, $source_value) { + $this->localeConfigManager + ->getStringTranslation($config_name, $this->langcode, $source_value, '') + ->delete(); $this->localeConfigManager->deleteTranslationOverride($config_name, $this->langcode); $this->configFactory->reset($config_name);