我对i18next很陌生。
我正在尝试从服务端点使用翻译文件,它返回json(通过浏览器/邮递员)。
{
"hello": "hello EN",
"stringInt": "hello{{string}} EN",
"currency": "€",
"selectYourLanguage": "Select your language"
}
但是,我的应用正确使用了它们,
i18next::translator: missingKey undefined translation hello hello
在chrome调试工具上检查网络时,它还会显示“无法加载响应数据”
这是我的i18next.ts
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import Backend from "i18next-http-backend";
// not like to use this?
// have a look at the Quick start guide
// for passing in lng and translations on init
i18n
// load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales)
// learn more: https://github.com/i18next/i18next-http-backend
.use(Backend)
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
fallbackLng: "en-us",
debug: true,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
backend: {
loadPath:
"http://desktop-s6c8fgn:8597/localization/{{lng}}/{{ns}}.json",
requestOptions: {
// used for fetch, can also be a function (payload) => ({ method: 'GET' })
mode: "no-cors",
},
},
});
export default i18n;