i18next with axios backend in react

1k Views Asked by At

I'm trying to implement language change in my app using these dependencies:

"i18next": "^21.6.13",
"i18next-browser-languagedetector": "^6.1.3",
"i18next-http-backend": "^1.3.2",
"react-i18next": "^11.15.6",

I tried pretty standard method and it works fine:

import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import { DateTime } from "luxon";
import Backend from "i18next-http-backend";

i18n
  .use(Backend)
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    debug: true,
    fallbackLng: "en",
    interpolation: {
      escapeValue: false,
      format: (value, format, lng) => {
        if (value instanceof Date) {
          return DateTime.fromJSDate(value)
            .setLocale(lng)
            .toLocaleString(DateTime[format]);
        }
        return value;
      },
    },
  });

export default i18n;

What i need to do is to get translations from backend with axios. I tried to do this https://github.com/i18next/i18next-http-backend , but all examples are with local json data and this is not what i want to do. I tried to hook data and pass it in resources, but it dosen't work. Any thoughts of how it could be done? Or helpful links? It doesn't have to be with axios. What i have is accessive link with json data and I want to use it as backend with i18next. Any help would be much appreciated, thanks. P.S. please don't ban if question is not clear enough, I'll try to explain better if needed. I'm tired.

0

There are 0 best solutions below