Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js Handlebars globalization approach

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?

like image 878
thanikkal Avatar asked Dec 28 '22 05:12

thanikkal


2 Answers

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.

like image 82
randym Avatar answered Jan 03 '23 00:01

randym


Ember-I18n provides a solution: https://github.com/jamesarosen/ember-i18n

like image 42
ebryn Avatar answered Jan 02 '23 23:01

ebryn