当前位置: 首页>>代码示例>>PHP>>正文


PHP TranslatorInterface::setLocale方法代码示例

本文整理汇总了PHP中Symfony\Component\Translation\TranslatorInterface::setLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslatorInterface::setLocale方法的具体用法?PHP TranslatorInterface::setLocale怎么用?PHP TranslatorInterface::setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Translation\TranslatorInterface的用法示例。


在下文中一共展示了TranslatorInterface::setLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onKernelRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if ($this->session->has('_locale')) {
         $event->getRequest()->setLocale($this->session->get('_locale'));
         $this->translator->setLocale($this->session->get('_locale'));
     }
 }
开发者ID:ChrisdAutume,项目名称:EtuUTT,代码行数:10,代码来源:LocaleListener.php

示例2: setUp

 /**
  * Set up the tests.
  */
 public function setUp()
 {
     parent::setUp();
     $this->translator = $this->app['translator'];
     $this->detector = new LanguageDetector($this->translator);
     $this->translator->setLocale('fr');
 }
开发者ID:bitbeans,项目名称:laravel-language-detector,代码行数:10,代码来源:AbstractDriversTestCase.php

示例3: setLocale

 /**
  * @param HttpRequest $request
  * @param string $locale
  */
 public function setLocale(HttpRequest $request, $locale)
 {
     setlocale(LC_ALL, $locale);
     $locale = substr($locale, 0, 2);
     $request->setLocale($locale);
     $this->translator->setLocale($locale);
     $this->translatable->setTranslatableLocale($locale);
 }
开发者ID:anime-db,项目名称:app-bundle,代码行数:12,代码来源:Request.php

示例4: initialize

 private function initialize()
 {
     if ($this->initialized || $this->requestAnalyzer->getCurrentLocalization() === null) {
         return;
     }
     $this->translator->setLocale($this->requestAnalyzer->getCurrentLocalization()->getLocale(Localization::LCID));
     $this->initialized = true;
 }
开发者ID:sulu,项目名称:sulu,代码行数:8,代码来源:RequestAnalyzerTranslator.php

示例5: sendEmail

 public function sendEmail($type, $emailAddress, $arguments, $locale = 'en')
 {
     $this->eventDispatcher->dispatch(EmailEvent::BEFORE_SEND, new EmailEvent($type, $emailAddress, $arguments));
     $this->translator->setLocale($locale);
     $message = $this->constructEmailMessage($type, $emailAddress, $arguments);
     $status = $this->emailService->send($message);
     $this->dispatchEmailSendingEvent($type, $arguments, $message, $status);
     return $status;
 }
开发者ID:symfony-tutorial,项目名称:app,代码行数:9,代码来源:CommunicationService.php

示例6: onPostUpdate

 /**
  * @param GenericEvent $event
  */
 public function onPostUpdate(GenericEvent $event)
 {
     $user = $event->getSubject();
     if ($user === $event->getArgument('current_user')) {
         $request = $this->requestStack->getMasterRequest();
         $request->getSession()->set('_locale', $user->getUiLocale()->getCode());
         $this->translator->setLocale($user->getUiLocale()->getCode());
     }
 }
开发者ID:userz58,项目名称:pim-community-dev,代码行数:12,代码来源:LocaleSubscriber.php

示例7: onKernelRequest

 /**
  * onKernelRequest
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $url = $event->getRequest()->getRequestUri();
     $token = $this->context->getToken();
     if ($token && $this->isAdminToken($this->providerKey, $token) && $this->isAdminRoute($url)) {
         $locale = $token->getUser()->getAdminLocale();
         if (!$locale) {
             $locale = $this->defaultAdminLocale;
         }
         $this->translator->setLocale($locale);
     }
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:17,代码来源:AdminLocaleListener.php

示例8: setLocale

 /**
  * Set new locale.
  *
  * @param  string  $locale
  * @throws LanguageNotFoundException
  */
 public function setLocale($locale)
 {
     if (!in_array($locale, $this->getAvailableLanguages())) {
         throw new LanguageNotFoundException("Language {$locale} not found.");
     }
     $this->translator->setLocale($locale);
 }
开发者ID:arooth,项目名称:multi-language,代码行数:13,代码来源:LanguageManager.php

示例9: setRequestLocale

 public function setRequestLocale(GetResponseEvent $event)
 {
     $token = $this->tokenStorage->getToken();
     if (!$token) {
         return;
     }
     /** @var Identity $identity */
     $identity = $token->getUser();
     $request = $event->getRequest();
     $request->setLocale($identity->preferredLocale);
     // As per \Symfony\Component\HttpKernel\EventListener\TranslatorListener::setLocale()
     try {
         $this->translator->setLocale($request->getLocale());
     } catch (\InvalidArgumentException $e) {
         $this->translator->setLocale($request->getDefaultLocale());
     }
 }
开发者ID:eefjevanderharst,项目名称:Stepup-SelfService,代码行数:17,代码来源:LocaleListener.php

