Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 翻译不在Symfony2中工作_Php_Symfony_Twig_Xliff_Symfony 2.6 - Fatal编程技术网

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                  |
+----------+---------------+----------------------+