Exemplo n.º 1
0
  /**
   * Imports translations for the given currency entity.
   *
   * @param \Drupal\commerce_price\Entity\CurrencyInterface $currency
   *   The currency entity.
   * @param array $langcodes
   *   The langcodes.
   */
  protected function importEntityTranslations(CurrencyInterface $currency, array $langcodes) {
    $currencyCode = $currency->getCurrencyCode();
    $configName = $currency->getConfigDependencyName();
    foreach ($langcodes as $langcode) {
      try {
        $translatedCurrency = $this->externalRepository->get($currencyCode, $langcode);
      }
      catch (UnknownLocaleException $e) {
        // No translation found.
        continue;
      }

      $configTranslation = $this->languageManager->getLanguageConfigOverride($langcode, $configName);
      if ($configTranslation->isNew()) {
        $configTranslation->set('name', $translatedCurrency->getName());
        $configTranslation->set('symbol', $translatedCurrency->getSymbol());
        $configTranslation->save();
      }
    }
  }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultCurrency(CurrencyInterface $currency)
 {
     $this->set('default_currency', $currency->getCurrencyCode());
     return $this;
 }