You are here

protected function LocaleConfigManager::getTranslatableData in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 159
Contains \Drupal\locale\LocaleConfigManager.

Class

LocaleConfigManager
Manages configuration supported in part by interface translation.

Namespace

Drupal\locale

Code

protected function getTranslatableData(TypedDataInterface $element) {
  $translatable = array();
  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 = array();
      if (isset($definition['translation context'])) {
        $options['context'] = $definition['translation context'];
      }
      return new TranslatableMarkup($value, array(), $options);
    }
  }
  return $translatable;
}