PolyStella 单体
⚠️ 工作正在进行中. PolyStella正在积极发展. API,配置形状,以及内部行为可能不经通知而改变. 尚未通过新项目.
PolyStella是一个 天体 集成在构建时使用AI将内容翻译为附加地语,缓存Cloudflare R2中的翻译,并给被翻译的页面注入地语前缀路由.
它会做什么
- Build-time翻译. 翻译
.md, (中文(简体) ),.mdx,以及.toml内容包含到其它区域astro build。访客得到静态字节;没有运行时间 AI 呼叫. - R2号. 翻译内容由源字节+词汇+模型处理. 未更改的页面重建费用为零 。 译出从不执入回向.
- 词汇控制. Per-locale YAML 文件 pin do-not- translate terms, 首选翻译, 和免费格式的翻译注释.
- 手语翻译超载. 丢弃文件到
i18n/overrides/{locale}/<mirrored-path>它胜过人工智能的逐字输出. - 地方前置路由. 船舶通过注入的动态航道,将本地化前缀页标出.
- UI-string 维护. 用于铬文本的Per-locale JSON文件,有构建时漂移检测和同步+AI-fill的CLI.
安装
从 npm 安装 :
pnpm add @cloudflare/polystella
同伴依赖性 : astro ^7.0.0,可选 react ^17 || ^18 || ^19。 。 。 .
快开始
四个文件参与一个典型的设置.
1. 联合国. astro.config.mjs 登记合并。 当地人在这里生活.
import { defineConfig } from "astro/config";
import polystella from "@cloudflare/polystella";
import polystellaConfig from "./polystella.config.mjs";
export default defineConfig({
i18n: {
defaultLocale: "en-US",
locales: ["en-US", "pt-BR", "ja-JP"],
},
integrations: [polystella(polystellaConfig)],
});
2. 联合国. polystella.config.mjs ——提供方,词汇,R2,格式专用密钥. 每个选项都记录在 配置参考。 。 。 .
3个. src/content.config.ts ——注册兄弟会收藏,使Astro的内容层能取出翻译. 语言集是自动生成的 astro.config.mjs。 。 。 .
import { defineCollection } from "astro:content";
import { polystellaCollections } from "@cloudflare/polystella/content";
import { i18nLoader, i18nSchema } from "@cloudflare/polystella/i18n";
import { blog, authors } from "./content-schemas";
export const collections = {
...polystellaCollections({
source: { blog, authors },
}),
i18n: defineCollection({ loader: i18nLoader(), schema: i18nSchema() }),
};
4.四. src/env.d.ts ——取取PolyStella虚拟模块的类型:
/// <reference types="@cloudflare/polystella/client" />
仅限使用目录
已经处理本地化内容和路由的项目只能采用 PolyStella的JSON目录流:
import catalogAstro from "@cloudflare/polystella/catalog/astro";
export default defineConfig({
i18n: { defaultLocale: "en-US", locales: ["en-US", "pt-BR"] },
integrations: [catalogAstro({ baseDir: "./src/i18n" })],
});
这个束缚 Astro.locals.t 财务报告和审定财务报表 Astro.locals.lhref 只有这个 没有
运行内容翻译、 路由shims、 R2 缓存设置或本地化
收集 API.
文档
完整的文献资料在Nimbus Docs网站(下) docs/ 在此重播中 :
- 开始 安装、快速启动、心理模型
- 概念 ——管线,缓存,覆接,跑时桥
- 配置参考 - 每一个选择
- 国 际 —— 说
translate, (中文(简体) ),check-ui, (中文(简体) ),sync-ui, (中文(简体) ),translate-ui - 运行时间 API —— 说
Astro.locals,中间软件,反应钩 - 路线图 - 已运出/计划特性
捐款
捐款是受欢迎的,但PolyStella是由一个小的
团队和审查没有保障。 见
CONTRIBUTING.md。代理上下文存在于
AGENTS.md 财务报告和审定财务报表 ARCHITECTURE.md。 。 。 .