2

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?

A.L
  • 10,259
  • 10
  • 67
  • 98
Zwen2012
  • 3,360
  • 9
  • 40
  • 67

1 Answers1

6

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:

A.L
  • 10,259
  • 10
  • 67
  • 98