import i18n from "i18next"; import { initReactI18next } from "react-i18next"; import en from "./en.json"; import id from "./id.json"; const fallbackLng = "en"; i18n .use(initReactI18next) .init({ resources: { en: { translation: en }, id: { translation: id }, }, fallbackLng, debug: true, interpolation: { escapeValue: false, // not needed for react as it escapes by default }, lng: localStorage.getItem("language") || fallbackLng, }); // Set up an event listener to update the language in localStorage whenever the language is changed i18n.on("languageChanged", (lng) => { localStorage.setItem("language", lng); }); export default i18n;