You are here

protected function CurrencyImporter::importEntityTranslations in Commerce Core 8.2

Imports translations for the given currency entity.

Parameters

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

array $langcodes: The langcodes.

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

File

modules/price/src/CurrencyImporter.php, line 138

Class

CurrencyImporter
Default implementation of the currency importer.

Namespace

Drupal\commerce_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 (UnknownCurrencyException $e) {

      // The currency is custom and doesn't exist in the library.
      return;
    } 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();
    }
  }
}