You are here

protected function CurrencyImporter::importEntityTranslations in Price 2.0.x

Same name and namespace in other branches
  1. 8 src/CurrencyImporter.php \Drupal\price\CurrencyImporter::importEntityTranslations()
  2. 3.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 138

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 (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();
    }
  }
}