フランス語の翻訳を含むファイルがあります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/Controller/DefaultController.php
/**
* @Route("/")
* @Template()
*/
public function indexAction(Request $request)
{
$request->setLocale("fr");
$translatedMessage = $this->get('translator')->trans('Foo');
echo $translatedMessage;
return array();
}
または小枝テンプレート:
// 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 |
+----------+---------------+----------------------+
ここで何がうまくいかないのですか?