Play Framework 2.0.x JavaScript Internationalization

Play framework provides a very neat way of producing internationalized sites using the Messages plugin, but, it only supports native (Scala/Java) code or HTML templates, this means that JavaScript code can't be made i18n compliant.

Since this was getting on my nerves I started looking into alternatives for JavaScript i18n support. My first try was with i18next but the JSON file format used wasn't something that fit with us since we already have all our i18n text in standard Play form: in conf/messages.xx

Luckily, the jquery-i18n-properties jQuery plugin uses standard Java properties file format and that's what we're going to use here.

So, first of all, download the plugin and add it to your HTML template (right below jquery) and use the following code:

With this the plugin get's loaded and an alert is loaded to test everything works ok. Next, create a controller like:

Basically what we're doing here is providing a path to the plugin and using the standard Play language implementation, load the messages file and return it as plain text.