小编Why*_*his的帖子

使用 react-i18next useTranslationHooks 时出现“i18next backendConnector:加载命名空间失败”

我正在尝试使用 useTranslation() 挂钩在我的 create-react-app 应用程序上实现 react-i18next。

但是,在控制台中,调试模式显示

i18next::backendConnector: 为语言加载命名空间 billingAddress 失败,将 /locales/en/billingAddress.json 解析为 json

i18next::translator: missingKey en billingAddress Form.email 客户电子邮件(默认)

i18next.ts

import {initReactI18next} from "react-i18next";
import i18next from "i18next";
import LanguageDetector from 'i18next-browser-languagedetector';
import Backend from 'i18next-xhr-backend';
import XHR from "i18next-xhr-backend";

i18next
// .use(Backend)
    .use(LanguageDetector)
    .use(XHR)
    .use(initReactI18next) // passes i18n down to react-i18next
    .init({
        lng: "en",
        fallbackLng: {
            'en-US':['en'],
            'zh-CN':['cn'],
            default:['en']
        },
        debug: true,
        ns: ['billingAddress'],
        defaultNS: 'billingAddress',
        // load: "currentOnly",
        interpolation: {
            escapeValue: false // react already safes …
Run Code Online (Sandbox Code Playgroud)

typescript i18next reactjs react-i18next react-hooks

6
推荐指数
1
解决办法
5832
查看次数