i18n.t无法在ReactJS中解析正确的值

时间:2018-05-10 16:36:39

标签: javascript reactjs internationalization

名为navigations.json的JSON文件:

{
"sidenav.dashboard": "Dashboard",
"sidenav.profile": "Profile",
"sidenav.account": "Account",
}

在JS文件中使用:

import i18n from '../../../i18n'

export const driverItems = [
{
  link: '#',
  icon: <Edit stroke="#ffffff" />,
  text: i18n.t('navigations:sidenav.dashboard'),
  open: false
},
{
  link: '#',
  icon: <Edit stroke="#ffffff" />,
  text: i18n.t('navigations:sidenav.profile'),
  open: false
},
{
  link: '#',
  icon: <Edit stroke="#ffffff" />,
  text: i18n.t('navigations:sidenav.account'),
  open: false
}
]

然后在React组件中循环对象数组:

  import { ownerItems, driverItems } from './linksList'

  // then looping...

  const items = this.state.linksOwnerList.map((item, index) => {
    if (Array.isArray(item.submenus)) {
      return (
        ....

结果是 Result

有什么想法吗?

0 个答案:

没有答案