1

I am using translation.en.yml in twig.

What I want to do is very simple ,please check the code below.

in my twig

{{ "message.thxContactUs" | trans({'%username%' : "myName"})}}

in my translation.en.yml

message: 
    thxContactUs: Dear {{username}} thank you for contacting us 

however this out put is

Dear {{username}} thank you for contacting us 

however it doesn't work, please could anyone correct this code??

whitebear
  • 11,200
  • 24
  • 114
  • 237
  • 1
    The way you pass your variable from twig should match in your translation file as well. Change `{{username}}` with `%username%` – Artamiel Jul 06 '15 at 10:19
  • Thanks your comment slove my problem – whitebear Jul 06 '15 at 10:49
  • Keep in mind that using `% ... %` is just a convention. It's followed by most Symfony developers and it's recommended to use that format, but if you don't like it, you can change it. In your example, you could use `{{ "message.thxContactUs" | trans({'{{username}}' : "myName"}) }}` and it should work perfectly. – Javier Eguiluz Jul 06 '15 at 15:47
  • Thanks I will obey the standard way though, it is good knowledge for me. – whitebear Jul 07 '15 at 10:38

1 Answers1

3

You have to type the variable in yml on this way:

message: 
    thxContactUs: Dear %username% thank you for contacting us

Check this question:

How to handle Translation in twig file using variables?

Community
  • 1
  • 1