【问题标题】:Handlebars.js & i18n-js, new helperHandlebars.js & i18n-js,新助手
【发布时间】: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


    【解决方案1】:

    我用 i18n-js 写了一个车把助手。这应该非常适合您的需求: https://stackoverflow.com/a/8796912/499700

    【讨论】:

      猜你喜欢
      • 2016-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多