2

It is getting late and I think my mind is shutting down...for the life of me I cannot work out how to change the translation key to work with the value of currentType.

{% set currentType = site.getCurrentType() %}
{{ 'messages.site.{currentType}'|trans({ '%url%' : path('appbundle_course_url', { 'subdomain': site.subdomain }) }) }}

I'm doing something derpy and will kick myself when I see the solution. I just know it.

crmpicco
  • 16,605
  • 26
  • 134
  • 210
  • `'messages.site.'~currentType` ? – Goku Aug 04 '16 at 10:01
  • @DOZ Thanks, I had tried that. It does concat the string together but it doesn't translate. I'm left with an output of `messages.site.typenamehere'. (Yep, i've cleared the Symfony cache and double and triple checked the translation)... – crmpicco Aug 04 '16 at 10:07
  • simple question : if you put the correct value directly instead of Twig variable, does translation works (just to be sure) ? – Goku Aug 04 '16 at 10:11

1 Answers1

2

DOZ hint was actually almost correct.

'messages.site.'~currentType|trans

means translate currentType then append to string (Filter is applied first). So proper braces do the trick.

This works in my Code:

{{ ('messages.site.'~currentType)|trans({ '%url%' : path('appbundle_course_url', { 'subdomain': site.subdomain }) }) }}
Joe
  • 2,356
  • 10
  • 15