Home > Software engineering >  Make translation fixed in html twig template - symfony
Make translation fixed in html twig template - symfony

Time:12-31

I have this part of code in my twig template:

  {{ 'find.cars.back'|trans({'%url%': path('find_index')})|markdown }}

and it gives me translated text depending on the language that the user selected on the website, however, I wanna make this translation fixed, to be always English, I know i can put fixed text, but what I want is that

find.cars.back

calls always English-translated text and not text depending on the chosen locale. any help?

CodePudding user response:

The |trans() filter allows you to set a fixed locale as 3rd argument or by using it as named argument. For your example, it should probably look something like this:

{{ 'find.cars.back'|trans(arguments={'%url%': path('find_index')}, locale='en')|markdown }}

or without named arguments:

{{ 'find.cars.back'|trans({'%url%': path('find_index')}, 'messages', 'en')|markdown }}

I use the generic en locale, but you can also use the more specific en-US (or whichever other region you want to set).

  • Related