/**
  * {@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);
 }
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     try {
         $request->setLocale($this->localeContext->getLocaleCode());
     } catch (LocaleNotFoundException $exception) {
     }
     try {
         $request->setDefaultLocale($this->localeProvider->getDefaultLocaleCode());
     } catch (LocaleNotFoundException $exception) {
     }
 }
 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);
 }
 function it_sets_default_locale_on_request_even_if_locale_context_fails(LocaleContextInterface $localeContext, LocaleProviderInterface $localeProvider, GetResponseEvent $event, Request $request)
 {
     $event->getRequest()->willReturn($request);
     $localeContext->getLocaleCode()->willThrow(LocaleNotFoundException::class);
     $localeProvider->getDefaultLocaleCode()->willReturn('en_US');
     $request->setLocale(Argument::any())->shouldNotBeCalled();
     $request->setDefaultLocale('en_US')->shouldBeCalled();
     $this->onKernelRequest($event);
 }
 function it_sets_locale_and_default_locale_on_request(LocaleContextInterface $localeContext, LocaleProviderInterface $localeProvider, GetResponseEvent $event, Request $request)
 {
     $event->getRequest()->willReturn($request);
     $localeContext->getLocaleCode()->willReturn('pl_PL');
     $localeProvider->getDefaultLocaleCode()->willReturn('en_US');
     $request->setLocale('pl_PL')->shouldBeCalled();
     $request->setDefaultLocale('en_US')->shouldBeCalled();
     $this->onKernelRequest($event);
 }
 function its_nested_request_resolvers_can_have_priority(LocaleContextInterface $firstLocaleContext, LocaleContextInterface $secondLocaleContext, LocaleContextInterface $thirdLocaleContext)
 {
     $firstLocaleContext->getLocaleCode()->shouldNotBeCalled();
     $secondLocaleContext->getLocaleCode()->willReturn('pl_PL');
     $thirdLocaleContext->getLocaleCode()->willThrow(LocaleNotFoundException::class);
     $this->addContext($firstLocaleContext, -5);
     $this->addContext($secondLocaleContext, 0);
     $this->addContext($thirdLocaleContext, 5);
     $this->getLocaleCode()->shouldReturn('pl_PL');
 }
 /**
  * @param LifecycleEventArgs $args
  */
 public function postLoad(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$entity instanceof TranslatableInterface) {
         return;
     }
     try {
         $entity->setCurrentLocale($this->localeContext->getLocaleCode());
     } catch (LocaleNotFoundException $exception) {
         $entity->setCurrentLocale($this->localeProvider->getDefaultLocaleCode());
     }
     $entity->setFallbackLocale($this->localeProvider->getDefaultLocaleCode());
 }
 function it_gets_current_locale_code_from_context(LocaleContextInterface $localeContext)
 {
     $localeContext->getLocaleCode()->willReturn('en_US');
     $this->getLocaleCode()->shouldReturn('en_US');
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function formatAmount($amount, $currencyCode = null, $locale = null)
 {
     $locale = $locale ?: $this->localeContext->getLocaleCode();
     return $this->decoratedHelper->formatAmount($amount, $currencyCode, $locale);
 }
Example #10
0
 /**
  * @return Response
  */
 public function renderSelectorAction()
 {
     return $this->templatingEngine->renderResponse('SyliusShopBundle:Locale:selector.html.twig', ['activeLocaleCode' => $this->localeContext->getLocaleCode(), 'availableLocalesCodes' => $this->localeProvider->getAvailableLocalesCodes()]);
 }
Example #11
0
 /**
  * @param GetResponseEvent $event
  *
  * @throws LocaleNotFoundException
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $request->setLocale($this->localeContext->getLocaleCode());
     $request->setDefaultLocale($this->localeProvider->getDefaultLocaleCode());
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function getLocaleCode()
 {
     return $this->localeContext->getLocaleCode();
 }
Example #13
0
 function it_decorates_the_helper_with_current_locale_if_it_is_not_passed(MoneyHelperInterface $decoratedHelper, LocaleContextInterface $localeContext)
 {
     $localeContext->getLocaleCode()->willReturn('fr_FR');
     $decoratedHelper->formatAmount(42, null, 'fr_FR')->willReturn('Formatted 42 in fr_FR');
     $this->formatAmount(42)->shouldReturn('Formatted 42 in fr_FR');
 }
Example #14
0
 /**
  * @return Response
  */
 public function renderAction()
 {
     return $this->templatingEngine->renderResponse('@SyliusShop/_localeSwitch.html.twig', ['active' => $this->localeContext->getLocaleCode(), 'locales' => $this->localeProvider->getAvailableLocalesCodes()]);
 }