Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Add useIntlayer, useDictionary, useLocale hooks, middleware, and formatters documentation"v9.5.59/19/2026
- "Unified documentation for all exports"v8.0.01/21/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
astro-intlayer Package
The astro-intlayer package provides the necessary tools to integrate Intlayer into Astro applications. It configures locale-based routing, dictionary management, build-time page rewriting, request middleware, and hooks for accessing multilingual content across both server-rendered .astro components and client-side scripts.
Installation
Copy the code to the clipboard
Exports
Integration
The astro-intlayer package provides an Astro integration that sets up Intlayer in your project.
Import:
Copy the code to the clipboard
or default import in astro.config.mjs:
Copy the code to the clipboard
Open the table in a modal to view all data content clearly
| Function | Description | Related Doc |
|---|---|---|
intlayer | Astro integration that prepares dictionaries, configures Vite plugins (aliases, routing proxy, prune), automatically registers request middleware, and emits prerendered pages at localized rewritten URLs. | intlayer |
Hooks (Server & Client)
Import:
Copy the code to the clipboard
Open the table in a modal to view all data content clearly
| Hook | Description | Related Doc |
|---|---|---|
useIntlayer | Picks one dictionary by its key and returns its localized content. In .astro frontmatter, it reads the request locale from Astro.locals. In client <script>, it reads from the client store. | useIntlayer |
useDictionary | Transforms a dictionary object and returns content for the resolved locale. Works in frontmatter and client scripts. | useDictionary |
useLocale | Returns the current locale, default locale, available locales, and a function to update the locale. | useLocale |
Middleware (astro-intlayer/middleware)
Import:
Copy the code to the clipboard
Open the table in a modal to view all data content clearly
| Export | Type | Description | Related Doc |
|---|---|---|---|
onRequest | MiddlewareHandler | Astro middleware that detects the request locale and attaches Astro.locals.intlayer. Registered automatically by intlayer(), or imported manually to compose. | onRequest |
Utilities
Import:
Copy the code to the clipboard
Open the table in a modal to view all data content clearly
| Function | Description | Related Doc |
|---|---|---|
getIntlayerLocals | Helper function to retrieve the current IntlayerLocals object from the request storage scope outside of Astro.locals. | - |
Client Utilities (astro-intlayer/client)
Import:
Copy the code to the clipboard
When imported in the browser or inside client <script> tags, astro-intlayer automatically maps to astro-intlayer/client (powered by vanilla-intlayer), providing client-side dictionary getters, store subscribers, and locale persistence tools.
Formatters (astro-intlayer/format)
Import:
Copy the code to the clipboard
Open the table in a modal to view all data content clearly
| Hook | Description |
|---|---|
useIntl | Returns an Intl instance bound to the request or client locale with caching and subscription capabilities. |
useDate | Returns a date formatting function pre-bound to the current locale (Intl.DateTimeFormat). |
useNumber | Returns a number formatting function pre-bound to the current locale (Intl.NumberFormat). |
useCurrency | Returns a currency formatting function pre-bound to the current locale. |
usePercentage | Returns a percentage formatting function pre-bound to the current locale. |
useRelativeTime | Returns a relative time formatting function pre-bound to the current locale (Intl.RelativeTimeFormat). |
useList | Returns a list formatting function pre-bound to the current locale (Intl.ListFormat). |
useUnit | Returns a unit formatting function pre-bound to the current locale. |
useCompact | Returns a compact number formatting function pre-bound to the current locale (e.g. 1.5K). |
HTML Utilities (astro-intlayer/html)
Import:
Copy the code to the clipboard
Open the table in a modal to view all data content clearly
| Export | Type | Description |
|---|---|---|
renderHTML | Function | Standalone utility function to render HTML nodes. |
useHTML | Hook | Hook to get the HTML provider context and configuration. |
useHTMLRenderer | Hook | Hook to obtain a pre-configured HTML renderer function. |
Markdown Utilities (astro-intlayer/markdown)
Import:
Copy the code to the clipboard
Open the table in a modal to view all data content clearly
| Export | Type | Description |
|---|---|---|
compileMarkdown | Function | Compiles markdown strings into structured representation. |
renderMarkdown | Function | Renders markdown content into output nodes. |
parseMarkdown | Function | Parses raw markdown content into an AST. |
useMarkdown | Hook | Hook to get the markdown provider context. |
useMarkdownRenderer | Hook | Hook to obtain a pre-configured Markdown renderer function. |
Types
Import:
Copy the code to the clipboard
Open the table in a modal to view all data content clearly
| Type | Description |
|---|---|
IntlayerLocals | The object attached to Astro.locals.intlayer containing locale, defaultLocale, and availableLocales. |
UseLocaleProps | Optional configuration properties accepted by useLocale(). |
UseLocaleResult | The return type of useLocale(), providing locale properties and update methods. |
