我在 i18next 中遇到问题,文本无法从 json 数据显示

问题描述 投票:0回答:2

我尝试了不止一种方法,但没有用,我不知道! 像我写的那样显示的文本不是来自 json 文件。 我做了不止一次,以确保我没有任何错误。 所以如果您知道问题是什么,请告诉我。

[text i want to show how it show

注意:我在文件和index.js文件中尝试了i18n,但两者都不起作用 我希望你能找到错误。感谢大家尝试帮助

错误类型是:

i18next.js:27 i18next::backendConnector: loading namespace common for language en failed failed parsing ../public/assets/i18n/common/en.json to json

i18next.js:27 i18next::backendConnector: loading namespace about for language en failed failed parsing ../public/assets/i18n/about/en.json to json
i18next::translator: missingKey en home home home
javascript reactjs i18next react-i18next
2个回答
0
投票

您的 json 文件似乎不是有效的 json 格式。 末尾可能有一些额外的逗号(,)或类似的...... 验证您的 json 文件。

例如将 json 内容放在这里并检查是否有错误:https://jsonlint.com/


0
投票

您没有添加

resources
属性

import { en } from './en.json'

.
.
.

    resources: {
      en:en,
    },

backendOptions: [
        {
          loadPath: '/locales/{{lng}}/{{ns}}.json',
        },
      ],
© www.soinside.com 2019 - 2024. All rights reserved.