protected function LocaleConfigManager::getTranslatableData in Drupal 10
Same name and namespace in other branches
- 8 core/modules/locale/src/LocaleConfigManager.php \Drupal\locale\LocaleConfigManager::getTranslatableData()
 - 9 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.
File
- core/
modules/ locale/ src/ LocaleConfigManager.php, line 163  
Class
- LocaleConfigManager
 - Manages configuration supported in part by interface translation.
 
Namespace
Drupal\localeCode
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;
}