diff --git a/.gitignore b/.gitignore index 32dab8f..766c9e9 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ apps/site/public/registry.json apps/site/public/r/ apps/site/dist/ apps/site/.astro/ +apps/site/src/paraglide/ diff --git a/AGENTS.md b/AGENTS.md index f48c821..c0b8587 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -16,7 +16,8 @@ drives most of what follows. ```bash pnpm install pnpm build # packages → CSS → registry → the Astro site, in that order -pnpm verify # format:check, lint, typecheck, test, registry:check +pnpm verify # i18n, format:check, lint, typecheck, test, registry:check +pnpm i18n # paraglide compile — the site's generated, gitignored message code pnpm site:dev # astro dev pnpm site:deploy # wrangler pages deploy — Cloudflare Pages, project botui-site ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b6640f..f6b9e7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,13 @@ All notable changes to BotUI are recorded here. The format follows - `apps/site/test/playground.test.tsx` drives the real controls: ten tests that dispatch input events and assert the field changed. A slider that renders and does nothing is indistinguishable from one that works, in a screenshot and in a DOM dump. +- **The site is bilingual.** English at `/` and Chinese at `/zh/`, from Paraglide message + catalogs under `apps/site/messages/`, with a real link between them, per-page `hreflang`, and a + `` that matches the copy. The switch is a link to the other locale's file rather + than a client-side toggle, so `/zh/` is reachable with JavaScript off and crawlable. +- `pnpm i18n` compiles the message catalogs. `apps/site/src/paraglide` is generated and + gitignored, so `typecheck` and `verify` now run this first: from a clean clone they used to + fail on imports that were not on disk yet. ### Fixed @@ -49,9 +56,6 @@ All notable changes to BotUI are recorded here. The format follows - Two audits in `apps/site/test/playground.test.tsx` compare each slider's thumb against the number printed beside it, and its requested value against its declared range. Both were verified by reintroducing the defect. - -### Fixed - - **The stagger dial was a one-way door.** Its default is the _preset's_ spread, so once dragged, `stagger` was a number forever: the label stopped saying "preset", switching the preset no longer moved the dial, and nothing on screen offered a way back. It now shows the @@ -61,6 +65,19 @@ All notable changes to BotUI are recorded here. The format follows start. Anchoring the match to the start meant the one slider whose default comes from a preset was the one slider the audit skipped — which is how a label reading only "preset" survived while its thumb sat at 95. +- **The Chinese page reverted to English the moment it finished loading.** The server-rendered + markup was correct, because the SSG middleware sets the locale outright, but every island + resolved its own copy from the URL — and the default locale's URL pattern was the catch-all + `/:path(.*)?`, which also matches `/zh/` by reading "zh" as a path segment. Paraglide takes + the first pattern that matches, so English won every URL. The default locale's pattern is now + `/` exactly, and `apps/site/test/locale-resolution.test.tsx` renders the playground at both + URLs and asserts copy that exists in only one catalog. The section headings could not have + caught it: they are bilingual in both catalogs, so the page only _looked_ half translated. +- The Paraglide compiler options were written down twice — in `astro.config.mjs` and in + `project.inlang/paraglide.config.js` — and the copies had already drifted, with the standalone + config still placing English at `/en/` while Astro had been writing it to `/`. A + `paraglide compile` run from the CLI would have generated a runtime that disagreed with the + one that ships. Both now read `project.inlang/paraglide.options.js`. ## [0.1.0] — 2026-09-30 diff --git a/CHANGELOG.zh.md b/CHANGELOG.zh.md index 4b5a090..d5bca15 100644 --- a/CHANGELOG.zh.md +++ b/CHANGELOG.zh.md @@ -27,6 +27,12 @@ BotUI 的所有值得注意的变更都记录在此。格式遵循 - 引擎导出 `cssRenderable()` / `cssRenderGap()`,调用方直接问组件 CSS 渲染器能否表达某个动效, 而不是自己重写这条规则。playground 之前检查的是 preset **是否存在**,所以 `columns`(per-dot delay 无法表达的动效)的复选框仍然是可勾选状态。 +- **站点现在支持双语。** 英文在 `/`,中文在 `/zh/`,文案来自 `apps/site/messages/` 下的 Paraglide + 消息目录;两个语言之间是真实链接,页面带各自的 `hreflang`,`` 与文案一致。切换器 + 指向另一个语言的**文件**,而不是客户端 toggle —— 这样关掉 JavaScript 也能到达 `/zh/`,搜索引擎 + 也能抓到。 +- `pnpm i18n` 编译消息目录。`apps/site/src/paraglide` 是生成产物且被 gitignore,因此 `typecheck` + 和 `verify` 现在会先跑这一步:全新 clone 时它们原本会因为引用尚不存在的文件而失败。 - `apps/site/test/playground.test.tsx` 驱动真实控件:10 个测试派发 input 事件并断言场确实变了。 一个渲染出来但不干活的滑杆,在截图和 DOM dump 里和一个正常工作的滑杆无法区分。 @@ -42,8 +48,6 @@ BotUI 的所有值得注意的变更都记录在此。格式遵循 - `apps/site/test/playground.test.tsx` 里新增两条审计:把每个滑杆的滑块位置和它旁边的数字 对照,把请求值和声明范围对照。两条都通过"重新植入缺陷"验证过确实会失败。 -### 修复 - - **错峰滑杆是单向门。** 它的默认值来自 _preset_ 的 spread,所以一旦拖动,`stagger` 就永远 是个数字:标签不再显示"预设"、切换 preset 也不再带动滑杆,而且界面上没有任何回去的入口。 现在标签显示 preset 自身的数值(`预设 95%`,因此标签永远不会和滑块矛盾),并且在值被覆盖 @@ -51,6 +55,17 @@ BotUI 的所有值得注意的变更都记录在此。格式遵循 - 滑杆审计现在在标签**任意位置**找百分比,而不再只匹配开头。只匹配开头意味着"默认值来自 preset 的那个滑杆"恰好是审计唯一跳过的滑杆 —— 这就是为什么只写着"预设"、滑块却停在 95 的 标签能一直存在。 +- **中文页面一加载完就退回英文。** 服务端渲染出的 HTML 是对的,因为 SSG middleware 直接设置了 + locale;但每个 island 自己从 URL 解析文案,而默认语言的 URL pattern 是通配的 `/:path(.*)?`, + 它同样能匹配 `/zh/` —— 把 "zh" 当成路径段读走了。Paraglide 取第一个匹配的 pattern,于是英文 + 赢下所有 URL。现在默认语言的 pattern 精确为 `/`,并且 + `apps/site/test/locale-resolution.test.tsx` 会在两个 URL 下分别渲染 playground,断言只在其中一个 + 目录里存在的文案。区块标题本来抓不到这个问题:它们在两个目录里都是双语的,所以页面看起来只是 + 「翻译了一半」。 +- Paraglide 的编译选项被写了两份 —— `astro.config.mjs` 和 `project.inlang/paraglide.config.js` + —— 而且两份已经漂移:独立那份仍把英文放在 `/en/`,而 Astro 一直写在 `/`。从 CLI 跑一次 + `paraglide compile` 就会生成一个与线上不一致的 runtime。现在两份都读 + `project.inlang/paraglide.options.js`。 ## [0.1.0] — 2026-09-30 diff --git a/README.md b/README.md index 9a25df9..be3969b 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Using them as npm packages is supported but not the recommended path — the poi ## The site -`apps/site` is an [Astro](https://astro.build) site with React islands, built by Vite and deployed to **Cloudflare Pages** as `ui.botharness.ai`. It is `output: 'static'`, so the deploy is a file tree. +`apps/site` is an [Astro](https://astro.build) site with React islands, built by Vite and deployed to **Cloudflare Pages** as `ui.botharness.ai`. It is `output: 'static'`, so the deploy is a file tree. The site is bilingual — English at `/`, Chinese at `/zh/` — from Paraglide catalogs in `apps/site/messages/`, one document per locale because a static build has no request to vary on. The language switch is a link to the other locale's file, not a client-side toggle. The demos mount `@botharness/botui-core` **directly**, not through the published `` wrapper. A docs site that demos its own component through its own wrapper inherits every fix and reports the component works; here the only React code is a ref and an effect, so what the page shows is the engine doing its own thing. @@ -91,7 +91,8 @@ pnpm site:deploy # wrangler pages deploy ```bash pnpm install pnpm build # packages → CSS → registry → the Astro site, in that order -pnpm verify # format, lint, typecheck, test, registry check +pnpm verify # i18n, format, lint, typecheck, test, registry check +pnpm i18n # compile the message catalogs (generated, gitignored) ``` Toolchain: pnpm 12 · Node ≥22 · **TypeScript 7** · **Vite 8** · **React 19.3** · **Astro 7** · oxlint · oxfmt · vitest · tsdown. diff --git a/apps/site/astro.config.mjs b/apps/site/astro.config.mjs index 62e483e..c45287b 100644 --- a/apps/site/astro.config.mjs +++ b/apps/site/astro.config.mjs @@ -1,6 +1,8 @@ // @ts-check import { defineConfig } from "astro/config"; import react from "@astrojs/react"; +import { paraglideVitePlugin } from "@inlang/paraglide-js"; +import * as paraglideOptions from "./project.inlang/paraglide.options.js"; /** * Static output, no adapter. @@ -8,22 +10,38 @@ import react from "@astrojs/react"; * The registry is JSON and the demos run in the browser, so there is nothing to * render per request — and `output: 'static'` means the deploy target is a plain * file tree, which is exactly what Cloudflare Pages wants. Adding SSR later is one - * line: `@astrojs/cloudflare` plus `output: 'server'`, and the pages here do not - * change. + * line: `@astrojs/cloudflare` plus `output: 'server'`, and the pages do not change. + * + * `i18n.locales` MUST match `project.inlang/settings.json`. Astro's i18n is what + * gives the middleware a `currentLocale` during a static render — with no request, + * something has to tell Paraglide which language it is building. */ export default defineConfig({ output: "static", integrations: [react()], - build: { - // the engine ships real source in the registry, so the demo inlining the built - // bundle is not the same bytes — but it IS the same implementation, which is - // the property that matters. Keeping it a separate chunk makes that visible in - // the network panel instead of hidden in a bundle. - assets: "assets", + i18n: { + defaultLocale: "en", + locales: ["en", "zh"], + // every locale is prefixed, because SSG needs one file per locale: `/en/` and + // `/zh/` are different files on disk, not one file that varies by request + // English is NOT prefixed: `/` is English and `/zh/` is Chinese. Astro demands a + // root index page whenever prefixDefaultLocale is on, and paying a redirect hop on + // the URL people share and bookmark is a worse trade than one shared page body. + routing: { prefixDefaultLocale: false, redirectToDefaultLocale: false }, }, + build: { assets: "assets" }, vite: { - // a warning here means the engine is being pulled into the SSR graph, where it - // has no document to paint into ssr: { noExternal: ["@botharness/botui-core"] }, + plugins: [ + // Options come from project.inlang/paraglide.options.js, which the standalone + // CLI compile reads too, so the plugin and `pnpm --filter botui-site + // i18n:compile` cannot produce two different runtimes. Only `outdir` is spelled + // out here: it is a path relative to the bundler's CWD, not to the project. + paraglideVitePlugin({ + project: "./project.inlang", + outdir: "./src/paraglide", + ...paraglideOptions, + }), + ], }, }); diff --git a/apps/site/messages/en.json b/apps/site/messages/en.json new file mode 100644 index 0000000..a20c9cc --- /dev/null +++ b/apps/site/messages/en.json @@ -0,0 +1,104 @@ +{ + "site_title": "BotUI — open-source UI components for agent products", + "site_description": "Copy-and-own UI components for agent products. Install with npx, then the code is yours. MIT licensed.", + "brand": "BotUI", + "nav_install": "Install", + "nav_components": "Components", + "nav_github": "GitHub", + "hero_title": "UI components for things that think.", + "hero_lede": "Loading states, streaming indicators, agent status — the surfaces an agent product lives on. Install one with npx, and the code lands in your repo. No runtime dependency, nothing to keep current. Read it, change it, delete the name.", + "hero_also": "Also works with shadcn, against the same registry:", + "install_command": "npx @botharness/botui add dot-matrix", + "install_copy": "copy", + "install_copied": "copied", + "install_manual": "select it", + "components_heading": "Components", + "components_note": "Read from /registry.json — the same document the CLI installs from.", + "components_loading": "Loading the registry…", + "components_error": "Could not read /registry.json — {reason}. The registry is served from this site, so this is the site being broken rather than the component.", + "components_install": "npx @botharness/botui add {name}", + "group_shape": "shape · 形状", + "group_size": "size · 尺寸", + "group_motion": "motion · 动效", + "ctl_silhouette": "silhouette", + "ctl_sides": "sides", + "ctl_glyph": "glyph preset", + "ctl_radius": "corner radius", + "ctl_aspect": "aspect", + "ctl_size": "size", + "ctl_cols": "cols", + "ctl_rows": "rows", + "ctl_dot_cell": "dot / cell", + "ctl_gap_x": "gap x", + "ctl_gap_y": "gap y", + "ctl_preset": "preset", + "ctl_speed": "speed", + "ctl_stagger": "stagger", + "ctl_softness": "softness", + "ctl_grow": "grow", + "ctl_floor": "floor", + "ctl_reset": "reset to the preset value", + "ctl_reset_aria": "{label} — 回到预设值", + "value_preset": "preset {value}", + "value_radius": "{value}% of {max}%", + "value_speed": "{value}×", + "css_renderer": "CSS renderer", + "css_renderer_note": "0 JS per frame", + "css_refused": "This motion is a highlight moving down the field, and a per-dot delay can only offset a phase — so the CSS renderer refuses it rather than showing something else.", + "readout_dot_cell": "dot / cell", + "readout_dot_pitch": "dot / pitch", + "readout_touching": "touching at", + "readout_pitch": "pitch", + "readout_dot": "dot", + "readout_silhouette": "silhouette", + "readout_renderer": "renderer", + "readout_touching_hint": "100% = two dots touching", + "readout_touching_value": "dot / cell = {value}", + "glyph_square": "Square", + "glyph_rounded": "Rounded square", + "glyph_circle": "Circle", + "glyph_ellipse": "Ellipse", + "glyph_triangle": "Triangle", + "glyph_diamond": "Diamond", + "glyph_pentagon": "Pentagon", + "glyph_hexagon": "Hexagon", + "glyph_star4": "4-point star", + "glyph_star5": "5-point star", + "glyph_star6": "6-point star", + "glyph_burst": "Soft star", + "glyph_drop": "Teardrop", + "glyph_bar": "Bar", + "poly_triangle": "triangle", + "poly_square": "square", + "poly_pentagon": "pentagon", + "poly_hexagon": "hexagon", + "poly_heptagon": "heptagon", + "poly_octagon": "octagon", + "poly_nonagon": "nonagon", + "poly_decagon": "decagon", + "poly_gon": "{sides}-gon", + "task_thinking": "Thinking", + "task_advancing": "Advancing", + "task_serpentine": "Serpentine", + "task_expanding": "Expanding", + "task_chasing": "Chasing", + "task_sweeping": "Sweeping", + "task_column_drop": "Column drop", + "task_breathing": "Breathing", + "task_morphing": "Morphing", + "why_heading": "Why copy-and-own", + "why_own_title": "Yours after install", + "why_own_body": "The registry ships the real source files. What lands in components/botui/ is the same text as the repository, and a test in CI proves it byte for byte.", + "why_version_title": "No version to track", + "why_version_body": "There is no runtime dependency to upgrade and nothing that can break under you. When BotUI ships something better, you take the diff when you want to.", + "why_layers_title": "One component, five layers", + "why_layers_body": "Lattice, traversal, brightness envelope, dot polygon, renderer. Each is a table you can extend without touching the layers above.", + "footer_license": "MIT licensed · {repo}", + "sil_square": "square", + "sil_circle": "circle", + "sil_diamond": "diamond", + "sil_hex": "hexagon", + "sil_ring": "ring", + "sil_cross": "cross", + "readout_speed": "speed" +} diff --git a/apps/site/messages/zh.json b/apps/site/messages/zh.json new file mode 100644 index 0000000..52f4f99 --- /dev/null +++ b/apps/site/messages/zh.json @@ -0,0 +1,104 @@ +{ + "site_title": "BotUI —— 给 agent 产品的开源 UI 组件", + "site_description": "copy-and-own 的 agent 产品 UI 组件。用 npx 安装,代码归你。MIT 协议。", + "brand": "BotUI", + "nav_install": "安装", + "nav_components": "组件", + "nav_github": "GitHub", + "hero_title": "给会思考的东西用的界面组件。", + "hero_lede": "加载态、流式指示、agent 状态 —— agent 产品真正待着的那些界面。用 npx 装一个,代码直接落到你的仓库里。没有运行时依赖,不用追版本。读它、改它、把名字删掉都行。", + "hero_also": "同样支持 shadcn,用的是同一个 registry:", + "install_command": "npx @botharness/botui add dot-matrix", + "install_copy": "复制", + "install_copied": "已复制", + "install_manual": "请手动选中", + "components_heading": "组件", + "components_note": "读自 /registry.json —— 和 CLI 安装用的是同一份文档。", + "components_loading": "正在读取 registry…", + "components_error": "读不到 /registry.json —— {reason}。registry 就托管在这个站上,所以这说明是站点坏了,不是组件坏了。", + "components_install": "npx @botharness/botui add {name}", + "group_shape": "形状 shape", + "group_size": "尺寸 size", + "group_motion": "动效 motion", + "ctl_silhouette": "整体轮廓 silhouette", + "ctl_sides": "点边数 sides", + "ctl_glyph": "点预设 glyph", + "ctl_radius": "圆角 radius", + "ctl_aspect": "拉伸 aspect", + "ctl_size": "size", + "ctl_cols": "cols", + "ctl_rows": "rows", + "ctl_dot_cell": "点占格 dot/cell", + "ctl_gap_x": "列间距 gap x", + "ctl_gap_y": "行间距 gap y", + "ctl_preset": "preset", + "ctl_speed": "速度 speed", + "ctl_stagger": "错峰 stagger", + "ctl_softness": "波宽 softness", + "ctl_grow": "呼吸 grow", + "ctl_floor": "底噪 floor", + "ctl_reset": "回到预设值", + "ctl_reset_aria": "{label} —— 回到预设值", + "value_preset": "预设 {value}", + "value_radius": "{value}% / {max}%", + "value_speed": "{value}×", + "css_renderer": "CSS 渲染器", + "css_renderer_note": "零 JS 逐帧", + "css_refused": "这个动效是**移动**的高亮,而 per-dot 延迟只能偏移相位 —— 所以 CSS 渲染器会明确拒绝,而不是给你看一个别的东西。", + "readout_dot_cell": "点占格", + "readout_dot_pitch": "点占间距", + "readout_touching": "紧贴时", + "readout_pitch": "间距", + "readout_dot": "点", + "readout_silhouette": "整体形状", + "readout_renderer": "渲染器", + "readout_touching_hint": "100% = 两个点刚好贴合", + "readout_touching_value": "点占格 = {value}", + "glyph_square": "方形", + "glyph_rounded": "圆角方形", + "glyph_circle": "圆形", + "glyph_ellipse": "椭圆", + "glyph_triangle": "三角形", + "glyph_diamond": "菱形", + "glyph_pentagon": "五边形", + "glyph_hexagon": "六边形", + "glyph_star4": "四角星", + "glyph_star5": "五角星", + "glyph_star6": "六角星", + "glyph_burst": "柔角星", + "glyph_drop": "水滴", + "glyph_bar": "竖条", + "poly_triangle": "三角", + "poly_square": "方形", + "poly_pentagon": "五边", + "poly_hexagon": "六边", + "poly_heptagon": "七边", + "poly_octagon": "八边", + "poly_nonagon": "九边", + "poly_decagon": "十边", + "poly_gon": "{sides} 边形", + "task_thinking": "思考中", + "task_advancing": "逐行推进", + "task_serpentine": "逐列折返", + "task_expanding": "扩散", + "task_chasing": "追逐", + "task_sweeping": "斜扫", + "task_column_drop": "逐列下落", + "task_breathing": "呼吸", + "task_morphing": "变形", + "why_heading": "为什么是 copy-and-own", + "why_own_title": "装完就是你的", + "why_own_body": "registry 下发的是真实源码。落进 components/botui/ 的文本和仓库里逐字节相同,CI 里有测试证明。", + "why_version_title": "不用追版本", + "why_version_body": "没有运行时依赖要升级,也没有什么会在你脚下突然坏掉。BotUI 以后有更好的实现,你什么时候想拿 diff 就什么时候拿。", + "why_layers_title": "一个组件,五层", + "why_layers_body": "点阵、遍历、亮度包络、点字形、渲染器。每一层都是一张表,你可以扩展而不动它上面的层。", + "footer_license": "MIT 协议 · {repo}", + "sil_square": "方形", + "sil_circle": "圆形", + "sil_diamond": "菱形", + "sil_hex": "六边", + "sil_ring": "圆环", + "sil_cross": "十字", + "readout_speed": "速度" +} diff --git a/apps/site/package.json b/apps/site/package.json index 25e92a0..c6d9eb6 100644 --- a/apps/site/package.json +++ b/apps/site/package.json @@ -10,11 +10,13 @@ "preview": "astro preview", "check": "astro check", "deploy": "wrangler pages deploy dist --project-name botui-site", - "typecheck": "tsc --noEmit" + "typecheck": "tsc --noEmit", + "i18n:compile": "paraglide-js compile --project ./project.inlang --outdir ./src/paraglide" }, "dependencies": { "@astrojs/react": "^7.0.0", "@botharness/botui-core": "workspace:*", + "@inlang/paraglide-js": "^2.25.4", "astro": "^7.3.5", "react": "^19.3.0", "react-dom": "^19.3.0" diff --git a/apps/site/project.inlang/.gitignore b/apps/site/project.inlang/.gitignore new file mode 100644 index 0000000..4871754 --- /dev/null +++ b/apps/site/project.inlang/.gitignore @@ -0,0 +1,26 @@ +# IF GIT SHOWED THAT THIS FILE CHANGED +# +# 1. RUN THE FOLLOWING COMMAND +# +# --- +# git rm --cached '**/*.inlang/.gitignore' +# --- +# +# 2. COMMIT THE CHANGE +# +# --- +# git commit -m "fix: remove tracked .gitignore from inlang project" +# --- +# +# Inlang handles the gitignore itself starting with version ^2.5. +# +# everything is ignored except settings.json +* +!settings.json +# ...and except the compiler options. `astro.config.mjs` imports +# paraglide.options.js, so a clone without it cannot build, and the standalone +# `paraglide compile` reads paraglide.config.js to get the same values — if either +# is missing, the CLI silently falls back to Paraglide's defaults and generates a +# runtime that disagrees with the one the bundler ships. +!paraglide.config.js +!paraglide.options.js \ No newline at end of file diff --git a/apps/site/project.inlang/paraglide.config.js b/apps/site/project.inlang/paraglide.config.js new file mode 100644 index 0000000..f1a6127 --- /dev/null +++ b/apps/site/project.inlang/paraglide.config.js @@ -0,0 +1,14 @@ +/** + * The compiler options for a standalone `paraglide compile`. + * + * They live in `paraglide.options.js` because `astro.config.mjs` compiles with the + * same ones — see that file for why they must not be written twice. + */ +import { emitTsDeclarations, strategy, urlPatterns } from "./paraglide.options.js"; + +export default { + outdir: "./src/paraglide", + emitTsDeclarations, + strategy, + urlPatterns, +}; diff --git a/apps/site/project.inlang/paraglide.options.js b/apps/site/project.inlang/paraglide.options.js new file mode 100644 index 0000000..2d2b444 --- /dev/null +++ b/apps/site/project.inlang/paraglide.options.js @@ -0,0 +1,53 @@ +/** + * The Paraglide compiler options, in one place. + * + * `astro.config.mjs` and `paraglide.config.js` both need these, and they have to + * agree: the plugin runs the compiler during `astro build`, the CLI runs it when + * someone regenerates the types by hand, and a disagreement means the emitted + * `.d.ts` files describe a runtime other than the one that ships. That is not + * hypothetical — the two copies drifted once already, with the standalone config + * still claiming English lived at `/en/` while Astro had been writing it to `/`. + * A shared module makes the second copy impossible to write. + * + * `strategy` order matters: `globalVariable` has to come before `baseLocale` so + * `setLocale()` can hold the locale during a STATIC render. With no browser there is + * nothing to read `window.location` from, and the SSG middleware sets the locale + * explicitly before each page renders. + * + * The patterns are URL-prefixed, which SSG requires: `/` and `/zh/` have to be two + * different files on disk, so there is no such thing as "the same path, two + * languages" without a request to vary on. This also has to agree with + * `i18n.routing` in `astro.config.mjs`, or the language switcher links to a file + * that was never generated — a 404 only a human clicking it finds. + * @typedef {import("@inlang/paraglide-js").CompilerOptions} CompilerOptions + */ + +export const strategy = /** @type {CompilerOptions["strategy"]} */ ([ + "url", + "globalVariable", + "baseLocale", +]); + +/** + * One document per locale, so the patterns are exact. + * + * The default locale's pattern is `/`, never a catch-all. Paraglide walks + * `localized` in order and takes the first pattern that matches, so `/:path(.*)?` for + * `en` also matches `/zh/` — it captures the "zh" as a path segment — and English + * then wins every URL. That failure is invisible on the server, where the middleware + * calls `setLocale()` outright, and appears only after hydration, when every island + * flips back to English on the Chinese page while the markup around it stays + * Chinese. `test/locale-resolution.test.tsx` is what notices if a page is added here + * and forgotten. + */ +export const urlPatterns = /** @type {NonNullable} */ ([ + { + pattern: "/:path(.*)?", + localized: [ + ["en", "/"], + ["zh", "/zh/"], + ], + }, +]); + +export const emitTsDeclarations = /** @type {CompilerOptions["emitTsDeclarations"]} */ (true); diff --git a/apps/site/project.inlang/settings.json b/apps/site/project.inlang/settings.json new file mode 100644 index 0000000..d7beaa0 --- /dev/null +++ b/apps/site/project.inlang/settings.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://inlang.com/schema/project-settings", + "sourceLanguageTag": "en", + "languageTags": ["en", "zh"], + "modules": [ + "https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-missing-translation@latest/dist/index.js", + "https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-identical-pattern@latest/dist/index.js", + "https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4.4.0/dist/index.js", + "https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2.2.6/dist/index.js" + ], + "plugin.inlang.messageFormat": { + "pathPattern": "./messages/{languageTag}.json" + } +} diff --git a/apps/site/src/components/Home.astro b/apps/site/src/components/Home.astro new file mode 100644 index 0000000..909f3c9 --- /dev/null +++ b/apps/site/src/components/Home.astro @@ -0,0 +1,89 @@ +--- +import Base from '../layouts/Base.astro'; +import { InstallCommand } from './InstallCommand'; +import { Playground } from './Playground'; +import { RegistryList } from './RegistryList'; +import LocaleSwitch from './LocaleSwitch.astro'; +import { m } from '../paraglide/messages.js'; +import { localizeHref, locales } from '../paraglide/runtime.js'; + +/** + * The whole page, shared by both locales. + * + * The locale is NOT read from the URL here: the middleware has already called + * `setLocale()` before this renders, so `m.*` resolves correctly. That is what lets + * one body serve `/` (English) and `/zh/` (Chinese) — there is no second copy to + * drift, which is the failure mode a duplicated page has. + */ +const locale = Astro.currentLocale ?? 'en'; +const path = Astro.url.pathname; +--- + + +
+ {m.brand()} + +
+ +
+
+

