diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php b/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php index 0fb1673..c69b705 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php @@ -74,11 +74,12 @@ public function getString() { * * @param $name * Option name. + * * @return mixed - * The value of this option. + * The value of this option or empty string of option is not set. */ public function getOption($name) { - return $this->options[$name]; + return isset($this->options[$name]) ? $this->options[$name] : ''; } /** diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 9943889..ef70fab 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -366,15 +366,18 @@ function locale_cron() { * translations for, indexed by type. */ function locale_system_set_config_langcodes(array $components) { + // Need to rewrite some default configuration language codes if the default + // site language is not English. $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); if ($default_langcode != 'en') { - $components += array('module' => array(), 'theme' => array()); - $list = array_merge($components['module'], $components['theme']); - // If just installed the locale module, we need to update all prior - // shipped configuration to the foreign site language. Otherwise just update - // the shipped configuration just imported. - $names = Locale::config()->getComponentNames(in_array('locale', $list) ? array() : $list); + // shipped configuration to the foreign site language. Otherwise keep the + // components list received to just update the shipped configuration just + // imported. + if (isset($components['module']) && in_array('locale', $components['module'])) { + $components = array(); + } + $names = Locale::config()->getComponentNames($components); foreach ($names as $name) { $config = \Drupal::configFactory()->getEditable($name); diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index c9ec321..1d1762f 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -184,16 +184,23 @@ protected function processTranslatableData($name, array $active, array $translat if (!isset($active[$key])) { continue; } - if (is_array($item) && $value = $this->processTranslatableData($name, $active[$key], $item, $langcode)) { - $translated[$key] = $value; + if (is_array($item)) { + // Only add this key if there was a translated value underneath. + $value = $this->processTranslatableData($name, $active[$key], $item, $langcode); + if (!empty($value)) { + $translated[$key] = $value; + } } else { /** @var \Drupal\Core\StringTranslation\TranslationWrapper $item */ if ($langcode != 'en' || locale_translate_english()) { - return $this->translateString($name, $langcode, $item->getString(), $item->getOption('context')); + $value = $this->translateString($name, $langcode, $item->getString(), $item->getOption('context')); } else { - return $item->getString(); + $value = $item->getString(); + } + if (!empty($value)) { + $translated[$key] = $value; } } } @@ -420,7 +427,7 @@ public function hasTranslation($name, $langcode) { public function defaultConfigLangcode($name) { $shipped = $this->installStorageRead($name); if (!empty($shipped)) { - return $shipped['langcode'] ?: 'en'; + return !empty($shipped['langcode']) ? $shipped['langcode'] : 'en'; } } @@ -437,7 +444,7 @@ public function defaultConfigLangcode($name) { public function activeConfigLangcode($name) { $active = $this->configStorage->read($name); if (!empty($active)) { - return $active['langcode'] ?: 'en'; + return !empty($active['langcode']) ? $active['langcode'] : 'en'; } } @@ -510,6 +517,9 @@ public function updateConfigTranslations(array $names, array $langcodes = array( foreach ($langcodes as $langcode) { $processed = $this->processTranslatableData($name, $active, $translatable, $langcode); + if (empty($processed)) { + continue; + } if ($langcode != $active_langcode) { // If the language code is not the same as the active storage // language, we should update a configuration override. diff --git a/core/modules/locale/src/LocaleConfigSubscriber.php b/core/modules/locale/src/LocaleConfigSubscriber.php index 711eaf2..d76db9d 100644 --- a/core/modules/locale/src/LocaleConfigSubscriber.php +++ b/core/modules/locale/src/LocaleConfigSubscriber.php @@ -134,6 +134,7 @@ public function onOverrideDelete(LanguageConfigOverrideCrudEvent $event) { * A callable to apply to each translatable string of the configuration. */ protected function updateTranslationStrings(LanguageConfigOverrideCrudEvent $event, $callable) { + return; $translation_config = $event->getLanguageConfigOverride(); $name = $translation_config->getName();