diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index 920ef54..647df06 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -166,6 +166,8 @@ protected function getTranslatableData(TypedDataInterface $element) { * * @param string $name * The configuration name. + * @param array $active + * The active configuration data. * @param array $translatable * The translatable array structure, see this::getTranslatableData(). * @param string $langcode @@ -176,10 +178,13 @@ protected function getTranslatableData(TypedDataInterface $element) { * different from source strings or in case of untranslatable English, the * source strings themselves. */ - protected function processTranslatableData($name, array $translatable, $langcode) { + protected function processTranslatableData($name, array $active, array $translatable, $langcode) { $translated = array(); foreach ($translatable as $key => $item) { - if (is_array($item) && $value = $this->processTranslatableData($name, $item, $langcode)) { + if (!isset($active[$key])) { + continue; + } + if (is_array($item) && $value = $this->processTranslatableData($name, $active[$key], $item, $langcode)) { $translated[$key] = $value; } else { @@ -196,36 +201,6 @@ protected function processTranslatableData($name, array $translatable, $langcode } /** - * Compares default configuration with updated data. - * - * @param array $default - * Default configuration data. - * @param array|false $updated - * Current configuration data, or FALSE if no configuration data existed. - * - * @return array - * The elements of default configuration that haven't changed. - */ - protected function compareConfigData(array $default, $updated) { - // Speed up comparison, specially for install operations. - if ($default === $updated) { - return $default; - } - $result = array(); - foreach ($default as $key => $value) { - if (isset($updated[$key])) { - if (is_array($value)) { - $result[$key] = $this->compareConfigData($value, $updated[$key]); - } - elseif ($value === $updated[$key]) { - $result[$key] = $value; - } - } - } - return $result; - } - - /** * Saves translated configuration override. * * @param string $name @@ -437,12 +412,16 @@ public function hasTranslation($name, $langcode) { * * @param $name * The configuration name. - * @return string - * Language code of the original shipped configuration. + * + * @return null|string + * Language code of the original shipped configuration. NULL if no such + * default configuration. */ public function defaultConfigLangcode($name) { $shipped = $this->installStorageRead($name); - return $shipped['langcode'] ?: 'en'; + if (!empty($shipped)) { + return $shipped['langcode'] ?: 'en'; + } } /** @@ -450,12 +429,16 @@ public function defaultConfigLangcode($name) { * * @param $name * The configuration name. - * @return string - * Language code of the current active configuration. + * + * @return null|string + * Language code of the current active configuration. NULL if no such active + * configuration. */ public function activeConfigLangcode($name) { $active = $this->configStorage->read($name); - return $active['langcode'] ?: 'en'; + if (!empty($active)) { + return $active['langcode'] ?: 'en'; + } } /** @@ -451,7 +451,7 @@ public function activeConfigLangcode($name) { * TRUE if interface translation is supported. */ public function isSupported($name) { - return $this->defaultConfigLangcode($name) == 'en'; + return $this->defaultConfigLangcode($name) == 'en' && !is_null($this->activeConfigLangcode($name)); } /** @@ -463,6 +446,7 @@ public function activeConfigLangcode($name) { * * @param $name * The configuration name. + * * @return bool * TRUE if interface translation is supported. */ @@ -475,11 +459,15 @@ public function isSupported($name) { * * @param $name * The configuration name. + * * @return bool - * TRUE if interface translation is supported. + * TRUE if the configuration both exists as default and active configuration + * and their language codes don't match. */ public function isTranslatedConfig($name) { - return $this->defaultConfigLangcode($name) != $this->activeConfigLangcode($name); + $default_langcode = $this->defaultConfigLangcode($name); + $active_langcode = $this->activeConfigLangcode($name); + return !is_null($default_langcode) && !is_null($active_langcode) && $default_langcode != $active_langcode; } /** @@ -511,14 +499,20 @@ public function updateConfigTranslations(array $names, array $langcodes = array( $langcodes = $langcodes ? $langcodes : array_keys($this->languageManager->getLanguages()); $count = 0; foreach ($names as $name) { + // Only deal with configuration which was shipped. if (!$this->isSupported($name)) { continue; } $translatable = $this->getTranslatableDefaultConfig($name); + $active_langcode = $this->activeConfigLangcode($name); + $active = $this->configStorage->read($name); + foreach ($langcodes as $langcode) { - $processed = $this->processTranslatableData($name, $translatable, $langcode); - if ($langcode != 'en' || !$this->isTranslatedConfig($name)) { + $processed = $this->processTranslatableData($name, $active, $translatable, $langcode); + if ($langcode != $active_langcode) { + // If the language code is not the same as the active storage + // language, we should update a configuration override. if ($processed) { // Update translation data in configuration override. $this->saveTranslationOverride($name, $langcode, $processed); @@ -530,7 +524,9 @@ public function updateConfigTranslations(array $names, array $langcodes = array( } } elseif ($langcode != 'en' || locale_translate_english()) { - $active = $this->configStorage->read($name); + // If the language code is the active storage language, we should + // update. If it is English, we should only update if English is also + // translatable. $active = $this->mergeToActiveConfig($active, $processed); $this->saveTranslationActive($name, $active); }