{m.hero_title()}

+

{m.hero_lede()}

+ +

+ {m.hero_also()} + npx shadcn@latest add https://ui.botharness.ai/r/dot-matrix.json +

+
+ + +
+ +
+ +
+

{m.components_heading()}

+

{m.components_note()}

+ +
+ +
+

{m.why_heading()}

+
+
+

{m.why_own_title()}

+

{m.why_own_body()}

+
+
+

{m.why_version_title()}

+

{m.why_version_body()}

+
+
+

{m.why_layers_title()}

+

{m.why_layers_body()}

+
+
+
+
+ +
+

{m.footer_license({ repo: 'BotHarness/BotUI' })}

+
+ + +{ + locales.map((l) => ( + + )) +} + diff --git a/apps/site/src/components/InstallCommand.tsx b/apps/site/src/components/InstallCommand.tsx index 43524ef..c91dd7d 100644 --- a/apps/site/src/components/InstallCommand.tsx +++ b/apps/site/src/components/InstallCommand.tsx @@ -1,4 +1,5 @@ import { useState } from "react"; +import { m } from "../i18n.js"; /** * The install command, with a copy button. @@ -9,6 +10,12 @@ import { useState } from "react"; */ export function InstallCommand({ command }: { command: string }) { const [state, setState] = useState<"idle" | "copied" | "manual">("idle"); + const label = + state === "copied" + ? m.install_copied() + : state === "manual" + ? m.install_manual() + : m.install_copy(); return (
@@ -25,7 +32,7 @@ export function InstallCommand({ command }: { command: string }) { setTimeout(() => setState("idle"), 1800); }} > - {state === "copied" ? "copied" : state === "manual" ? "select it" : "copy"} + {label}
); diff --git a/apps/site/src/components/LocaleSwitch.astro b/apps/site/src/components/LocaleSwitch.astro new file mode 100644 index 0000000..a460b1c --- /dev/null +++ b/apps/site/src/components/LocaleSwitch.astro @@ -0,0 +1,28 @@ +--- +/** + * The language switcher. + * + * A plain `` to the sibling locale's page, not a button that calls setLocale(). + * Both locales are real files in the output, so the link works with JavaScript + * disabled and is crawlable — and a client-side toggle would swap the text without + * moving the URL, which is worse for sharing a page and impossible to bookmark. + */ +import { localizeHref, locales } from '../paraglide/runtime.js'; + +interface Props { + current: string; + path: string; +} + +const { current, path } = Astro.props; +const others = locales.filter((l) => l !== current); +const LABELS: Record = { en: 'EN', zh: '中文' }; +--- + +{ + others.map((l) => ( + + {LABELS[l] ?? l} + + )) +} diff --git a/apps/site/src/components/Playground.tsx b/apps/site/src/components/Playground.tsx index 94de046..9e7d431 100644 --- a/apps/site/src/components/Playground.tsx +++ b/apps/site/src/components/Playground.tsx @@ -17,6 +17,7 @@ import { type PresetName, type Silhouette, } from "@botharness/botui-core"; +import { m, glyphLabel, polygonName, silhouetteLabel, taskLabel } from "../i18n.js"; import { Matrix } from "./Matrix"; /** @@ -91,27 +92,27 @@ export function Playground() {
- + set({ silhouette: SILHOUETTE_KEYS[i] as Silhouette })} /> setSpec({ sides: n })} /> set({ preset: preset as PresetName })} options={PRESET_KEYS.map((key) => ({ value: key, label: key }))} /> set({ speed })} /> {/* The label states the preset's OWN number rather than the word "preset": @@ -226,16 +230,24 @@ export function Playground() { back to following the preset — a dial you can leave but not return to is a trap, and switching the preset no longer moves this one. */} set({ stagger: null })} onChange={(stagger) => set({ stagger })} /> set({ softness: v / 100 })} /> set({ grow: v / 100 })} /> setCssRenderer(e.target.checked)} /> - CSS renderer 0 JS per frame + {m.css_renderer()} {m.css_renderer_note()} - {!cssAvailable && ( -

- This motion is a highlight moving down the field, and a per-dot delay can only - offset a phase — so the CSS renderer refuses it rather than showing something else. -

- )} + {!cssAvailable &&

{m.css_refused()}

}
         {[
-          `dot / cell   ${Math.round((options.dotSize ?? 0) * 100)}%`,
-          `dot / pitch  ${Math.round(pitchShare * 100)}%    100% = two dots touching`,
-          `touching at  dot / cell = ${touching.toFixed(2)}`,
-          `pitch        ${geometry.pitchX.toFixed(1)} × ${geometry.pitchY.toFixed(1)} px`,
-          `dot          ${geometry.dotPx.toFixed(1)} px`,
-          `silhouette   ${options.silhouette}   dot ${POLYGON_NAMES[sides] ?? `${sides}-gon`}`,
-          `renderer     ${cssRenderer ? "css" : "svg"}   speed ${(options.speed ?? 1).toFixed(2)}×`,
+          `${m.readout_dot_cell()}   ${Math.round((options.dotSize ?? 0) * 100)}%`,
+          `${m.readout_dot_pitch()}  ${Math.round(pitchShare * 100)}%    ${m.readout_touching_hint()}`,
+          `${m.readout_touching()}  ${m.readout_touching_value({ value: touching.toFixed(2) })}`,
+          `${m.readout_pitch()}        ${geometry.pitchX.toFixed(1)} × ${geometry.pitchY.toFixed(1)} px`,
+          `${m.readout_dot()}          ${geometry.dotPx.toFixed(1)} px`,
+          `${m.readout_silhouette()}   ${silhouetteLabel(options.silhouette ?? "square")}   dot ${polygonName(sides)}`,
+          `${m.readout_renderer()}     ${cssRenderer ? "css" : "svg"}   ${m.readout_speed()} ${m.value_speed({ value: (options.speed ?? 1).toFixed(2) })}`,
         ].join("\n")}
       
); } -const POLYGON_NAMES: Record = { - 3: "triangle 三角", - 4: "square 方", - 5: "pentagon 五边", - 6: "hexagon 六边", - 7: "heptagon 七边", - 8: "octagon 八边", - 9: "nonagon 九边", - 10: "decagon 十边", -}; - const percent = (v: number) => percentOf(v); const percentOf = (v: number) => `${Math.round(v * 100)}%`; @@ -431,8 +427,8 @@ function Slider({