Y H*_*H R 1 arrays json i18next reactjs react-i18next
上下文:react-i18next我正在使用ReactJS 模块制作一个多语言页面。
问题:我无法访问排列的 JSON 内容。
翻译的内容存储在每种语言的单独 JSON 文件中,非数组内容工作正常并正确显示和翻译,但是,我似乎无法在 React 组件上使用数组内容,更不用说通过console.log().
以下是我的文件的示例translationEN.json:
{
"name": "Test",
"occupations":["occupation1",
"Part-time occupation2",
"Language enthusiast"]
}
Run Code Online (Sandbox Code Playgroud)
我可以name使用 来引用非数组i18n.t("name")。但是,尝试访问我的 arrayed occupationsusingi18n.t("occupations")结果会出现在以下 console.log 中:
key 'occupations (en)' returned an object instead of string.
使用JSON.stringify()并不能解决问题,也不能console.log(i18n.t("occupations"), { returnObjects: true })按照i18next 文档中的建议解决问题
提前致谢!
问题解决了。数组值可以这样访问:i18n.t("occupations.0")for occupation 1、i18n.t("occupations.1")forPart-time occupation 2和i18n.t("occupations.2")for Language enthusiast。我只需要把它循环起来,让它看起来更干净。
| 归档时间: |
|
| 查看次数: |
2034 次 |
| 最近记录: |