I am using ember-cli-i18n
in an ember-cli
app..
我在ember-cli app中使用ember-cli-i18n ..
I have property menuItems
which returns..
我有属性menuItems返回..
[{
text: 'leftnav_nonfollower',
route: 'nonFollowers'
}, {
text: 'leftnav_nonfans',
route: 'fans'
}]
In template i use menuItems
as ..
在模板中我使用menuItems作为..
{{#each menuItem in navItems}}
<li {{action 'changeRoute' menuItem }} >
<a href="#" class='nav-circle'>
{{t menuItem.text}}
</a>
</li>
{{/each}}
Now instead of looking for translation for leftnav_nonfollower
.. the library utility t()
is actually instead looking for translation of string menuItem.text
.. thus giving error Assertion Failed: Missing translation for key "menuItem.text".
现在,而不是为leftnav_nonfollower寻找翻译..库实用程序t()实际上是在寻找字符串menuItem.text的翻译。因此给出错误断言失败:缺少关键字“menuItem.text”的翻译。
1 个解决方案
#1
1
t
is automatically injected into Controllers, Components, Routes, and Models.
t自动注入控制器,组件,路径和模型。
source: https://github.com/dockyard/ember-cli-i18n#utility
来源:https://github.com/dockyard/ember-cli-i18n#utility
So, Instead of doing it in your template why don't you do it when forming the array. Something like this:
所以,不要在你的模板中这样做,为什么不在形成数组时这样做呢。像这样的东西:
var menu = [{
text: 'leftnav_nonfollower',
route: 'nonFollowers'
}, {
text: 'leftnav_nonfans',
route: 'fans'
}]
menu = menu.map(function(item) {
item.text = this.t(item.text);
return item;
});
this will give you translated text in the key which you can directly use in your template.
这将为您提供可在模板中直接使用的密钥中的翻译文本。
#1
1
t
is automatically injected into Controllers, Components, Routes, and Models.
t自动注入控制器,组件,路径和模型。
source: https://github.com/dockyard/ember-cli-i18n#utility
来源:https://github.com/dockyard/ember-cli-i18n#utility
So, Instead of doing it in your template why don't you do it when forming the array. Something like this:
所以,不要在你的模板中这样做,为什么不在形成数组时这样做呢。像这样的东西:
var menu = [{
text: 'leftnav_nonfollower',
route: 'nonFollowers'
}, {
text: 'leftnav_nonfans',
route: 'fans'
}]
menu = menu.map(function(item) {
item.text = this.t(item.text);
return item;
});
this will give you translated text in the key which you can directly use in your template.
这将为您提供可在模板中直接使用的密钥中的翻译文本。