简体   繁体   English

i18n转换不适用于ember-断言失败:密钥缺少翻译

[英]i18n translation not working with ember - Assertion Failed: Missing translation for key

I am using ember-cli-i18n in an ember-cli app.. 我在ember-cli应用程式中使用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". 现在,库实用程序t()不再寻找leftnav_nonfollower翻译,而是寻找字符串menuItem.text ..的翻译,因此给出错误Assertion Failed: Missing translation for key "menuItem.text".

t is automatically injected into Controllers, Components, Routes, and Models. t会自动注入到Controllers,Components,Routes和Models中。

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. 这将为您提供可以直接在模板中使用的密钥中的翻译文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM