Skip to content

React Router: ReactRouterI18n

Functions, types, and exports for React Router: ReactRouterI18n.

Page outline
import type { ReactRouterI18n } from "@palamedes/react-router"

type ReactRouterI18n<TLocale extends string = string> = {
    /**
     * Root route middleware. Export it from `app/root.tsx` as
     * `export const middleware = [i18n.middleware]`; every loader, action, and
     * document render below it then runs with the request's i18n instance.
     */
    readonly middleware: MiddlewareFunction<Response>;
    /**
     * A complete streaming server entry. Use it as the default export of
     * `app/entry.server.tsx`. It renders inside the request scope, provides
     * `useDocumentLocale()` and `useCatalogAvailable()` with the document's
     * state, and adds the locale's `<html lang>`,
     * catalog import map, and readiness script to the document.
     */
    readonly handleRequest: ReactRouterHandleRequest;
    /** The locale the middleware resolved for this request. */
    getLocale(context: ReactRouterContext): TLocale;
    /** Custom entries: run `work` inside the request's i18n scope. */
    run<Result>(request: Request, context: ReactRouterContext, work: () => Result | Promise<Result>): Promise<Result>;
    /**
     * Custom entries: the document transform for the request's locale. It sets
     * `<html lang>` and, in production, adds the locale's import map.
     */
    createDocumentTransform(request: Request, context: ReactRouterContext): Promise<Transform>;
    /** The adapter's server i18n scope, created once per `createReactRouterI18n()` call. */
    readonly scope: ServerI18nScope<I18nInstance>;
};

Properties

NameTypeRequiredDescription
middlewareMiddlewareFunction<Response>YesReadonly. Root route middleware. Export it from app/root.tsx as
export const middleware = [i18n.middleware]; every loader, action, and
document render below it then runs with the request's i18n instance.
handleRequestReactRouterHandleRequestYesReadonly. A complete streaming server entry. Use it as the default export of
app/entry.server.tsx. It renders inside the request scope, provides
useDocumentLocale() and useCatalogAvailable() with the document's
state, and adds the locale's <html lang>,
catalog import map, and readiness script to the document.
scopeServerI18nScope<I18nInstance>YesReadonly. The adapter's server i18n scope, created once per createReactRouterI18n() call.

getLocale

The locale the middleware resolved for this request.

getLocale(context: ReactRouterContext): TLocale

Parameters

NameTypeRequired
contextReactRouterContextYes

Returns

TLocale

run

Custom entries: run work inside the request's i18n scope.

run<Result>(request: Request, context: ReactRouterContext, work: () => Result | Promise<Result>): Promise<Result>

Parameters

NameTypeRequired
requestRequestYes
contextReactRouterContextYes
work() => Result | Promise<Result>Yes

Returns

Promise<Result>

createDocumentTransform

Custom entries: the document transform for the request's locale. It sets <html lang> and, in production, adds the locale's import map.

createDocumentTransform(request: Request, context: ReactRouterContext): Promise<Transform>

Parameters

NameTypeRequired
requestRequestYes
contextReactRouterContextYes

Returns

Promise<Transform>

Source entry on GitHub

Last updated: November 1, 2026