繁体   English   中英

Symfony 3-无法加载翻译“消息”文件

[英]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)

这些是我的文件:

  • app / config / config.yml

     parameters: locale: en framework: #esi: ~ translator: { fallbacks: ['%locale%'] } 
  • translations \\ messages.fr_FR.xlf

     <!-- messages.fr.xlf --> <?xml version="1.0"?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="file.ext"> <body> <trans-unit id="symfony_is_great"> <source>Symfony is great</source> <target>J'aime Symfony</target> </trans-unit> </body> </file> </xliff> 
  • 我在Twig文件中使用了鞣制

     {% trans %} Symfony is great { endtrans %} 

我希望你能帮帮我 !!

XML解析器大吼大叫,因为文档声明必须在第一行。 因此,切换这两行,该错误应消失:

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

转换可能无法正常进行,因为模板中的字符串(而不是xml文件)中的字符串周围有空格:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM