app-template/packages/i18n/AGENTS.md

37 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# AGENTS.md — @app/i18n
## 职责
**文案与 locale 纯函数库**:静态 messages、`t()`、Accept-Language 解析、cookie 名。
不依赖 Astro/React/DB;islands 与 `.astro` 共用同一套查表,**不要引入 i18next**。
## 结构
```
src/
locales.ts # Locale、LOCALES、DEFAULT_LOCALE、PREFIX_LOCALE
cookie.ts # COOKIE_LANG = "app-lang"
accept-language.ts # parsePreferredLocale / shouldRedirectRootToEn
preferred.ts # resolvePreferredLocale(cookie > Accept-Language > zh-CN)
messages/zh-CN.ts # key 权威源
messages/en.ts # 必须与 zh-CN 同构
t.ts # t(locale, key, params?)
index.ts
```
## 约定
- 中文 `/zh-CN`、英文 `/en` 前缀;裸 `/` 仅由 middleware 检测后 302,不挂页面。
- 页面路由:`@app/web` 用 **单套** `src/pages/[locale]/…` 动态前缀,不要复制 `zh-CN/`、`en/` 目录。
- 新增文案:先改 `zh-CN.ts`,再补 `en.ts`(类型强制 key 对齐)。
- 插值仅支持 `{name}`;无 ICU/复数(需要时再扩展)。
- React island:传 `locale` prop 或组件内 `t(locale, key)`,不靠 Provider。
- 路径检测与 302 在 `@app/web` 的 `middleware.ts`,本包只提供解析函数。
## 命令
```bash
yarn workspace @app/i18n typecheck
yarn workspace @app/i18n build
```