← 返回 Skill 列表
extension
分类: 开发与工程API Key 暂未确认

intlayer-astro

将Intlayer国际化与Astro应用程序集成。当用户要求“设置Astro i18n”时使用,或在Astro组件中使用“getIntlayer”,以及在Astro中管理服务器端内容时使用。

person作者: 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