I am looking for a good way to share my translations between my Symfony2 App and my Angular.JS App, they are essentially the same app, however they act very differently.
First of all I have made a directive to allow for templating using [[ variable ]] in my angular js app, so I can use the variables from twig alongside my variables in angular.
So what I want to achieve is to translate my sentences into the localisation that the user prefers.
So my conclusion is that I want to use the translations features of Symfony, as there is no good support for that in Angular. I also want to use all the built in features that Symfony includes, which is like update the files automatically, support YAML etc. But I need to work out how to transfer them to my JS application and how I can detect them in Symfony, so both applications can use them.
So my initial idea:
Change the capturing of translations or at least add an additional one to the scope.
{% trans %}Hello [[name]]{% endtrans %}
<trans name="My Name" translation="Hello [[name]]" />
And also support all other functionalities with pluralisation etc.
This would then generate a file that has the translations, and pluralisation etc.
Request language through angular ajax call and save this into a local storage on the client side.
This would allow me to replace the directive above of trans with the proper value. This is not a problem to set up. However it needs to be exported from whatever format to JSON that angular can read.
Then there needs to be a matcher, and there needs to be support for pluralisation and all other features available.
Other Ideas
It might be better in general to not use the Symfony2 translations when you do an Angular.JS App, and thereby only use the angular translations, otherwise the text written in Symfony2 Twigs and is translated would probably not be translatable in Angular. But the generation of these files I find it to be better if Symfony could capture and spit out.
I think this needs to be a bit of work to be solid, but I feel that this needs to be solved. Any ideas and helpful comments are appreciated, I am considering to start a project for this on GitHub, to give proper support for this. But if there's such already it might just be better to work with that.
/Marcus