【发布时间】:2012-01-06 10:14:38
【问题描述】:
我想在客户端使用 Handlebars 和 Ruby 的 i18n-js gem(在 Rails 3 应用程序上)翻译我的 i18n 键。根据您的说法,这样的 Handlebars 助手可能是什么?
根据当前的 Handlebars 版本,默认的助手看起来像:
Handlebars.registerHelper('if', function(context, options) {
var type = toString.call(context);
if(type === functionType) { context = context.call(this); }
if(!context || Handlebars.Utils.isEmpty(context)) {
return options.inverse(this);
} else {
return options.fn(this);
}
});
Handlebars.registerHelper('unless', function(context, options) {
var fn = options.fn, inverse = options.inverse;
options.fn = inverse;
options.inverse = fn;
return Handlebars.helpers['if'].call(this, context, options);
});
Handlebars.registerHelper('with', function(context, options) {
return options.fn(context);
});
Handlebars.registerHelper('log', function(context) {
Handlebars.log(context);
});
关于 i18n-js gem,它似乎是一个不错的组合。这个库例如在 Ember.js 中使用(作为 ember-i18n)。是否已有关于 Handlebars.js 和 i18n 的最佳实践?
感谢您的任何建议。
【问题讨论】:
标签: ruby-on-rails internationalization javascript handlebars.js