processTranslatableData example


  public function updateLocaleStorage(StorableConfigBase $config$langcode, array $reference_config = []) {
    $name = $config->getName();
    if ($this->localeConfigManager->isSupported($name) && locale_is_translatable($langcode)) {
      $translatables = $this->localeConfigManager->getTranslatableDefaultConfig($name);
      $this->processTranslatableData($name$config->get()$translatables$langcode$reference_config);
    }
  }

  /** * Process the translatable data array with a given language. * * @param string $name * The configuration name. * @param array $config * The active configuration data or override data. * @param array|\Drupal\Core\StringTranslation\TranslatableMarkup[] $translatable * The translatable array structure. * @see \Drupal\locale\LocaleConfigManager::getTranslatableData() * @param string $langcode * The language code to process the array with. * @param array $reference_config * (Optional) Reference configuration to check against if $config was an * override. This allows us to update locale keys for data not in the * override but still in the active configuration. */

  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();
        }
        
Home | Imprint | This part of the site doesn't use cookies.