简体   繁体   中英

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?

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.

Ember-I18n提供了一个解决方案: https//github.com/jamesarosen/ember-i18n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM