מחבר:
הפנו את עוזר ה-AI המועדף עליכם למסמך הזהChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Init doc"v9.5.519.9.2026
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתעריכת המסמך הזה
אם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודנוצר:2026-09-19עדכון אחרון:2026-09-19
העתקה
העתקת ה-Markdown של המסמך ללוח
useIntlayer Hook Documentation
The useIntlayer hook allows you to retrieve localized dictionary content by key in Astro applications.
It can be called in two distinct contexts using the same import path:
- Server / Frontmatter: Inside
.astrofiles, it automatically resolves content using the request locale stored inAstro.locals.intlayer. - Browser / Client
<script>: Inside client scripts or UI framework components, it resolves to the client-side store implementation (vanilla-intlayer).
Usage
In Astro Component Frontmatter
src/pages/index.astro
העתקת קוד
העתקת הקוד ללוח
In Client <script> Blocks
src/components/InteractiveWidget.astro
העתקת קוד
העתקת הקוד ללוח
Parameters
ts
העתקת קוד
העתקת הקוד ללוח
key: The unique key of the dictionary (as defined in your.content.tsdeclaration files).localeOrSelector(optional): A specific locale or selector object ({ item },{ variant }, optionally withlocale). When provided, it overrides the locale detected from the request context or client store.
Description
The hook performs the following tasks:
- Locale Resolution:
- On the server, reads the active locale from
Astro.locals.intlayervia anAsyncLocalStoragescope initialized by theastro-intlayer/middleware. - In the browser, reads the active locale from the client storage/store.
- On the server, reads the active locale from
- Dictionary Retrieval: Injects the dictionary content matching the specified key.
- Translation Processing: Resolves translations (
t()), enumerations, conditions, and markdown into ready-to-render content.
