Php 翻译不在Symfony2中工作
我在Php 翻译不在Symfony2中工作,php,symfony,twig,xliff,symfony-2.6,Php,Symfony,Twig,Xliff,Symfony 2.6,我在FooBundle/Resources/translations/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"> <bo
FooBundle/Resources/translations/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="1">
<source>Foo</source>
<target>Bar</target>
</trans-unit>
</body>
</file>
</xliff>
或细枝模板:
// FooBundle/Resources/views/Default/index.html.twig
{{ 'Foo'|trans }} or {% trans %}Foo{% endtrans %}
它总是显示Foo
(原始字符串)
作为默认语言环境,我使用英语('en')。我的语言环境配置来自config.yml
:
framework:
translator: { fallback: "%locale%" }
default_locale: "%locale%"
...
我试图清理缓存,但没有任何区别
如果我尝试调试这些翻译,则表明它们正在被使用:
$ php app/console debug:translation fr FooBundle
+----------+---------------+----------------------+
| State(s) | Id | Message Preview (fr) |
+----------+---------------+----------------------+
| | Foo | Bar |
+----------+---------------+----------------------+
知道这里出了什么问题吗?问题似乎是我安装的另一个捆绑包(LuneticsLocaleBundle)
它必须以某种方式覆盖
$request->setLocale(“fr”)代码>我在控制器中使用,因此结果表明我使用了en_US
作为区域设置。这就是为什么它没有显示翻译的原因。只是在没有修改的情况下使用您的代码进行了测试(Symfony 2.6.3),并且它可以正常工作。尝试输出框架包的设置,并检查与转换器服务相关的所有内容是否正常。
$ php app/console debug:translation fr FooBundle
+----------+---------------+----------------------+
| State(s) | Id | Message Preview (fr) |
+----------+---------------+----------------------+
| | Foo | Bar |
+----------+---------------+----------------------+