当前位置: 首页>>代码示例>>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;未经允许,请勿转载。