Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

i18next-http-backend not working on production

I am using i18next for transalation with i18next-http-backend to get the translation files. My codes works on development but not on production, it’s a vite application.
i have tried a couple of suggestion by using different i18next-http-backend version like the v1.2.4 but still same as suggested here link

The debug is showing
debug

My config file

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import backend from "i18next-http-backend";

i18n
  .use(initReactI18next)
  .use(backend)
  .init({
    fallbackLng: "en",
    lng: "en",
    backend: {
      loadPath: "src/i18n/locales/{{lng}}.json",
      addPath: "src/i18n/locales/add/{{lng}}",
    },
    interpolation: { escapeValue: false },
    debug: true,
  });

export default i18n;
function App() {
  return (
    <Suspense fallback={<Spinner/>}>
      <Routes>
        <Route path="/" element={<LandingPage />} />
       
      </Routes>
    </Suspense>
  );
}

export default App;

>Solution :

Check routes of your translations files. You have 404 eroror in console. Use public folder.

Files should be at public/src/i18n/locales/{{lng}}.json

and public/src/i18n/locales/add/{{lng}}.json

But maybe will be correctly to change it to public/i18n/locales/{{lng}}.json.

Config will be:

loadPath: "i18n/locales/{{lng}}.json",
addPath: "i18n/locales/add/{{lng}}",

https://react.i18next.com/legacy-v9/step-by-step-guide#a-add-an-additional-language-file

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading