如果我使用内置于helper input中的input
{{input value=query class="form-input" placeholder="Search"}}我想用该字符串的翻译版本替换占位符字符串"Search“。
通常,如果我还没有使用input助手,我会像这样访问已翻译的字符串:
{{ t "home.search" }}发布于 2014-05-12 03:54:53
通过使用子表达式:http://handlebarsjs.com/expressions.html解决了这个问题
{{input value=query class="form-input" placeholder=(t "home.search") }}发布于 2014-06-27 01:07:18
我无法让dylanjha的解决方案起作用,因为Ember.I18n的t助手返回包装在翻译文本周围的span,而不是翻译文本本身。我通过编写自己的助手直接调用翻译来解决这个问题:
Ember.Handlebars.registerHelper('ts', function (key) {
return Em.I18n.t(key);
});然后我就能像这样使用我的助手了:
{{input value=login placeholder=(ts 'signin.login') }}发布于 2014-05-12 11:06:21
我在我的应用程序中使用这个:
// This is a custom text field that allows i18n placeholders
App.TextField = Ember.TextField.extend({
attributeBindings: ['autofocus', 'z-index', 'autocomplete'],
placeholder: function () {
if (this.get('placeholderKey')) {
return I18n.t(this.get('placeholderKey'));
} else {
return ''; //or this.get('placeholder')
}
}.property('placeholderKey')
});https://stackoverflow.com/questions/23600717
复制相似问题