问题描述
我正在尝试使用ember.js/emblem.js编写登录表单.一切正常,除非我尝试像这样对占位符进行修饰:
I'm trying to write a login form with ember.js/emblem.js. Everything works, unless I try I18ning the placeholders like so:
Em.TextField valueBinding="view.username" placeholder="#{t 'users.attributes.username}"
Em.TextField valueBinding="view.password" placeholder="#{t 'users.attributes.password'}" type="password"
如果尝试,我会得到相同的答复:
I get the same response if I try:
= input value=view.username placeholder="#{t 'users.attributes.username}"
= input value=view.password placeholder="#{t 'users.attributes.password'}" type="password"
在两种情况下,我都会收到此错误消息:
In both cases, I get this error message:
Pre compilation failed for: form
. . . .
Compiler said: Error: Emblem syntax error, line 2: Expected BeginStatement or DEDENT but "\uEFEF" found. Em.TextField valueBinding="view.username" placeholder="#{t 'users.attributes.username}"
我认为这是因为我正在尝试从已经被编译的语句中编译某些东西.作为证明,如果将代码更改为以下内容,则不会出现运行时错误:
I assume this is happening because I'm trying to compile something from within a statement that's already being compiled. In evidence of this, I don't get the runtime error if I change the code to:
input value=view.username placeholder="#{t 'users.attributes.username}"
input value=view.password placeholder="#{t 'users.attributes.password'}" type="password"
但是缺点是值绑定不再起作用,这仍然使表格无法使用.有没有解决我未曾考虑过的问题的另一种方法?
But the downside is that the value bindings no longer work, which still leaves the form nonoperational. Is there another way of approaching this problem that I haven't considered?
推荐答案
正如亚历山大指出,这是Ember和Handlebars的局限.我一直在使用的解决方法是使placeholder
引用一个控制器属性,然后该属性返回转换后的字符串.例如:
As Alexander pointed out, this is a limitation of Ember and Handlebars. The workaround that I've been using is to make the placeholder
refer to a controller property which then returns the translated string. For example:
{{input
type="text"
value=controller.filterText
placeholder=controller.filterPlaceholder }}
然后在控制器中:
filterPlaceholder: function () {
return i18n.t('players.filter');
}.property('model.name'),
这篇关于使用Emblem.js将翻译插入占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!