שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Init doc"v9.5.519.9.2026
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
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:
העתקת הקוד ללוח
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:
העתקת הקוד ללוח
Accessing Context Directly
In addition to using hooks, you can access the resolved IntlayerState directly from the Remix request context:
העתקת הקוד ללוח
