UNPKG

remix-i18next

Version:

The easiest way to translate your Full Stack React Router apps

23 lines 978 B
import { createInstance } from "i18next"; import { createContext } from "react-router"; import { LanguageDetector } from "./lib/language-detector.js"; export function createI18nextMiddleware({ detection, i18next = {}, plugins = [], }) { let localeContext = createContext(); let i18nextContext = createContext(); let languageDetector = new LanguageDetector(detection); return [ async function i18nextMiddleware(args, next) { let lng = await languageDetector.detect(args); args.context.set(localeContext, lng); let instance = createInstance(i18next); for (const plugin of plugins ?? []) instance.use(plugin); await instance.init({ lng }); args.context.set(i18nextContext, instance); return await next(); }, (context) => context.get(localeContext), (context) => context.get(i18nextContext), ]; } //# sourceMappingURL=index.js.map