function it_sets_locale_and_translatable_resource_for_translations(FormEvent $event, FormInterface $form, Collection $data, FormInterface $parent, TranslatableInterface $translatable, TranslationInterface $englishTranslation, TranslationInterface $polishTranslation)
 {
     $event->getData()->willReturn($data);
     $event->getForm()->willReturn($form);
     $form->getParent()->willReturn($parent);
     $parent->getNormData()->willReturn($translatable);
     $data->getIterator()->willReturn(new \ArrayIterator(['en_US' => $englishTranslation->getWrappedObject(), 'pl_PL' => $polishTranslation->getWrappedObject()]));
     $englishTranslation->setLocale('en_US')->shouldBeCalled();
     $englishTranslation->setTranslatable($translatable)->shouldBeCalled();
     $polishTranslation->setLocale('pl_PL')->shouldBeCalled();
     $polishTranslation->setTranslatable($translatable)->shouldBeCalled();
     $this->submit($event);
 }
Beispiel #2
0
 /**
  * @param TranslationInterface $translation
  */
 public function addTranslation(TranslationInterface $translation)
 {
     if (!$this->translations->containsKey($translation->getLocale())) {
         $this->translations->set($translation->getLocale(), $translation);
         $translation->setTranslatable($this);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function translate($locale = null)
 {
     $locale = $locale ?: $this->currentLocale;
     if (null === $locale) {
         throw new \RuntimeException('No locale has been set and current locale is undefined.');
     }
     if ($this->currentTranslation && $locale === $this->currentTranslation->getLocale()) {
         return $this->currentTranslation;
     }
     if (!($translation = $this->translations->get($locale))) {
         if (null === $this->fallbackLocale) {
             throw new \RuntimeException('No fallback locale has been set.');
         }
         if (!($fallbackTranslation = $this->translations->get($this->getFallbackLocale()))) {
             $className = $this->getTranslationClass();
             /** @var TranslationInterface $translation */
             $translation = new $className();
             $translation->setLocale($locale);
             $this->addTranslation($translation);
         } else {
             $translation = clone $fallbackTranslation;
         }
     }
     $this->currentTranslation = $translation;
     return $translation;
 }