i18next-http-backend
i18next-http-backend copied to clipboard
backend request doesn't work
i18next::translator: missingKey en translation K1 K1
` 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 (