Ember.js Handlebars globalization approach
-
26-10-2019 - |
Question
I am trying to use ember.js in my Rails app.
Have a question specific to globalizing the handlerbars view template content.
Should I try to create myview.handlebars.erb and get the strings translated on the server side (havent tried this) or should I create seperate handlebars templates per each language (doesnt sound like really DRY unless there is a cleaner way)?
Whats the ideal way to go about it?
Solution
Ember-I18n provides a solution: https://github.com/jamesarosen/ember-i18n
OTHER TIPS
Did you get this working to your satisfactioin?
Another alternative (what we use at http://travis-ci.org) is i18n-js. We like it because it lets you keep all your localizations in the same place (config/locales/[x].yml) and automatically adds them into your assets path.
Part of that DRY thing ;)
The syntax in your handlebars is pretty much the same, we just us a handlebars helper
Handlebars.registerHelper('i18n', function(key) {
return new Handlebars.SafeString(I18n.t(key))
});
and then {{i18n "path.to.translation"}} in the handlebars view.