eav
eav

Reputation: 2171

Translate messages inside twig in symfony2

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:

Upvotes: 7

Views: 14396

Answers (2)

Aize
Aize

Reputation: 546

{% trans% }app.name{% endtrans %}

In your messages.en.yml

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

In your messages.de.yml

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

Upvotes: -1

nucleartux
nucleartux

Reputation: 1390

With inline notation you should use filter:

{{ 'application.name'|trans }}

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

Upvotes: 25

Related Questions