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 is a Principal Developer at Box UK. He has wide range of development experience in various platforms and languages, in particular PHP and Symfony. Ian has worked on and delivered a number of successful projects and is currently most interested in maintaining and transforming troublesome legacy projects into well-tested, high-performance web applications.