Loading...
Loading...
Internationalization best practices for React Router framework mode using remix-i18next. Use when setting up locales, middleware, resource routes, or language switching.
npx skill4agent add sergiodxa/agent-skills frontend-internationalization-best-practicesremix-i18nextremix-i18next/api/localescreateI18nextMiddlewareexport const [i18nextMiddleware, getLocale, getInstance] =
createI18nextMiddleware({
detection: {
supportedLanguages: ["es", "en"],
fallbackLanguage: "en",
cookie: localeCookie,
},
i18next: { resources },
plugins: [initReactI18next],
});// app/locales/en/translation.ts
export default { title: "Example" };// Large app: common + route namespaces
export default { common, home, notFound };export const [i18nextMiddleware, getLocale] = createI18nextMiddleware({
detection: { cookie: localeCookie, fallbackLanguage: "en" },
});return data(
{ locale },
{ headers: { "Set-Cookie": await localeCookie.serialize(locale) } },
);<html lang dir>export async function loader({ context }: Route.LoaderArgs) {
let locale = getLocale(context);
return data(
{ locale },
{ headers: { "Set-Cookie": await localeCookie.serialize(locale) } },
);
}htmlTagi18next.init({ detection: { order: ["htmlTag"], caches: [] } });I18nextProvider<I18nextProvider i18n={getInstance(routerContext)}>
<ServerRouter context={entryContext} url={request.url} />
</I18nextProvider>/api/locales/:lng/:nsreturn data(namespaces[ns.data], { headers });t()useTranslationlet t = getInstance(context).getFixedT(locale);