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); }
/** * Set the right locale via context. * * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); if (!$request->hasPreviousSession()) { return; } $request->setLocale($this->localeContext->getCurrentLocale() ?: $this->localeContext->getDefaultLocale()); }
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 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 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'); }
/** * {@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) { } }
/** * @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()); }
/** * {@inheritdoc} */ public function formatAmount($amount, $currencyCode = null, $locale = null) { $locale = $locale ?: $this->localeContext->getLocaleCode(); return $this->decoratedHelper->formatAmount($amount, $currencyCode, $locale); }
/** * {@inheritdoc} */ public function getLocaleCode() { return $this->localeContext->getCurrentLocale(); }
function it_formats_money_using_default_locale_if_not_given(LocaleContextInterface $localeContext, MoneyFormatterInterface $moneyFormatter) { $localeContext->getDefaultLocale()->willReturn('fr_FR'); $moneyFormatter->format(312, 'EUR', 'fr_FR')->willReturn('€3.12'); $this->formatAmount(312, 'EUR')->shouldReturn('€3.12'); }
/** * {@inheritdoc} */ public function getFallbackLocale() { return $this->localeContext->getDefaultLocale(); }
/** * @return Response */ public function renderSelectorAction() { return $this->templatingEngine->renderResponse('SyliusShopBundle:Locale:selector.html.twig', ['activeLocaleCode' => $this->localeContext->getLocaleCode(), 'availableLocalesCodes' => $this->localeProvider->getAvailableLocalesCodes()]); }
/** * @return Response */ public function renderAction() { return $this->templatingEngine->renderResponse('@SyliusShop/_localeSwitch.html.twig', ['active' => $this->localeContext->getLocaleCode(), 'locales' => $this->localeProvider->getAvailableLocalesCodes()]); }
/** * {@inheritdoc} */ protected function getDefaultLocale() { return $this->localeContext->getLocale(); }
function it_returns_required_locales(LocaleContextInterface $syliusLocaleContext) { $syliusLocaleContext->getDefaultLocale()->shouldBeCalled()->willReturn('pl_PL'); $this->getRequiredLocales()->shouldReturn(array('pl_PL')); }
function it_converts_locales_code_to_name(LocaleContextInterface $localeContext) { $localeContext->getCurrentLocale()->shouldBeCalled()->willReturn('en_US'); $this->convertToName('fr_FR')->shouldReturn('French (France)'); }
/** * @param GetResponseEvent $event * * @throws LocaleNotFoundException */ public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); $request->setLocale($this->localeContext->getLocaleCode()); $request->setDefaultLocale($this->localeProvider->getDefaultLocaleCode()); }
/** * {@inheritdoc} */ public function formatAmount($amount, $currencyCode = null, $locale = null) { $locale = $locale ?: $this->localeContext->getDefaultLocale(); $currencyCode = $currencyCode ?: $this->currencyContext->getCurrencyCode(); return $this->moneyFormatter->format($amount, $currencyCode, $locale); }
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'); }
function it_gets_current_locale_code_from_context(LocaleContextInterface $localeContext) { $localeContext->getLocaleCode()->willReturn('en_US'); $this->getLocaleCode()->shouldReturn('en_US'); }
/** * {@inheritdoc} */ public function getRequiredLocales() { return [$this->syliusLocaleContext->getDefaultLocale()]; }