diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php index 87cace7..49b0640 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php @@ -120,7 +120,7 @@ protected function compareConfigData(array $default, $updated) { * Configuration data to be saved, that will be only the translated values. */ public function saveTranslationData($name, $langcode, array $data) { - $locale_name = 'locale.config.' . $langcode . '.' . $name; + $locale_name = self::localeConfigName($langcode, $name); $this->configStorage->write($locale_name, $data); } @@ -133,7 +133,7 @@ public function saveTranslationData($name, $langcode, array $data) { * Language code. */ public function deleteTranslationData($name, $langcode) { - $locale_name = 'locale.config.' . $langcode . '.' . $name; + $locale_name = self::localeConfigName($langcode, $name); $this->configStorage->delete($locale_name); } @@ -207,7 +207,7 @@ public function getStringNames(array $lids) { * Language code to delete. */ public function deleteLanguageTranslations($langcode) { - $locale_name = 'locale.config.' . $langcode; + $locale_name = self::localeConfigName($langcode); foreach ($this->configStorage->listAll($locale_name) as $name) { $this->configStorage->delete($name); } @@ -272,11 +272,23 @@ public function translateString($name, $langcode, $source, $context) { $this->translations[$name][$langcode][$context][$source] = $translation; } - $translation = $this->translations[$name][$langcode][$context][$source]; // Return the string only when the string object had a translation. - return $translation->isTranslation() ? $translation->getString() : FALSE; + if ($this->translations[$name][$langcode][$context][$source]->isTranslation()) { + $this->translations[$name][$langcode][$context][$source]->getString(); + } } return FALSE; } + /** + * Provides configuration data location for given langcode and name. + * + * @param string $langcode + * @param null $name + * + * @return string + */ + public static function localeConfigName($langcode, $name = NULL) { + return rtrim('locale.config.' . $langcode . '.' . $name, '.'); + } } diff --git a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php index 1784bae..5a80718 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleTypedConfig.php @@ -65,7 +65,7 @@ public function getTypedConfig() { } /** - * Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages(). + * {@inheritdoc} */ public function getTranslationLanguages($include_default = TRUE) { $languages = locale_translatable_language_list(); @@ -80,7 +80,7 @@ public function getTranslationLanguages($include_default = TRUE) { } /** - * Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslation(). + * {@inheritdoc} */ public function getTranslation($langcode, $strict = TRUE) { $options = array( @@ -89,11 +89,11 @@ public function getTranslation($langcode, $strict = TRUE) { 'strict' => $strict, ); $data = $this->getElementTranslation($this->getTypedConfig(), $options); - return $this->localeConfig->create($this->definition, isset($data) ? $data : array()); + return $this->localeConfig->create($this->definition, is_array($data) ? $data : array()); } /** - * Implements \Drupal\Core\TypedData\TranslatableInterface::language(). + * {@inheritdoc} */ public function language() { return new Language(array('langcode' => $this->langcode)); @@ -127,18 +127,19 @@ protected function canTranslate($from_langcode, $to_langcode) { * Array with translation options that must contain the keys defined in * \Drupal\locale\LocaleTypedConfig::translateElement() * - * @return array - * Configuration data translated to the requested language. + * @return array|NULL + * Configuration data translated to the requested language if available, + * NULL otherwise. */ protected function getElementTranslation($element, array $options) { $translation = NULL; if ($element instanceof ArrayElement) { $translation = $this->getArrayTranslation($element, $options); } - elseif ($this->translateElement($element, $options) || empty($options['strict'])) { + elseif ($this->translateElement($element, $options)) { $translation = $element->getValue(); } - if ($translation || empty($options['strict'])) { + if (!empty($translation)) { return $translation; } else {