Zwen2012
Zwen2012

Reputation: 3498

Symfony2: How to create own translation files?

I want to create my own translation file. For Example I want a "my-application.en_EN.yml" in my tranlsations folder in Ressources in my Bundle.

When I do this, the translation in my file does not work. Only when I name the file like the standard name "messages.en_EN.yml" then it works.

But how can I have my own namings?

Upvotes: 2

Views: 1113

Answers (1)

A.L
A.L

Reputation: 10493

messages.{language}.yml is the default name of translation files (in YML format), Symfony will load the translation file automatically and provide translations in all the contexts.

It's different if the translation file has a different name, in this case you have to add the first part of the file name (the translation domain) as an argument when translating a string:

In a Controller:

$this->get('translator')->trans('my.message', array(), 'my-application');

In a Twig template:

{{ 'my.message'|trans({}, 'my-application') }} 

See the official documentation for further information:

Upvotes: 6

Related Questions