-
Hey, my config: const backend = require("i18next-http-backend/cjs");
const { axios } = require("./lib/axios");
module.exports = {
debug: false,
i18n: {
locales: ["ar"],
defaultLocale: "ar"
},
use: [backend],
backend: {
loadPath: "{{lng}}|{{ns}}",
request: async (options, url, payload, callback) => {
try {
const [lng, ns] = url.split("|");
//it will logged for each namespace
console.log("ns", ns);
await axios
.get("/translations", {
params: { group: ns }
})
.then((response) => {
callback(null, {
data: response.data.data[lng][ns],
status: 200
});
})
.catch((error) => {
console.log(error.response);
});
} catch (e) {
callback(null, {
status: 500
});
}
}
},
reloadOnPrerender: true,
serializeConfig: false
}; my page: export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
return {
props: {
...(await serverSideTranslations(locale ?? i18nextConfig.i18n.defaultLocale, ["common", "titles"], i18nextConfig))
}
};
};
export default function Test() {
const { t } = useTranslation();
return (
<div>
{t("titles:blog")}
<Link href="/">{t("common:test")}</Link>
</div>
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 17 replies
-
For caching have a look at: https://www.i18next.com/how-to/caching#server-side-next.js-caching-with-filesystem |
Beta Was this translation helpful? Give feedback.
https://github.com/yaman3bd/local-test/pull/1/files
like here: https://github.com/locize/next-i18next-locize/tree/local-caching/next-i18next.config.js