remix-i18next
Version:
The easiest way to translate your Full Stack React Router apps
23 lines • 1.03 kB
JavaScript
import { createInstance } from "i18next";
import { unstable_createContext } from "react-router";
import { LanguageDetector } from "./lib/language-detector.js";
export function unstable_createI18nextMiddleware({ detection, i18next = {}, plugins = [], }) {
let localeContext = unstable_createContext();
let i18nextContext = unstable_createContext();
let languageDetector = new LanguageDetector(detection);
return [
async function i18nextMiddleware({ request, context }, next) {
let lng = await languageDetector.detect(request);
context.set(localeContext, lng);
let instance = createInstance(i18next);
for (const plugin of plugins ?? [])
instance.use(plugin);
await instance.init({ lng });
context.set(i18nextContext, instance);
return await next();
},
(context) => context.get(localeContext),
(context) => context.get(i18nextContext),
];
}
//# sourceMappingURL=middleware.js.map