1

如何在 i18n 键中使用动作助手。例如, i18n 键是

Please <a{{action displayList}}>click here</a> to display the list.

如何使用 ember 运行时正确翻译此内容(即车把未编译版本)

4

2 回答 2

1

自从提出这个问题以来已经有一段时间了,但是由于我在任何地方都没有找到解决方案,所以让我把我的解决方案放在这里。我解决它的方法是使用Handlebars subexpressions。对于您的示例,它看起来像这样:

在翻译文件中

var translations = {
    'fb.clickhere.msg': 'Please <a {{actionDisplayList}}>click here</a> to display the list.'
}

在车把模板中

{{t 'fb.clickhere.msg' actionDisplayList=(action "displayList") }}
于 2014-12-18T11:18:27.077 回答
0

如果 Handlebar 助手支持返回Ember.View实例,那么以下定义的助手应该可以工作

{{localizedView fb.clickhere.msg}}

Handlebars.registerBoundHelper("localizedView", function(value, options){
  // value = fb.clickhere.msg
  var localizedString = loc(value); // localizedString = "<a{{action displayList}}>click here</a>"
  return Ember.View.create({template: Ember.Handlebars.compile(localizedString)});
}) // Ofcourse you should define it before you can use this 
于 2013-05-29T11:19:01.503 回答