-
| 
         Hey, console.log("Namespaces API:", req.query.ns)but when I remove  const ChainedBackend = require("i18next-chained-backend/dist/cjs/i18nextChainedBackend.js");
const FSBackend = require("i18next-fs-backend/cjs");
const HttpBackend = require("i18next-http-backend/cjs");
const MultiloadAdapter = require("i18next-multiload-backend-adapter/cjs");
const backendOptions = require("./backendOptions");
module.exports = {
    i18n: {
        locales: ["en"],
        defaultLocale: "en"
    },
    use: [MultiloadAdapter, ChainedBackend],
    ns: ["auth", "otp", "common", "validation"],
    preload: ["en"],
    defaultNS: "common",
    backend: {
        backends: [FSBackend, HttpBackend],
        backendOptions
    },
    maxParallelReads: 50,
    serializeConfig: false
};
 const axios = require("axios");
module.exports = [
    {
        loadPath: "./public/locales_cache/{{lng}}/{{ns}}.json",
        addPath: "./public/locales_cache/{{lng}}/{{ns}}.json",
        expirationTime: 60 * 60 * 1000
    },
    {
        loadPath: "{{lng}}|{{ns}}",
        request: async (options, url, payload, callback) => {
            try {
                const [lng, ns] = url.split("|");
                await axios
                    .get("http://localhost:3001/api/translations", {
                        params: { lng, ns }
                    })
                    .then((response) => {
                        const lngs = lng.split("+");
                        const nss = ns.split("+");
                        for (const $lng of lngs) {
                            for (const $ns of nss) {
                                if (response.data.data[$lng][$ns]) {
                                    // eslint-disable-next-line no-console
                                    console.log("response data: ", response.data.data[$lng][$ns]);
                                    callback(null, {
                                        data: response.data.data[$lng][$ns],
                                        status: 200
                                    });
                                }
                            }
                        }
                    })
                    .catch((error) => {
                        // eslint-disable-next-line no-console
                        console.log("response error: ", error.response.data);
                        callback(null, {
                            status: 500
                        });
                    });
            } catch (e) {
                // eslint-disable-next-line no-console
                console.log("catch error: ", e);
                callback(null, {
                    status: 500
                });
            }
        }
    }
];I thought  changing  the order of  backends: [HttpBackend, FSBackend],and  use: [MultiloadAdapter, ChainedBackend],but unfortunately, it did not Can anyone help me figure out what I am doing wrong or what is missing in my config? Thanks!  | 
  
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
| 
         Sorry, but I don't understand what your goal should be. Some stuff I notice: 
 also have a look at: i18next/i18next-http-backend#114 and i18next/i18next-http-backend#117  | 
  
Beta Was this translation helpful? Give feedback.


ok, a config like this should work: https://github.com/i18next/i18next-multiload-backend-adapter/blob/master/examples/caching/app.js#L38
This means your config would probably look like this: