function it_should_assign_current_and_default_locale_to_given_translatable_entity(TranslationLocaleProviderInterface $translationLocaleProvider, TranslatableInterface $translatableEntity)
 {
     $translationLocaleProvider->getDefaultLocaleCode()->willReturn('en_US');
     $translatableEntity->setCurrentLocale('en_US')->shouldBeCalled();
     $translatableEntity->setFallbackLocale('en_US')->shouldBeCalled();
     $this->assignLocale($translatableEntity);
 }
Exemplo n.º 2
0
 /**
  * @param string $name
  *
  * @return string
  */
 protected function getPropertyName($name)
 {
     if (in_array($name, $this->translatableFields, true)) {
         return 'translations.' . $this->localeProvider->getDefaultLocaleCode() . '.' . $name;
     }
     return $name;
 }
Exemplo n.º 3
0
 function it_creates_translatable_and_sets_locales(FactoryInterface $factory, TranslationLocaleProviderInterface $localeProvider, TranslatableInterface $resource)
 {
     $localeProvider->getDefaultLocaleCode()->willReturn('pl_PL');
     $factory->createNew()->willReturn($resource);
     $resource->setCurrentLocale('pl_PL')->shouldBeCalled();
     $resource->setFallbackLocale('pl_PL')->shouldBeCalled();
     $this->createNew()->shouldReturn($resource);
 }
 function it_should_use_default_locale_as_current_if_could_not_resolve_the_current_locale(LocaleContextInterface $localeContext, TranslationLocaleProviderInterface $translationLocaleProvider, TranslatableInterface $translatableEntity)
 {
     $localeContext->getLocaleCode()->willThrow(new LocaleNotFoundException());
     $translationLocaleProvider->getDefaultLocaleCode()->willReturn('en_US');
     $translatableEntity->setCurrentLocale('en_US')->shouldBeCalled();
     $translatableEntity->setFallbackLocale('en_US')->shouldBeCalled();
     $this->assignLocale($translatableEntity);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  *
  * @throws UnexpectedTypeException
  */
 public function createNew()
 {
     $resource = $this->factory->createNew();
     if (!$resource instanceof TranslatableInterface) {
         throw new UnexpectedTypeException($resource, TranslatableInterface::class);
     }
     $resource->setCurrentLocale($this->localeProvider->getDefaultLocaleCode());
     $resource->setFallbackLocale($this->localeProvider->getDefaultLocaleCode());
     return $resource;
 }
 /**
  * {@inheritdoc}
  */
 public function assignLocale(TranslatableInterface $translatableEntity)
 {
     $fallbackLocale = $this->translationLocaleProvider->getDefaultLocaleCode();
     try {
         $currentLocale = $this->localeContext->getLocaleCode();
     } catch (LocaleNotFoundException $e) {
         $currentLocale = $fallbackLocale;
     }
     $translatableEntity->setCurrentLocale($currentLocale);
     $translatableEntity->setFallbackLocale($fallbackLocale);
 }
Exemplo n.º 7
0
 /**
  * @param TranslationLocaleProviderInterface $localeProvider
  */
 public function __construct(TranslationLocaleProviderInterface $localeProvider)
 {
     $this->definedLocalesCodes = $localeProvider->getDefinedLocalesCodes();
     $this->defaultLocaleCode = $localeProvider->getDefaultLocaleCode();
 }
 /**
  * {@inheritdoc}
  */
 public function assignLocale(TranslatableInterface $translatableEntity)
 {
     $localeCode = $this->translationLocaleProvider->getDefaultLocaleCode();
     $translatableEntity->setCurrentLocale($localeCode);
     $translatableEntity->setFallbackLocale($localeCode);
 }