1

私は翻訳可能を使用しています

現在のロケール設定に応じて、データを直接処理できます。

しかし、ときどきロケール設定を無視して各データにアクセスしたいことがあります。

コントローラで。

このように各データにアクセスできます。

    $transRepo = $em->getRepository('Gedmo\Translatable\Entity\Translation');
    $repo = $transRepo->findTranslations($myEntity);
    var_dump($repo['en']['comment']);

では、小枝で各言語のデータを取得する方法はありますか??

{{comment}} // it shows the comment depending on the locale setting.

{{comment | trancelate(en)}} // I want to ignore the locale setting like this.
4

1 に答える 1

3

翻訳を表示する必要があるため、翻訳を Twig テンプレートに渡してみませんか。

$translations = $repository->findTranslations($article);

次に、Twig テンプレートで次のようなことができます。

{{ translations.en.comment }}
{{ translations.de.comment }}
{{ translations.fr.comment }}

公式ドキュメントが役立つかもしれません。

于 2015-04-18T10:24:23.903 に答える