コード例 #1
0
 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);
 }
コード例 #2
0
ファイル: LocaleSubscriber.php プロジェクト: lingoda/Sylius
 /**
  * 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());
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 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');
 }
コード例 #6
0
 /**
  * {@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);
 }
コード例 #7
0
 /**
  * @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) {
     }
 }
コード例 #8
0
 /**
  * @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());
 }
コード例 #9
0
ファイル: MoneyHelper.php プロジェクト: ReissClothing/Sylius
 /**
  * {@inheritdoc}
  */
 public function formatAmount($amount, $currencyCode = null, $locale = null)
 {
     $locale = $locale ?: $this->localeContext->getLocaleCode();
     return $this->decoratedHelper->formatAmount($amount, $currencyCode, $locale);
 }
コード例 #10
0
ファイル: ShopperContext.php プロジェクト: okwinza/Sylius
 /**
  * {@inheritdoc}
  */
 public function getLocaleCode()
 {
     return $this->localeContext->getCurrentLocale();
 }
コード例 #11
0
ファイル: MoneyHelperSpec.php プロジェクト: okwinza/Sylius
 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');
 }
コード例 #12
0
 /**
  * {@inheritdoc}
  */
 public function getFallbackLocale()
 {
     return $this->localeContext->getDefaultLocale();
 }
コード例 #13
0
 /**
  * @return Response
  */
 public function renderSelectorAction()
 {
     return $this->templatingEngine->renderResponse('SyliusShopBundle:Locale:selector.html.twig', ['activeLocaleCode' => $this->localeContext->getLocaleCode(), 'availableLocalesCodes' => $this->localeProvider->getAvailableLocalesCodes()]);
 }
コード例 #14
0
 /**
  * @return Response
  */
 public function renderAction()
 {
     return $this->templatingEngine->renderResponse('@SyliusShop/_localeSwitch.html.twig', ['active' => $this->localeContext->getLocaleCode(), 'locales' => $this->localeProvider->getAvailableLocalesCodes()]);
 }
コード例 #15
0
ファイル: MoneyHelper.php プロジェクト: Strontium-90/Sylius
 /**
  * {@inheritdoc}
  */
 protected function getDefaultLocale()
 {
     return $this->localeContext->getLocale();
 }
コード例 #16
0
 function it_returns_required_locales(LocaleContextInterface $syliusLocaleContext)
 {
     $syliusLocaleContext->getDefaultLocale()->shouldBeCalled()->willReturn('pl_PL');
     $this->getRequiredLocales()->shouldReturn(array('pl_PL'));
 }
コード例 #17
0
 function it_converts_locales_code_to_name(LocaleContextInterface $localeContext)
 {
     $localeContext->getCurrentLocale()->shouldBeCalled()->willReturn('en_US');
     $this->convertToName('fr_FR')->shouldReturn('French (France)');
 }
コード例 #18
0
ファイル: RequestLocaleSetter.php プロジェクト: sylius/sylius
 /**
  * @param GetResponseEvent $event
  *
  * @throws LocaleNotFoundException
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $request->setLocale($this->localeContext->getLocaleCode());
     $request->setDefaultLocale($this->localeProvider->getDefaultLocaleCode());
 }
コード例 #19
0
ファイル: MoneyHelper.php プロジェクト: okwinza/Sylius
 /**
  * {@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);
 }
コード例 #20
0
ファイル: MoneyHelperSpec.php プロジェクト: loic425/Sylius
 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');
 }
コード例 #21
0
 function it_gets_current_locale_code_from_context(LocaleContextInterface $localeContext)
 {
     $localeContext->getLocaleCode()->willReturn('en_US');
     $this->getLocaleCode()->shouldReturn('en_US');
 }
コード例 #22
0
 /**
  * {@inheritdoc}
  */
 public function getRequiredLocales()
 {
     return [$this->syliusLocaleContext->getDefaultLocale()];
 }