本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
}