我想使用树枝模板系统为我的电子邮件创建模板。电子邮件的区域设置应该基于用户设置,而不是来自会话或请求区域设置。渲染枝条模板时如何强制区域设置?强制树枝区域设置
该手册确实提到了如何to force the locale for the Translator。但是我想将这个语言环境传递给render()方法,以便在该语言环境中呈现树枝模板内部的翻译。
这与在模板中将转换为不同,因为我认为这会强制在特定区域设置的模板内进行翻译。
因此,采取从Symfony的例子,我在寻找这样的事情:
public function indexAction($name)
{
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody(
$this->renderView(
'HelloBundle:Hello:email.txt.twig',
array('name' => $name),
'nl_NL' // <-- This would be nice!
)
)
;
$this->get('mailer')->send($message);
return $this->render(...);
}
是的,但我不认为模板会自动为{%trans%}块使用此区域设置,是不是? – rolandow 2013-03-08 12:52:35
不,你可以强制转换过滤器使用语言环境,你想'{{“Hello”| trans({},“messages”,locale)}}',翻译器组件自动使用请求中定义的语言环境,if你想改变它'$ this-> get('translator') - > setLocale($ locale);' – 2013-03-25 09:47:27