מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Init doc"v9.5.519.9.2026
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2026-09-19עדכון אחרון:2026-09-19
העתקה
העתקת ה-Markdown של המסמך ללוח
onRequest Astro Middleware Documentation
The onRequest middleware from astro-intlayer/middleware resolves the locale of each incoming HTTP request and populates Astro.locals.intlayer.
When you register the intlayer() integration in astro.config.mjs, this middleware is injected automatically. You only need to import it directly if you are manually composing Astro middleware using sequence(...).
Usage
src/middleware.ts
העתקת קוד
העתקת הקוד ללוח
Description
The middleware performs the following:
- Locale Detection:
- URL: Analyzes the URL path prefix or
?locale=search parameter (unlessrouting.modeis set tono-prefix). - Cookies / Headers: Checks persisted locale cookies or custom header values.
- Accept-Language: Falls back to the browser's preferred language negotiation.
- For prerendered pages (
context.isPrerendered), the locale is extracted strictly from the URL to prevent Astro build warnings.
- URL: Analyzes the URL path prefix or
- Context Population: Populates
Astro.locals.intlayerwith:locale: The resolved locale.defaultLocale: The default fallback locale.availableLocales: The array of configured locales.
- AsyncLocalStorage Scope: Wraps the downstream request processing inside an
AsyncLocalStoragescope, allowinguseIntlayer(),useDictionary(), anduseLocale()to access request state without passing arguments.
IntlayerLocals Type
ts
העתקת קוד
העתקת הקוד ללוח
