You are here

protected function CurrencyImporter::importEntityTranslations in Price 8

Same name and namespace in other branches
  1. 3.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::importEntityTranslations()
  2. 2.0.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::importEntityTranslations()
  3. 2.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::importEntityTranslations()
  4. 3.0.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::importEntityTranslations()

Imports translations for the given currency entity.

Parameters

\Drupal\price\Entity\CurrencyInterface $currency: The currency entity.

array $langcodes: The langcodes.

2 calls to CurrencyImporter::importEntityTranslations()
CurrencyImporter::import in src/CurrencyImporter.php
Imports currency data for the given currency code.
CurrencyImporter::importTranslations in src/CurrencyImporter.php
Imports translations for the given language codes.

File

src/CurrencyImporter.php, line 137

Class

CurrencyImporter
Default implementation of the currency importer.

Namespace

Drupal\price

Code

protected function importEntityTranslations(CurrencyInterface $currency, array $langcodes) {
  $currency_code = $currency
    ->getCurrencyCode();
  $config_name = $currency
    ->getConfigDependencyName();
  foreach ($langcodes as $langcode) {
    try {
      $translated_currency = $this->externalRepository
        ->get($currency_code, $langcode);
    } catch (UnknownLocaleException $e) {

      // No translation found.
      continue;
    }

    /** @var \Drupal\language\Config\LanguageConfigOverride $config_translation */
    $config_translation = $this->languageManager
      ->getLanguageConfigOverride($langcode, $config_name);
    if ($config_translation
      ->isNew()) {
      $config_translation
        ->set('name', $translated_currency
        ->getName());
      $config_translation
        ->set('symbol', $translated_currency
        ->getSymbol());
      $config_translation
        ->save();
    }
  }
}