diff --git a/core/modules/locale/locale.services.yml b/core/modules/locale/locale.services.yml index 95683b3..4135d82 100644 --- a/core/modules/locale/locale.services.yml +++ b/core/modules/locale/locale.services.yml @@ -22,6 +22,6 @@ services: - { name: stream_wrapper, scheme: translations } locale.config_subscriber: class: Drupal\locale\LocaleConfigSubscriber - arguments: ['@locale.storage', '@config.factory', '@locale.config.typed', '@language_manager'] + arguments: ['@config.factory', '@locale.config.typed', '@language_manager'] tags: - { name: event_subscriber } diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index 1fa9e2f..5aa2866 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -402,6 +402,37 @@ public function translateString($name, $langcode, $source, $context) { } /** + * Get the translation object for the given source/context and language. + * + * @param string $name + * Name of the configuration location. + * @param string $langcode + * Language code to translate to. + * @param string $source + * The source string, should be English. + * @param string $context + * The string context. + * + * @return \Drupal\locale\TranslationString|FALSE + * The translation object if the string was not empty or FALSE otherwise. + */ + public function getStringTranslation($name, $langcode, $source, $context) { + if ($source) { + $this->translateString($name, $langcode, $source, $context); + if ($string = $this->translations[$name][$langcode][$context][$source]) { + if (!$string->isTranslation()) { + $conditions = array('lid' => $string->lid, 'language' => $langcode); + return $this->localeStorage->createTranslation($conditions); + } + else { + return $string; + } + } + } + return FALSE; + } + + /** * Checks whether a language has configuration translation. * * @param string $name diff --git a/core/modules/locale/src/LocaleConfigSubscriber.php b/core/modules/locale/src/LocaleConfigSubscriber.php index 2c32cda..bd29133 100644 --- a/core/modules/locale/src/LocaleConfigSubscriber.php +++ b/core/modules/locale/src/LocaleConfigSubscriber.php @@ -40,13 +40,6 @@ class LocaleConfigSubscriber implements EventSubscriberInterface { /** - * The string storage for reading and writing translations. - * - * @var \Drupal\locale\StringStorageInterface; - */ - protected $localeStorage; - - /** * The configuration factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface @@ -70,15 +63,14 @@ class LocaleConfigSubscriber implements EventSubscriberInterface { /** * Constructs a LocaleConfigSubscriber. * - * @param \Drupal\locale\StringStorageInterface $string_storage - * The string storage. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The configuration factory. * @param \Drupal\locale\LocaleConfigManager $locale_config_manager * The typed configuration manager. + * @param Drupal\Core\Language\LanguageManagerInterface + * The language manager. */ - public function __construct(StringStorageInterface $string_storage, ConfigFactoryInterface $config_factory, LocaleConfigManager $locale_config_manager, LanguageManagerInterface $language_manager) { - $this->localeStorage = $string_storage; + public function __construct(ConfigFactoryInterface $config_factory, LocaleConfigManager $locale_config_manager, LanguageManagerInterface $language_manager) { $this->configFactory = $config_factory; $this->localeConfigManager = $locale_config_manager; $this->languageManager = $language_manager; @@ -186,12 +178,12 @@ protected function saveCustomizedTranslation($name, $source, $context, $translat // If the source is still the same as the translation, keep it as-is, to let // locale to later update translations. if ($source != $translation) { - $locale_translation = $this->localeConfigManager->translateString($name, $langcode, $source, $context); + $locale_translation = $this->localeConfigManager->getStringTranslation($name, $langcode, $source, $context); // If the translation is the same as we already have in locale, keep it // as-is, ie. don't set customized. - if ($translation != $locale_translation) { - $string = $this->localeStorage->findTranslation(array('source' => $source, 'context' => $context, 'language' => $langcode)); - $string + debug($locale_translation); + if (!empty($locale_translation) && ($locale_translation->isNew() || $translation != $locale_translation->getString())) { + $locale_translation ->setString($translation) ->setCustomized(TRUE) ->save();