本文整理匯總了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());
}
}