i18next-http-backend icon indicating copy to clipboard operation
i18next-http-backend copied to clipboard

backend request doesn't work

Open xian107 opened this issue 1 month ago • 5 comments

i18next::translator: missingKey en translation K1 K1 image

` import i18next from "i18next"; import { initReactI18next } from "react-i18next"; import LanguageDetector from "i18next-browser-languagedetector"; import backend from "i18next-http-backend"; import axios from "axios"; i18next .use(LanguageDetector) .use(initReactI18next) .use(backend) .init( { backend: { //loadPath: "https:/xxx.json", request: async (options, url, payload, callback) => { const result = await axios.get("https:/xxx.json") if (result.status === 200 && result.data) { callback(null, { status: 200, data: { en: { translation: { 'K1': "YES" } }, zh: { translation: { 'K1': "是" } //translation: result.data["CN"], }, }, }); }

            },
        },
        fallbackLng: "en",
        lng: "en",
        debug: true,
        ns: ['translation'],
        defaultNS: 'translation',
        interpolation: {
            escapeValue: false, // not needed for react!!
        },
    },
    (err, t) => {
        if (err) {
            console.error("i18next error:", err);
        } else {
            console.log("i18 success");
        }
    }
);

export default i18next `

page

` import {useTranslation} from 'react-i18next';

export default function Home() { const {t} = useTranslation(); return (

{t("K1")}
) } ` The page shows K1,doesn't work。i18next::translator: missingKey en translation K1 K1

xian107 avatar May 28 '24 06:05 xian107