You are here

protected function LocaleConfigSubscriber::resetExistingTranslations in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/locale/src/LocaleConfigSubscriber.php \Drupal\locale\LocaleConfigSubscriber::resetExistingTranslations()

Reset existing locale translations to their source values.

Goes through $translatable to reset any existing translations to the source string, so prior translations would not reappear in the configuration.

Parameters

string $name: The configuration name.

array|\Drupal\Core\StringTranslation\TranslatableMarkup $translatable: Either a possibly nested array with TranslatableMarkup objects at the leaf items or a TranslatableMarkup object directly.

array|string $reference_config: Either a possibly nested array with strings at the leaf items or a string directly. Only those $translatable items that are also present in $reference_config will get translations reset.

string $langcode: The language code of the translation being processed.

1 call to LocaleConfigSubscriber::resetExistingTranslations()
LocaleConfigSubscriber::processTranslatableData in core/modules/locale/src/LocaleConfigSubscriber.php
Process the translatable data array with a given language.

File

core/modules/locale/src/LocaleConfigSubscriber.php, line 179

Class

LocaleConfigSubscriber
Updates strings translation when configuration translations change.

Namespace

Drupal\locale

Code

protected function resetExistingTranslations($name, $translatable, $reference_config, $langcode) {
  if (is_array($translatable)) {
    foreach ($translatable as $key => $item) {
      if (isset($reference_config[$key])) {

        // Process further if the key still exists in the reference active
        // configuration and the default translation but not the current
        // configuration override.
        $this
          ->resetExistingTranslations($name, $item, $reference_config[$key], $langcode);
      }
    }
  }
  elseif (!is_array($reference_config)) {
    $this
      ->saveCustomizedTranslation($name, $translatable
      ->getUntranslatedString(), $translatable
      ->getOption('context'), $reference_config, $langcode);
  }
}