Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate messages inside twig in symfony2

Tags:

twig

symfony

I'm trying to access to the translations via twig.

For example, I have the name of my application inside my Resources/translations/messages.de.yml and Resources/translations/messages.en.yml

My controller does only a render of the twig file.

And inside my twig-file I want to access to the application.name property which is defined inside the messages-file (yml)

How can I access to this property to get the application name (let's say it contains some language-specific information)

I tried these methods, and failed:

  • {{ application.name }}
    • Looks more like for variables which have been sent through the controller, I've got an error, that the variable 'application' was not found
  • {% trans% } application.name {% endtrans %}
    • displays application.name
  • {% trans% } 'application.name' {% endtrans %}
    • displays 'application.name'
like image 646
eav Avatar asked Feb 21 '13 17:02

eav


1 Answers

With inline notation you should use filter:

{{ 'application.name'|trans }}

With trans tag I think problem in whitespaces around application.name

like image 59
nucleartux Avatar answered Sep 22 '22 21:09

nucleartux