Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Init doc"v9.5.59/19/2026
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
intlayer Remix 3 Middleware Documentation
The intlayer middleware for Remix 3 manages the internationalization layer across your application. Built on web standards (Request and Response), it handles locale routing (redirects and internal rewrites), detects the request locale, persists it to cookies and headers, and establishes an AsyncLocalStorage scope so that downstream handlers and components can access translations without prop drilling.
Usage
Register the intlayer middleware when initializing your Remix 3 router:
Copy the code to the clipboard
Description
The intlayer middleware performs the following tasks:
- Dictionary Preparation: Runs
prepareIntlayeron startup to ensure all generated dictionaries are built and available. - Locale Routing: Evaluates the request against the configured routing strategy (
prefix_always,prefix_as_needed,no_prefix):- Redirects: If a user visits
/aboutand should be routed to a locale prefix (e.g./fr/about), the middleware issues a redirect response with appropriatelocationandSet-Cookieheaders. - Internal Rewrites: When a user accesses
/fr/about, the URL is rewritten internally so your route handler matches/about, while the resolved locale is captured asfr. - Localized URL Aliases: Respects URL rewrite rules defined in
intlayer.config.ts(e.g., rewriting/fr/aboutto/fr/a-propos).
- Redirects: If a user visits
- Locale Resolution: Detects the active locale based on URL prefix, persisted cookies, custom headers, or
Accept-Languagebrowser preferences. - Context Injection:
- Attaches
IntlayerState(locale,defaultLocale,availableLocales) to the RemixRequestContextunder theIntlayerkey andcontext.intlayer. - Runs the rest of the request inside an
AsyncLocalStoragescope (requestStorage), enablinguseIntlayer,useDictionary, anduseLocaleto be invoked cleanly in handlers, views, and components.
- Attaches
- Persistence: Attaches outgoing locale headers and cookies to the final HTTP response to persist the user's preference.
Parameters
The intlayer function accepts optional IntlayerMiddlewareOptions:
Copy the code to the clipboard
Accessing Context Directly
In addition to using hooks, you can access the resolved IntlayerState directly from the Remix request context:
Copy the code to the clipboard