示例10: onKernelRequest

 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$this->isApiRequest($request)) {
         return;
     }
     // request language
     if ($request->headers->has('Language')) {
         $this->translator->setLocale($request->headers->get('Language'));
         $request->setLocale($request->headers->get('Language'));
     }
     // request content type
     if ($type = $request->getContentType()) {
         switch ($type) {
             case 'json':
                 $request->setRequestFormat('json');
                 break;
             default:
                 $mime = $request->headers->get('Content-Type');
                 throw new HttpException(406, "The content type: \"{$type}\" specified as mime \"{$mime}\" - is not supported.");
         }
     } else {
         // default format is JSON
         $request->setRequestFormat('json');
     }
     // request accept content type, currently only JSON
     $accepts = $request->getAcceptableContentTypes();
     $types = array_filter(array_unique(array_map([$request, 'getFormat'], $accepts)));
     if ($types && !in_array('json', $types, true)) {
         $acceptable = implode(',', $accepts);
         throw new HttpException(406, "None of acceptable content types: {$acceptable} are supported.");
     }
     // if there is a body, decode it currently as JSON only
     if ($content = $request->getContent()) {
         $data = @json_decode($content, true);
         if (null === $data) {
             // the error may be important, log it
             if (null !== $this->logger) {
                 $this->logger->error("Failed to parse json request content, err: " . json_last_error_msg());
             }
             throw new HttpException(400, "The given content is not a valid json.");
         }
         $request->request = new ParameterBag($data);
     }
 }
开发者ID:vaidasif,项目名称:symfony-force,代码行数:45,代码来源:ApiResponseListener.php

示例11: sendBatchMail

 /**
  * @param $fromEmail
  * @param BatchEntryMail $batchMail
  * @param $doSend
  */
 private function sendBatchMail($fromEmail, BatchEntryMail $batchMail, $doSend)
 {
     $receivers = $batchMail->getReceiverEntries($this->em);
     $this->writeOutput('Sending "' . $batchMail->getName() . '" mail to ' . count($receivers) . ' people from ' . $fromEmail);
     $spool = $this->mailer->getTransport()->getSpool();
     foreach ($receivers as $receiver) {
         $this->writeOutput(' -> ' . $receiver->getEmail());
         $htmlTemplate = $batchMail->getHtmlTemplate($receiver);
         $plainTextTemplate = $batchMail->getPlainTextTemplate($receiver);
         $templateData = $batchMail->getTemplateData($receiver, $this->em);
         $this->translator->setLocale($receiver->getPool()->getLocale());
         $plainTextBody = $this->twig->render($plainTextTemplate, $templateData);
         $htmlBody = $this->twig->render($htmlTemplate, $templateData);
         $message = \Swift_Message::newInstance()->setSubject($batchMail->getSubject($receiver, $this->translator))->setFrom($fromEmail, $batchMail->getFrom($receiver, $this->translator))->setTo($receiver->getEmail())->setBody($plainTextBody)->addPart($htmlBody, 'text/html');
         if ($doSend) {
             $this->mailer->send($message);
             $spool->flushQueue($this->transport);
             $batchMail->handleMailSent($receiver, $this->em);
         }
     }
 }
开发者ID:vincecore,项目名称:SecretSanta,代码行数:26,代码来源:Mailer.php

示例12: render

 /**
  * renders content with the real website controller.
  *
  * @param PageBridge $content
  * @param bool       $partial
  *
  * @return string
  */
 public function render(PageBridge $content, $partial = false)
 {
     // set active theme
     $webspace = $this->webspaceManager->findWebspaceByKey($content->getWebspaceKey());
     $this->activeTheme->setName($webspace->getTheme()->getKey());
     // get controller and invoke action
     $request = new Request();
     $request->attributes->set('_controller', $content->getController());
     $controller = $this->controllerResolver->getController($request);
     // prepare locale for translator and request
     $request->setLocale($content->getLanguageCode());
     $localeBefore = $this->translator->getLocale();
     $this->translator->setLocale($content->getLanguageCode());
     $this->requestStack->push($request);
     /** @var Response $response */
     $response = $controller[0]->{$controller[1]}($content, true, $partial);
     // roll back
     $this->requestStack->pop();
     $this->translator->setLocale($localeBefore);
     return $response->getContent();
 }
开发者ID:kriswillis,项目名称:sulu,代码行数:29,代码来源:PreviewRenderer.php

示例13: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     if (!is_array($controller)) {
         // not a object but a different kind of callable. Do nothing
         return;
     }
     $controllerObject = $controller[0];
     if ($controllerObject instanceof CantigaController) {
         // set the time formatting settings
         $this->translator->setLocale($event->getRequest()->getLocale());
         $this->timeFormatter->configure($this->translator, $event->getRequest()->getLocale(), $event->getRequest()->getSession()->get('timezone'));
         $this->localeProvider->setLocale($event->getRequest()->getLocale());
         // initialize the controller
         $potentialResponse = $controllerObject->initialize($event->getRequest(), $this->authChecker);
         if (!empty($potentialResponse)) {
             $event->setController(function () use($potentialResponse) {
                 return $potentialResponse;
             });
         }
     }
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:22,代码来源:GeneralListener.php

示例14: onConsoleCommand

 public function onConsoleCommand()
 {
     setlocale(LC_ALL, $this->locale);
     $this->translator->setLocale($this->locale);
     $this->translatable->setTranslatableLocale(substr($this->locale, 0, 2));
 }
开发者ID:anime-db,项目名称:app-bundle,代码行数:6,代码来源:Console.php

示例15:

 function it_proxies_setting_the_locale_to_the_decorated_translator(TranslatorInterface $translator)
 {
     $translator->setLocale('pl_PL')->shouldBeCalled();
     $this->setLocale('pl_PL');
 }
开发者ID:Sylius,项目名称:SyliusThemeBundle,代码行数:5,代码来源:ThemeAwareTranslatorSpec.php


注:本文中的Symfony\Component\Translation\TranslatorInterface::setLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。