nowiko
nowiko

Reputation: 2557

Load Symfony2 translations from custom directory

as we all know Symfony2 looks for translations in these directories:

YourBundle\Resources\translations\ - here lot of .yml files
app\Resources\translations\ - here lot of .yml files

But what if I want to put my translations into

MyBundle\Resources\translations\2015_04_23\ - and lot of .yml files will lay here

I read docs but didnt see solution, it is possible? Maybe I ommit part of doc? Can somebody help me? Thanks!

Upvotes: 6

Views: 1067

Answers (1)

Ilan Coulon
Ilan Coulon

Reputation: 1146

Indeed, it's documented here : http://symfony.com/doc/current/components/translation/custom_formats.html#components-translation-custom-loader

You do exactly the same as in the doc but when you use your translation loader, you add your translation by choosing yourself the directory :

$translator->addResource('my_format', __DIR__.'/translations/messages.txt', 'fr_FR');

(simply need to replace __DIR__ with your wisely chosen directory, try to be careful if you, for example, use dynamics files : you should use for example a service to be sure your code will be easily maintainable)

Upvotes: 1

Related Questions