Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Update Solid useIntlayer API usage to direct property access"v8.9.004/05/2026
- "Added init command"v7.5.930/12/2025
- "Update of Astro integration, configuration and usage"v6.2.003/10/2025
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
Translate your Astro site with Intlayer | Internationalisation (i18n)
Table of Contents
Why Intlayer over alternatives?
Compared to main solutions like astro-i18n or i18next, Intlayer is a solution that comes with integrated optimizations such as:
Intlayer is optimized to work perfectly with Astro by offering multilingual routing, sitemap, and all the features needed for scaling internationalization (i18n).
Instead of loading massive JSON files into your pages, load only the necessary content. Intlayer helps reduce your bundle and page sizes by up to 50%.
Scoping your application's content facilitates maintenance for large-scale applications. You can duplicate or delete a single feature folder without the mental burden of reviewing your entire content codebase. Additionally, Intlayer is fully typed to ensure your content's accuracy.
Co-locating content reduces the context needed by Large Language Models (LLMs). Intlayer also comes with a suite of tools, such as a CLI to test for missing translations,LSP, MCP, and agent skills, to make the developer experience (DX) even smoother for AI agents.
Use automation to translate in your CI/CD pipeline using the LLM of your choice at the cost of your AI provider. Intlayer also offers a compiler to automate content extraction, as well as a web platform to help translate in the background.
Connecting massive JSON files to components can lead to performance and reactivity issues. Intlayer optimizes your content loading at build time.
More than just an i18n solution, Intlayer provides an self-hosted visual editor and a full CMS to help you manage your multilingual content in real-time, making collaboration with translators, copywriters, and other team members seamless. Content can be stored locally and/or remotely.
Step-by-Step Guide to Configure Intlayer in Astro
Check out the application template on GitHub.
Install Dependencies
Install the necessary packages using your preferred package manager:
bashCopy codeCopy the code to the clipboard
npm install intlayer astro-intlayer# Optional: If you add support for React islandsnpm install react react-dom react-intlayer @astrojs/reactintlayer The core package that provides i18n tools for configuration management, translations, content declaration, transpilation, and CLI commands.
astro-intlayer Includes the Astro integration plugin to link Intlayer with the Vite bundler, as well as the middleware to detect the user's preferred language, manage cookies, and handle URL redirects.
Configure Your Project
Create a configuration file to define your application's languages:
intlayer.config.tsCopy codeCopy the code to the clipboard
import { Locales, type IntlayerConfig } from "intlayer";const config: IntlayerConfig = { internationalization: { locales: [ Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH, Locales.ENGLISH_UNITED_KINGDOM, // Your other languages ], defaultLocale: Locales.ENGLISH, },};export default config;Through this configuration file, you can configure localised URLs, middleware redirects, cookie names, location and extensions of content declarations, disable Intlayer logs in the console, and more. For a full list of available parameters, refer to the configuration documentation.
Integrate Intlayer into Your Astro Configuration
Add the
intlayerplugin to your Astro configuration.astro.config.tsCopy codeCopy the code to the clipboard
// @ts-checkimport { intlayer } from "astro-intlayer";import { defineConfig } from "astro/config";// https://astro.build/configexport default defineConfig({ integrations: [intlayer()],});The
intlayer()integration plugin is used to integrate Intlayer with Astro. It ensures the generation of the content declaration files and monitors them in development mode. It defines Intlayer environment variables within the Astro application and provides aliases to optimise performance.Declare Your Content
Create and manage your content declarations to store translations:
src/app.content.tsxCopy codeCopy the code to the clipboard
import { t, type Dictionary } from "intlayer";import type { ReactNode } from "react";const appContent = { key: "app", content: { title: t({ en: "Hello World", fr: "Bonjour le monde", es: "Hola mundo", "en-GB": "Hello World", }), },} satisfies Dictionary;export default appContent;Content declarations can be defined anywhere in your application, as long as they are included in the
contentDir(by default./src) and match the content declaration file extension (by default.content.{json,ts,tsx,js,jsx,mjs,cjs}).For more information, refer to the content declaration documentation.
Using Content in Astro
You can consume the dictionaries directly in your
.astrofiles using the core helpers exported fromintlayer.src/pages/index.astroCopy codeCopy the code to the clipboard
---import { getIntlayer, getLocaleFromPath, getLocalizedUrl, defaultLocale, localeMap, getHTMLTextDir, type LocalesValues,} from "intlayer";import LocaleSwitcher from "../components/LocaleSwitcher.astro";// Get the current locale from the URL (e.g. /es/about -> 'es')const locale = getLocaleFromPath(Astro.url.pathname) as LocalesValues;// Get the content for the 'app' dictionaryconst { title } = getIntlayer("app", locale);---<!doctype html><html lang={locale} dir={getHTMLTextDir(locale)}> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <title>{title}</title> <!-- Canonical link: Tells search engines which is the primary version of this page --> <link rel="canonical" href={new URL(getLocalizedUrl(Astro.url.pathname, locale), Astro.site)} /> <!-- Hreflang: Tell Google about all localized versions --> { localeMap(({ locale: mapLocale }) => ( <link rel="alternate" hreflang={mapLocale} href={new URL( getLocalizedUrl(Astro.url.pathname, mapLocale), Astro.site )} /> )) } <!-- x-default: Fallback for users in unmatched languages --> <link rel="alternate" hreflang="x-default" href={new URL( getLocalizedUrl(Astro.url.pathname, defaultLocale), Astro.site )} /> </head> <body> <header> <LocaleSwitcher /> </header> <main> <h1>{title}</h1> </main> </body></html>Localised Routing
Create dynamic route segments to serve localised pages (e.g.,
src/pages/[locale]/index.astro):src/pages/[locale]/index.astroCopy codeCopy the code to the clipboard
---import { getIntlayer } from "intlayer";const { title } = getIntlayer('app');---<h1>{title}</h1>The Astro integration adds a Vite middleware that helps with language-sensitive routing and environment definitions during development. You can also create links across languages using your own logic or
intlayertools likegetLocalizedUrl.Continue Using Your Favourite Frameworks
Keep building your application using the framework of your choice.
- Intlayer + React: Intlayer with React
- Intlayer + Vue: Intlayer with Vue
- Intlayer + Svelte: Intlayer with Svelte
- Intlayer + Solid: Intlayer with Solid
- Intlayer + Preact: Intlayer with Preact
Extract the content of your components
OptionalIf you have an existing codebase, transforming thousands of files can be time-consuming.
To ease this process, Intlayer propose a compiler / extractor to transform your components and extract the content.
To set it up, you can add a
compilersection in yourintlayer.config.tsfile:intlayer.config.tsCopy codeCopy the code to the clipboard
import { type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { // ... Rest of your config compiler: { /** * Indicates if the compiler should be enabled. */ enabled: true, /** * Defines the output files path */ output: ({ fileName, extension }) => `./${fileName}${extension}`, /** * Indicates if the components should be saved after being transformed. * * - If `true`, the compiler will rewrite the component file in the disk. So the transformation will be permanent, and the compiler will skip the transformation for the next process. That way, the compiler can transform the app, and then it can be removed. * * - If `false`, the compiler will inject the `useIntlayer()` function call into the code in the build output only, and keep the base codebase intact. The transformation will be done only in memory. */ saveComponents: false, /** * Dictionary key prefix */ dictionaryKeyPrefix: "", }, }; export default config;Run the extractor to transform your components and extract the content
bashCopy codeCopy the code to the clipboard
npx intlayer extract
TypeScript Configuration
Intlayer uses module augmentation to leverage TypeScript, making your codebase more robust.


Ensure your TypeScript configuration includes the autogenerated types.
Copy the code to the clipboard
{ // ... your existing TypeScript configuration "include": [ // ... your existing TypeScript configuration ".intlayer/**/*.ts", // Include autogenerated types ],}Git Configuration
It is recommended to ignore the files generated by Intlayer. This avoids committing them to your Git repository.
To do this, add the following instructions to your .gitignore file:
Copy the code to the clipboard
# Ignore the files generated by Intlayer.intlayerVS Code Extension
To improve your development experience with Intlayer, you can install the official Intlayer VS Code extension.
Installation from the VS Code Marketplace
This extension provides:
- Autocompletion for translation keys.
- Real-time error detection for missing translations.
- Inline preview of translated content.
- Quick actions for easily creating and updating translations.
For more information on using the extension, refer to the VS Code Extension documentation.
Deepen Your Knowledge
If you want to learn more, you can also implement the Visual Editor or use the CMS to externalise your content.