Symfony 3 - 无法加载翻译 "messages" 文件

Symfony 3 - Unable to load the translations "messages" file

我是 Symfony 3 的新手,希望你能帮助我。

我想在我的项目中使用翻译组件,我遵循了这个步骤“https://symfony.com/doc/3.4/translation.html#configuration”但是当我使用 CLI 清除缓存时,我遇到了这个错误并且翻译不起作用:

>php bin/console cache:clear

// Clearing the cache for the dev environment with debug true


In XliffFileLoader.php line 56:

  Unable to load "C:\wamp64\www\MyWebSite/translations\messages.en_US.xlf": [ERROR 64] XML declaration allowed only at the start of the document (in n/a - line 2, column 6)


In XmlUtils.php line 62:

  [ERROR 64] XML declaration allowed only at the start of the document (in n/a - line 2, column 6)

这些是我的文件:

希望你能帮帮我!!

XML 解析器对你大喊大叫,因为文档声明需要在第一行。所以切换这两行,错误应该消失:

<!-- messages.fr.xlf -->
<?xml version="1.0"?>

翻译可能无法正常工作,因为模板中的字符串周围有空格,而 xml 文件中没有:

<source>Symfony is great</source>
{% trans %} Symfony is great { endtrans %}