React Router i18n · Framework Mode
React Router i18n for Framework Mode.
Palamedes connects React Router 8 loaders, actions, SSR, and hydrated React components to one translation runtime. The Vite plugin compiles messages; one root middleware activates the request's catalog for every loader, action, and render.
Palamedes 2.0 is out. Read the release notes.
- Mode
- Framework
- Verified against
- React Router 8.5
- Integration
- @palamedes/react-router
- Locale models
- 4 examples
Type-safe route modules, loaders, actions, and SSR.
React 19 and the React Router Vite plugin.
Root middleware and server entry beside the Vite plugin.
Cookie, route, subdomain, and top-level domain.
@palamedes/react-routerv2.2.0827 downloads / month01 — The framework problem
The locale has to be route data, server state, and client state at the right times.
Framework Mode spans the initial server render and later browser navigations. A translated route must activate its locale before loader or action macros run, then hydrate React with the same catalog.
02 — The Palamedes model
Use route modules for policy and Palamedes for the translation lifecycle.
React Router continues to own matching, redirects, data loading, and mutations. Palamedes supplies transformed authoring, catalogs, request activation, and client synchronization around those APIs.
Compose two Vite plugins
The Palamedes plugin runs beside the React Router plugin, so macros and the configured PO catalogs compile into normal modules in the Framework Mode build.
Activate once, in root middleware
React Router 8 route middleware wraps every loader, action, data request, and document render. The adapter's middleware resolves the app's locale policy and activates the server runtime before translated code runs.
Hydrate from root locale data
The root loader exposes the document locale. The adapter's server entry adds that locale's catalog import map, so compiled messages load before hydration and before lazy route modules run; the client entry hydrates React normally.
03 — In TypeScript
The app owns the locale policy; the adapter owns the request scope.
lib/i18n.server.ts + root.tsx + entry.server.tsx + routes/locale-home.tsx
// app/lib/i18n.server.ts
import { createReactRouterI18n } from "@palamedes/react-router"
import { resolveLocaleFromRequest } from "./i18n"
export const i18n = createReactRouterI18n({
resolveLocale: resolveLocaleFromRequest,
i18nOptions: { timeZone: "Europe/Berlin" },
})
// app/root.tsx
export const middleware = [i18n.middleware]
// app/entry.server.tsx
export default i18n.handleRequest
// app/routes/locale-home.tsx
export async function action({ params }: Route.ActionArgs) {
const locale = normalizeLocale(params.locale)
return { message: t`Server action confirmed locale ${locale}.` }
}Loaders and actions need no wrapper: the root middleware gives each request its own i18n instance over a shared server catalog. The server entry injects the locale's catalog import map; the client entry calls HydratedRouter without an application-owned catalog loader.
04 — Locale strategy
Choose the URL model that fits your React Router product.
React Router route modules own params, requests, redirects, and links. Palamedes keeps the catalog and component model identical while the four examples change how those route modules derive a locale.
Cookie
One URL for all locales. Useful for signed-in apps; an explicit language choice is persisted and opens a new document in that locale.
Route segment
/de/checkout-style paths. The SEO-friendly default for public content with indexable localized pages.
Subdomain
de.example.com. Clean separation per market, works well with regional CDNs and analytics splits.
05 — Proof and boundaries
Framework Mode is tested as a full server-and-browser application.
The verifier checks the initial document, route or host behavior, client switching, and a localized action after hydration.
- Route modules
- Typed
- Initial response
- SSR checked
- Mutation
- Action checked
- Evidence
- Live + CI
The examples use generated loader and action types.
Server-rendered messages match the resolved locale.
A post-hydration action returns localized output.
Hosted demos and checked source cover the matrix.
06 — Questions
React Router i18n questions, answered
The short version of the decisions that usually block an implementation.
- Where should React Router resolve the locale?
- In the resolveLocale function passed to createReactRouterI18n. It receives the request, so it can read a cookie, a path segment, or the host. The adapter's root middleware calls it once per request and activates the matching catalog before loaders and actions run.
- Can actions return translated messages?
- Yes. The root middleware also covers actions, so an action can return a message produced by a transformed Palamedes macro without any wrapper.
- Does client navigation keep the active catalog synchronized?
- The adapter loads active-document-locale fragments before hydration and lazy route execution. Language changes navigate to a new document so root locale data, server rendering, and browser messages remain aligned.
- Is React Router Framework Mode the same as Remix?
- No. React Router Framework Mode is a React framework built around route modules and a Vite plugin. The new Remix is a separate server-first full-stack project with its own router, loaders, UI direction, and integration constraints.
07 — Keep exploring