We use Symfony for a lot of our projects and often Angular if a significant amount of JavaScript is required.

One problem this can present is how to neatly handle translations. Each has their own way of handling translations, but ideally we want to manage translations in a single place.

We dealt with this by handling all our translations within the Symfony app and using the excellent BazingaJsTranslationBundle to expose these translations to our JavaScript. The missing piece of the puzzle was accessing these in a neat way within our Angular app (including view partials).

So we wrote an Angular module that provides functionality to access translations exposed via BazingaJS. The benefits and key points of this are:

  • Works with both 1.x and 2.x versions of the BazingaJSTranslationBundle
  • Provides trans and transChoice filters with the same method signatures as the methods provided by the BazingaJS bundle
  • Uses an adapter so you can use 2.x syntax regardless of whether you’re using 1.x or 2.x
The Angular module is open source with an MIT license, and is easily installable using npm or bower.

Further instructions on how to use the module can be seen on the README for the project:

About the author

Ian Jenkins

Ian Jenkins

Ian Jenkins is a Principal Developer at Box UK. Ian works mostly with PHP, but loves trying out new things. When not sat in front of a computer, he likes to read, watch films and follow sport. Ian thinks he is the only blog contributor who does not play the guitar.

Related content

We're hiring. Let's talk. View available roles