function LocaleConfigManager::processTranslatableData

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

Process the translatable data array with a given language.

If the given language is translatable, will return the translated copy which will only contain strings that had translations. If the given language is English and is not translatable, will return a simplified array of the English source strings only.

Parameters

string $name: The configuration name.

array $active: The active configuration data.

array|\Drupal\Core\StringTranslation\TranslatableMarkup[] $translatable: The translatable array structure. A nested array matching the exact structure under of the default configuration for $name with only the elements that are translatable wrapped into a TranslatableMarkup.

string $langcode: The language code to process the array with.

Return value

array Processed translatable data array. Will only contain translations different from source strings or in case of untranslatable English, the source strings themselves.

See also

self::getTranslatableData()

1 call to LocaleConfigManager::processTranslatableData()
LocaleConfigManager::updateConfigTranslations in core/modules/locale/src/LocaleConfigManager.php
Updates all configuration translations for the names / languages provided.

File

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

Class

LocaleConfigManager
Manages configuration supported in part by interface translation.

Namespace

Drupal\locale

Code

protected function processTranslatableData($name, array $active, array $translatable, $langcode) {
    $translated = [];
    foreach ($translatable as $key => $item) {
        if (!isset($active[$key])) {
            continue;
        }
        if (is_array($item)) {
            // Only add this key if there was a translated value underneath.
            $value = $this->processTranslatableData($name, $active[$key], $item, $langcode);
            if (!empty($value)) {
                $translated[$key] = $value;
            }
        }
        else {
            if (locale_is_translatable($langcode)) {
                $value = $this->translateString($name, $langcode, $item->getUntranslatedString(), $item->getOption('context'));
            }
            else {
                $value = $item->getUntranslatedString();
            }
            if (!empty($value)) {
                $translated[$key] = $value;
            }
        }
    }
    return $translated;
}

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