/**
  * Return all languages with the master one promoted to the first position
  *
  * @return Collection Languages collection
  */
 public function getLanguagesWithMasterLanguagePromoted()
 {
     $languages = $this->languageManager->getLanguages()->toArray();
     $masterLocale = $this->masterLocale->getIso();
     $index = array_search($masterLocale, $languages);
     if (false !== $index) {
         $mainLanguage = $languages[$index];
         unset($languages[$index]);
         array_unshift($languages, $mainLanguage);
     }
     return new ArrayCollection($languages);
 }
Example #2
0
 /**
  * Returns the locale used to look for translations, which may not be the
  * same as $this->locale
  *
  * @return Locale Locale
  */
 public function getTranslationsLocale()
 {
     $localeIso = $this->locale->getIso();
     if (isset($this->localeTranslationAssociations[$localeIso])) {
         return Locale::create($this->localeTranslationAssociations[$localeIso]);
     }
     return $this->locale;
 }
Example #3
0
 /**
  * Move master language to the first position
  *
  * @param LanguageInterface[] $languages
  *
  * @return LanguageInterface[]
  */
 private function promoteMasterLanguage(array $languages)
 {
     $masterLocale = $this->masterLocale->getIso();
     $index = array_search($masterLocale, $languages);
     if (false !== $index) {
         unset($languages[$index]);
         array_unshift($languages, $masterLocale);
     }
     return $languages;
 }
Example #4
0
 /**
  * Return a formatted price given an Money object.
  *
  * If money is null, print empty string
  *
  * @param MoneyInterface $money the Money object to print
  *
  * @return string The formatted price
  */
 public function printMoney(MoneyInterface $money = null)
 {
     if (!$money instanceof MoneyInterface) {
         return '';
     }
     if (!$money->getCurrency() instanceof CurrencyInterface) {
         return $money->getAmount();
     }
     $moneyFormatter = new NumberFormatter($this->locale->getIso(), NumberFormatter::CURRENCY);
     /**
      * The precision of the integer amount for a given Money
      * (cents, thousandths, 10-thousandths, etc) should be
      * stored in the Currency object. We assume amounts are
      * represented in cents.
      *
      * Loss of precision due to conversion is possible, but only when
      * displaying prices. This operation does not affect amounts
      */
     return $moneyFormatter->formatCurrency($money->getAmount() / 100, $money->getCurrency()->getIso());
 }
Example #5
0
 /**
  * Get current key
  */
 protected function getKey()
 {
     return "{$this->key}_{$this->locale->getIso()}";
 }
 /**
  * Translate the entity to given locale
  *
  * @param LifecycleEventArgs $args Arguments
  */
 public function postLoad(LifecycleEventArgs $args)
 {
     $this->container->get('elcodi.entity_translator')->translate($args->getEntity(), $this->locale->getIso());
 }