我尝试了不止一种方法,但没有用,我不知道! 像我写的那样显示的文本不是来自 json 文件。 我做了不止一次,以确保我没有任何错误。 所以如果您知道问题是什么,请告诉我。
注意:我在文件和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
您的 json 文件似乎不是有效的 json 格式。 末尾可能有一些额外的逗号(,)或类似的...... 验证您的 json 文件。
例如将 json 内容放在这里并检查是否有错误:https://jsonlint.com/
您没有添加
resources
属性
import { en } from './en.json'
.
.
.
resources: {
en:en,
},
和
backendOptions: [
{
loadPath: '/locales/{{lng}}/{{ns}}.json',
},
],