我正在尝试translator.default
在 a 中使用该服务Controller
,但是我尝试通过该trans
方法翻译的任何消息都会返回未翻译的密钥。
/**
* @Route("/testT")
*/
public function testTAction(Request $req)
{
$translator = $this->get('translator.default');
$translated = $translator->trans('Hello from the other side');
die(dump($translated));
}
为了确保我的密钥被正确加载,我做了以下检查:
php app/console translation:update it --dump-messages
输出以下内容:
Translation Messages Extractor and Dumper
=========================================
// Generating "it" translation files for "app folder"
// Parsing templates...
// Loading translation files...
Messages extracted for domain "messages" (1 messages)
-----------------------------------------------------
* Hello from the other side
[OK] 1 messages were successfully extracted
我的密钥存储在<root>/app/resources/translations/messages.it.yml
我的语言环境下,当请求翻译的密钥设置良好时:
$translator = $this->get('translator.default');
die(dump($translator->getLocale()));
如果在我的控制器中调用,这会生成以下输出:"it",我猜它是正确的。所以:我哪里错了?
编辑
这是我的<root>/app/Resources/translations/messages.it.yml
Hello from the other side: Ciao dall'altra parte
这是与我的翻译服务相关的块<root>/app/config/config.yml
framework:
translator: { fallbacks: it }
我正在使用开发配置,但与那里的翻译无关。