5

I have a multiple apps project looking like this

/apps/app1
/apps/app2
/apps/app3
/apps/config
/src
/vendor
/web/app1
/web/app2
/web/app3

Each app has its kernel, console, cache, ... But how do I share common translations ?

I read there https://stackoverflow.com/a/11630933/689429 that on a one-app structure, you can use app/Resources/translations. How about a multiples-apps structure ?

I wish I could make /apps/Resources/translations that would be autoloaded (or loaded manually) in all my apps but is it even possible ?

Community
  • 1
  • 1
MaximeBernard
  • 1,090
  • 1
  • 19
  • 33
  • 2
    Could you use symbolic links from /apps/Resources/translations to the individual apps/app1/Resources/translations directories? I know this isn't ideal... – redbirdo Jun 05 '13 at 13:43
  • Yes I could but it means there is no way to have app specific translations AND apps common translations. I will do this if I can't find other solutions. Thanks for the tip. – MaximeBernard Jun 05 '13 at 16:01

1 Answers1

4

Haven't tried it yet, but perhaps the following is possible:

Write and register an EventListener on kernel.request in one of your apps and inject the translator service in it, so you are able to modify it. Maybe it needs to be executed before the LocaleListener which means it has to have a priority higher than 16 to be executed before.

Then in the onKernelRequest() method of your event listener, you could then call the Symfony\Component\Translation\Translator::addResource() method to add translation files on the fly.

See: http://api.symfony.com/2.3/Symfony/Component/Translation/Translator.html#method_addResource

The parameter $resource contains the path to your global translation files.

(What you are trying to do really is an edge case, but there has to be some method to do it without symlinking everything.)

Hope this thought helps. I'll try it out as soon as possible and post my results and how I've done it.

thormeier
  • 672
  • 9
  • 25
  • Thanks for this answer! I'll try it out asap. Theoretically, it should work. I'll set this answer as "accepted" as soon as I have my results. – MaximeBernard Jun 26 '13 at 14:24
  • Thank you for your feedback! Note that you perhaps have to register this event listener in all your apps anyway since those event listeners theoretically only work on requests in the app they're registered in, but at least your translation files will be centralized. As I said, I'll try it out as well myself because this really is an interesting use case you're having. If you're sucessful, could you provide your solution? – thormeier Jun 26 '13 at 16:06