我一直在尝试这样做:https://symfony.com/doc/current/translation.html
但似乎没有人对翻译有任何问题,我必须完全弄错。
我的区域设置在'services.yaml‘中设置为'fr’
我有我的message.en.xlf和message.fr.xlf
这是我的.fr:
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="fr" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="homepage_presta">
<source>homepage.presta</source>
<target>Les prestations</target>
</trans-unit>
</body>
</file>
</xliff>在控制器中尝试(收到“缺少转换键”警告):
var_dump($translator->trans("homepage_presta"));或者在细枝中:
{{ 'homepage.presta'|trans }} 但是什么都不起作用..最后,我想根据浏览器语言翻译成正确的语言,如果在导航栏中选择了语言(就像在cookie中?),则翻译成某种语言。
发布于 2018-06-10 02:44:49
/**
* @Route("/test/translation")
*/
public function translationAction(TranslatorInterface $translator)
{
dump($translator->trans("homepage.presta"));
return new Response('<html><body>testaroni</body></html>');
}对我来说很有效。一些事情..。
messages not
<source>homepage.presta</source>进行转换,而不是id message。每次创建新的转换文件php bin/console cache:clear时,请忘记清除缓存
https://stackoverflow.com/questions/50774935
复制相似问题