I m working on a Grails / Backbone / Handlebars application that s a front end to a much larger legacy Java system in which (for historical & customizability reasons) internationalization messages are deep in a database hidden behind a couple of SOAP services which are in turn hidden behind various internal Java libraries. Getting at these messages from the Grails layer is easy and works fine.
What I m wondering, though, is how to get (for instance) internationalized labels into my Handlebars templates.
Right now, I m using GSP fragments to generate the templates, including a custom tag that gets the message I m interested in, something like:
<li><myTags:message msgKey="title"/> {{title}}</li>
https://github.com/fnando/i18n-js https://github.com/fnando/i18n-js
So far the best thing I can think of is to wedge the labels into the Backbone model as well, so I d end up with something like
<li>{{titleLabel}} {{title}}</li>
However, this really gets away from the ideal of building the Backbone models on top of a nice clean RESTful JSON API -- either the JSON returned by the RESTful service is cluttered up with presentation data (i.e., localized labels), or I have to do additional work to inject the labels into the Backbone model -- and cluttering up the Backbone model with presentation data seems wrong as well.
I think what I d like to do, in terms of clean data and clean APIs, is write another RESTful service that takes a list of message keys and similar, and returns a JSON data structure containing all the localized messages. However, questions remain:
- What s the best way to indicate (probably in the template) what message keys are needed for a given view?
- What s the right format for the data?
- How do I get the localized messages into the Backbone views?
- Are there any existing Javascript libraries that will help, or should I just start making stuff up?
- Is there a better / more standard alternative approach?