我是 i18next 的新手,正在尝试本地化/翻译网站。一切都适用于组件内部的翻译,但在外部(意味着带有 i18n.t() 的 json 文件它不会检索所需的信息,而是显示默认值。
我正在使用 create-react-app 并且它是文件夹引用的默认设置,也许这是关键问题,但我不知道为什么以及要更改什么。
import i18n from '../../i18n';
const navigation = [
{
'id' : 'dashboard',
'title' : i18n.t('analytics.title', 'NOT FOUND'),
'type' : 'group',
'icon' : 'apps',
}
]
export default navigation;
Run Code Online (Sandbox Code Playgroud)
这是 i18n.js 文件的设置:
import i18n from "i18next";
import Backend from 'i18next-xhr-backend';
import { initReactI18next } from 'react-i18next';
import detector from "i18next-browser-languagedetector";
i18n
.use(detector)
.use(Backend)
.use(initReactI18next)
.init({
lng: localStorage.getItem('language') || 'en',
backend: {
/* translation file path */
loadPath: '/assets/i18n/{{ns}}/{{lng}}.json'
},
fallbackLng: ['en', …Run Code Online (Sandbox Code Playgroud)