← Back to skills
extension
Category: Development & EngineeringAPI key requirement unconfirmed

intlayer-astro

Integrates Intlayer internationalization with Astro applications. Use when the user asks to "setup Astro i18n", use "getIntlayer" in Astro components, or manage server-side content in Astro.

personAuthor: jakexiaohubgithub

Intlayer Astro Usage

Setup

The intlayer() integration in astro.config.ts builds the dictionaries and adds a middleware that resolves the locale of every request into Astro.locals.intlayer.

Server-side (Astro Components)

---
import { useIntlayer, useLocale } from "astro-intlayer";

// Locale resolved by the middleware (e.g. /es/about -> 'es')
const { locale } = useLocale();
const content = useIntlayer("my-dictionary-key");
---
<h1>{content.title}</h1>

Framework Islands

Islands use their framework package (react-intlayer, vue-intlayer, svelte-intlayer, solid-intlayer, preact-intlayer, lit-intlayer) and receive the server-detected locale as a prop.

Compiler

The Intlayer Compiler can extract all your content keys from your components, using one CLI command (npx intlayer extract) or automatically at app build.

References

Environments

Concepts

Packages