Translate messages inside a branch in symfony2

I'm trying to access translations through a twig.

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

My controller only renders from the twig file.

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

How can I access this property to get the name of the application (let it contain some information related to the language)

I tried these methods and failed:

  • {{ application.name }}
    • It looks like for the variables that were sent through the controller, I have an error that the variable 'application' was not found
  • {% trans% } application.name {% endtrans %}
    • displays application.name
  • {% trans% } 'application.name' {% endtrans %}
    • displays 'application.name'
+7
source share
2 answers

With built-in notation you should use a filter:

 {{ 'application.name'|trans }} 

With the trans tag, I think the problem is in spaces around application.name

+20
source
 {% trans% }app.name{% endtrans %} 

In your .en.yml posts

 <trans-unit id="app.name" resname="app.name"> <source>My app</source> <target>My app</target> </trans-unit> 

In your posts .de.yml

  <trans-unit id="app.name" resname="app.name"> <source>My app</source> <target>Meine App</target> </trans-unit> 
-one
source

All Articles