當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Translator::getLocale方法代碼示例

本文整理匯總了PHP中Symfony\Bundle\FrameworkBundle\Translation\Translator::getLocale方法的典型用法代碼示例。如果您正苦於以下問題:PHP Translator::getLocale方法的具體用法?PHP Translator::getLocale怎麽用?PHP Translator::getLocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Bundle\FrameworkBundle\Translation\Translator的用法示例。


在下文中一共展示了Translator::getLocale方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testGetLocale

 public function testGetLocale()
 {
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $request->expects($this->once())->method('getLocale')->will($this->returnValue('en'));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->exactly(2))->method('isScopeActive')->with('request')->will($this->onConsecutiveCalls(false, true));
     $container->expects($this->once())->method('has')->with('request')->will($this->returnValue(true));
     $container->expects($this->once())->method('get')->with('request')->will($this->returnValue($request));
     $translator = new Translator($container, new MessageSelector());
     $this->assertNull($translator->getLocale());
     $this->assertSame('en', $translator->getLocale());
 }
開發者ID:TuxCoffeeCorner,項目名稱:tcc,代碼行數:12,代碼來源:TranslatorTest.php

示例2: sendMessage

 /**
  * Override the fosuserbundles original sendMessage, to embed template variables etc. into html-emails.
  * @param  string  $templateName
  * @param  array   $context
  * @param  string  $fromEmail
  * @param  string  $toEmail
  * @return boolean true if the mail was sent successfully, else false
  */
 protected function sendMessage($templateName, $context, $fromEmail, $toEmail)
 {
     // get the subject from the template
     // => make sure the subject block exists in your fos-templates (FOSUserBundle:Registration:email.txt.twig & FOSUserBundle:Resetting:email.txt.twig)
     $twigTemplate = $this->loadTemplate($templateName);
     $subject = $twigTemplate->renderBlock('subject', $context);
     return $this->sendSingleEmail($toEmail, null, $subject, $context, $templateName, $this->translator->getLocale());
 }
開發者ID:azine,項目名稱:email-bundle,代碼行數:16,代碼來源:AzineTwigSwiftMailer.php

示例3: testGetDefaultLocale

 public function testGetDefaultLocale()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->once())->method('getParameter')->with('kernel.default_locale')->will($this->returnValue('en'));
     $translator = new Translator($container, new MessageSelector());
     $this->assertSame('en', $translator->getLocale());
 }
開發者ID:Dren-x,項目名稱:mobit,代碼行數:7,代碼來源:TranslatorTest.php

示例4: testGetLocaleWithInvalidLocale

 public function testGetLocaleWithInvalidLocale()
 {
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $request->expects($this->any())->method('getLocale')->will($this->returnValue('foo bar'));
     $request->expects($this->once())->method('getDefaultLocale')->will($this->returnValue('en-US'));
     $requestStack = new RequestStack();
     $requestStack->push($request);
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->once())->method('get')->with('request_stack')->will($this->returnValue($requestStack));
     $translator = new Translator($container, new MessageSelector());
     $this->assertSame('en-US', $translator->getLocale());
 }
開發者ID:carlostopo,項目名稱:prueba_runator,代碼行數:12,代碼來源:TranslatorTest.php

示例5: testGetLocale

 /**
  * @dataProvider getGetLocaleData
  */
 public function testGetLocale($inRequestScope)
 {
     $requestStack = new RequestStack();
     if ($inRequestScope) {
         $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
         $request->expects($this->once())->method('getLocale')->will($this->returnValue('en'));
         $requestStack->push($request);
     }
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->once())->method('get')->with('request_stack')->will($this->returnValue($requestStack));
     $translator = new Translator($container, new MessageSelector());
     if ($inRequestScope) {
         $this->assertSame('en', $translator->getLocale());
     } else {
         $this->assertNull($translator->getLocale());
     }
 }
開發者ID:raphael-thibierge,項目名稱:ProgWebServerProject,代碼行數:20,代碼來源:TranslatorTest.php


注:本文中的Symfony\Bundle\FrameworkBundle\Translation\Translator::getLocale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。