翻译Flash消息 [英] Translate the Flash Message
本文介绍了翻译Flash消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果表格成功,我将尝试翻译我发送的即显消息. 正常的请求如下所示:
I'm trying to translate the flash message I sent, if a form is succesful. The normal request looks like this:
$request->getSession()->getFlashBag()->add(
'notice',
'Your E-Mail has been sent.'
);
因此,我尝试使用以下变量来翻译消息:
So I tried to translate the message with the following variable:
$request->getSession()->getFlashBag()->add(
'notice',
'contact.message.email_has_been_sent'
);
发送表格后,消息显示为"contact.message.email_has_been_sent".因此它没有找到翻译,但变量正确.我在模板文件中对其进行了测试. 有谁知道我该如何解决?我还没有发现任何有用的东西.
After sending the form the message shows "contact.message.email_has_been_sent". So it didn't found the translation, but the variable is right. I tested it inside a template file. Has anyone an idea, how I could fix this? I didn't found anything useful yet.
推荐答案
假设您在Controller中:
Presuming you are in a Controller:
$request->getSession()->getFlashBag()->add(
'notice',
$this->get('translator')->trans('contact.message.email_has_been_sent'));
阅读如何处理翻译.
这篇关于翻译Flash消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文