i18next 解析语言环境翻译失败

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

部署 React App 时 i18n 在 console.log 中给出错误:

i18next::backendConnector: loading namespace translation for language EN failed failed parsing locales/EN/translation.json to json

JSON的格式是正确的,我查过了

在开发服务器上,一切正常,但在生产中,出现错误。

我试过更改配置中的路径,但这没有帮助。 这是 i18n congig:

import i18n from 'i18next';
import Backend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import {initReactI18next} from 'react-i18next';

i18n
    .use(Backend)
    .use(LanguageDetector)
    .use(initReactI18next)
    .init({
        debug: true,
        fallbackLng: 'ru',
        interpolation: {
            escapeValue: false,
        },
        backend: {
            loadPath: 'locales/{{lng}}/{{ns}}.json'
        }
    });

export default i18n;

这是 index.js 文件:

import React from 'react';
import ReactDOM from 'react-dom/client';

import './i18n';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
    <React.StrictMode>
        <App/>
    </React.StrictMode>
);

我的构建文件夹结构:

build
│   
│
└─── locales   
│    │   
│    └─── en   
│    │    └───translation.json
│    │   
│    └─── de   
│         └───translation.json
│
│
└─── static
│     │   
│     │
│     └─── js
│          └─── main.js
│
│     │
│     └─── media
│          └─── ...files
│
│
└─── asset-manifest.json
│
└─── favicon.ico
│
└─── index.html

Google 也帮不了我。 可能是什么问题?

感谢提前。

javascript reactjs i18next react-i18next
© www.soinside.com 2019 - 2024. All rights reserved.