This project is a comprehensive boilerplate for building multilingual Astro applications using Intlayer. It demonstrates how to integrate internationalization (i18n) across Astro and various UI frameworks like React, Svelte, Vue, and more.
- Framework Agnostic: Works with Astro, React, Vue, Svelte, Solid, Preact, and Lit.
- Declarative Dictionaries: Manage translations at the component level for better maintainability.
- Type Safety: Benefit from autogenerated TypeScript types for your translation keys.
- Localized Routing: Pre-configured middleware for locale detection and URL management.
- SEO Optimized: Includes patterns for
hreflang, canonical links, and sitemaps.
npm installnpm run devThe application will be available at http://localhost:4321.
Create content declarations in your src directory. They can be .json, .ts, or .tsx files matching the .content.{json,ts,tsx} extension.
// src/app.content.tsx
import { t, type Dictionary } from "intlayer";
const appContent = {
key: "app",
content: {
title: t({
en: "Hello World",
fr: "Bonjour le monde",
es: "Hola mundo",
}),
},
} satisfies Dictionary;
export default appContent;You can consume dictionaries directly in .astro files:
---
// src/pages/index.astro
import { getIntlayer, getLocaleFromPath } from "intlayer";
const locale = getLocaleFromPath(Astro.url.pathname);
const { title } = getIntlayer("app", locale);
---
<h1>{title}</h1>src/pages/[...locale]/: Handles localized routing.intlayer.config.ts: Configuration for your locales (en,fr,esby default) and routing strategies..intlayer/: Directory where Intlayer generates types and compiled dictionaries.
For full documentation and advanced patterns, visit the official Intlayer guides:
- Intlayer with Astro Guide
- Intlayer with React
- Intlayer with Vue
- Intlayer with Svelte
- Intlayer with Solid
- Intlayer with Preact
- Intlayer with Lit