Search code examples
symfonydoctrine-ormdoctrine-extensions

How to print translatable values in twig ( doctrine extension)


I am using translatable

It can handle the data directly depending on the current locale setting.

However I want to access each data sometimes with ignoring locale setting.

in contoroller.

I can access each data like this.

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

Then, is there any way to fetch each language data in twig??

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

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

Solution

  • How about passing the translations to your Twig template since you need to show them:

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

    And then in your Twig template you could do something like:

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

    The official documentation might help.