Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Update integration documentation with middleware and hooks details"v9.5.519/09/2026
- "Init doc"v8.0.021/01/2026
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf 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
intlayer Astro Integration Documentation
The intlayer integration for Astro configures your project for multilingual internationalisation (i18n). It handles build-time dictionary preparation, Vite plugin injection, automatic request middleware registration, and emitting localised prerendered pages.
Usage
Add intlayer() to your astro.config.mjs:
Copy the code to the clipboard
Astro CLI's codemod (astro add astro-intlayer) also generates a default import which is supported:
Copy the code to the clipboard
Description
The integration hooks into Astro's build and runtime lifecycle:
- Config Setup (
astro:config:setup):- Dictionary Preparation: Prepares Intlayer dictionaries and generated types before the build runs.
- Vite Plugins: Injects plugins for Vite aliases (enabling seamless dictionary imports), locale routing proxies, and build pruning.
- Middleware Registration: Automatically injects
astro-intlayer/middlewareinto your project's middleware chain, populatingAstro.locals.intlayeron every incoming request.
- Build Done (
astro:build:done):- Page Rewrites: Inspects localised URL rewrite rules and emits prerendered HTML pages at their corresponding localised paths.
What is Provided Out of the Box
Once configured, your Astro application can immediately use:
- The
useIntlayer,useDictionary, anduseLocalehooks inside.astrocomponent frontmatter. - The
Astro.locals.intlayerobject in Astro endpoints and pages. - Client-side imports in
<script>blocks that mirror the same API with reactive updates. - Built-in formatters under
astro-intlayer/format(useDate,useNumber,useCurrency, etc.).
