function LocaleConfigManager::getTranslatableData

Same name and namespace in other branches
  1. 8.9.x core/modules/locale/src/LocaleConfigManager.php \Drupal\locale\LocaleConfigManager::getTranslatableData()
  2. 10 core/modules/locale/src/LocaleConfigManager.php \Drupal\locale\LocaleConfigManager::getTranslatableData()
  3. 11.x core/modules/locale/src/LocaleConfigManager.php \Drupal\locale\LocaleConfigManager::getTranslatableData()

Gets translatable configuration data for a typed configuration element.

Parameters

\Drupal\Core\TypedData\TypedDataInterface $element: Typed configuration element.

Return value

array|\Drupal\Core\StringTranslation\TranslatableMarkup A nested array matching the exact structure under $element with only the elements that are translatable wrapped into a TranslatableMarkup. If the provided $element is not traversable, the return value is a single TranslatableMarkup.

1 call to LocaleConfigManager::getTranslatableData()
LocaleConfigManager::getTranslatableDefaultConfig in core/modules/locale/src/LocaleConfigManager.php
Gets array of translated strings for Locale translatable configuration.

File

core/modules/locale/src/LocaleConfigManager.php, line 163

Class

LocaleConfigManager
Manages configuration supported in part by interface translation.

Namespace

Drupal\locale

Code

protected function getTranslatableData(TypedDataInterface $element) {
    $translatable = [];
    if ($element instanceof TraversableTypedDataInterface) {
        foreach ($element as $key => $property) {
            $value = $this->getTranslatableData($property);
            if (!empty($value)) {
                $translatable[$key] = $value;
            }
        }
    }
    else {
        // Something is only translatable by Locale if there is a string in the
        // first place.
        $value = $element->getValue();
        $definition = $element->getDataDefinition();
        if (!empty($definition['translatable']) && $value !== '' && $value !== NULL) {
            $options = [];
            if (isset($definition['translation context'])) {
                $options['context'] = $definition['translation context'];
            }
            return new TranslatableMarkup($value, [], $options);
        }
    }
    return $translatable;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.