Creation:2026-09-19Last update:2026-09-19
Reference this doc to your favorite AI assistantChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
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.519/09/2026
The content of this page was translated using an AI.
See the last version of the original content in EnglishEdit this doc
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
Copy doc Markdown to clipboard
useIntlayer Hook Documentation
The useIntlayer hook allows you to retrieve localised 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
Copy code
Copy the code to the clipboard
In Client <script> Blocks
src/components/InteractiveWidget.astro
Copy code
Copy the code to the clipboard
Parameters
ts
Copy code
Copy the code to the clipboard
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 initialised 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.
