From f51bcde41c6df2be8c1da51f60f0f1f8aa0138af Mon Sep 17 00:00:00 2001 From: DoodleBear Date: Wed, 30 Sep 2026 06:58:36 +0900 Subject: [PATCH 1/3] feat: the site speaks both languages, at / and /zh/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit English at `/`, Chinese at `/zh/`, from Paraglide catalogs in `apps/site/messages/`. The switch is a link to the other locale's FILE, not a client-side toggle: SSG means two documents, so a toggle that rewrites the DOM would leave /zh/ unreachable without JavaScript and uncrawlable. One document per locale, not one document that varies. `src/pages/index.astro` became `src/components/Home.astro` and `src/pages/[locale]/index.astro` renders it per locale, because a second copy of the body is a second thing to drift. `src/i18n.ts` keeps the engine's key names — `square`, `spiral`, `thinking` — and translates on top of them. Those names are what a component saved as `dot: 'star5'` carries, so the copy belongs in the site and not in the engine; `preset.task` stays English in the core for the same reason, with the translated copy keyed off the preset name here. `pnpm i18n` compiles the catalogs, and `typecheck`/`verify` run it first: `apps/site/src/paraglide` is generated and gitignored, so from a clean clone both used to fail on imports that were not on disk yet. --- .gitignore | 1 + AGENTS.md | 3 +- CHANGELOG.md | 8 + CHANGELOG.zh.md | 7 + README.md | 5 +- apps/site/astro.config.mjs | 50 +- apps/site/messages/en.json | 104 ++++ apps/site/messages/zh.json | 104 ++++ apps/site/package.json | 4 +- apps/site/project.inlang/.gitignore | 26 + apps/site/project.inlang/paraglide.config.js | 26 + apps/site/project.inlang/settings.json | 14 + apps/site/src/components/Home.astro | 89 +++ apps/site/src/components/InstallCommand.tsx | 9 +- apps/site/src/components/LocaleSwitch.astro | 28 + apps/site/src/components/Playground.tsx | 104 ++-- apps/site/src/components/RegistryList.tsx | 14 +- apps/site/src/i18n.ts | 105 ++++ apps/site/src/layouts/Base.astro | 7 +- apps/site/src/middleware.ts | 21 + apps/site/src/pages/[locale]/index.astro | 20 + apps/site/src/pages/index.astro | 89 +-- apps/site/test/i18n.test.ts | 105 ++++ apps/site/test/playground.test.tsx | 12 +- package.json | 5 +- pnpm-lock.yaml | 594 ++++++++++++++++++- scripts/site.test.ts | 35 +- 27 files changed, 1397 insertions(+), 192 deletions(-) create mode 100644 apps/site/messages/en.json create mode 100644 apps/site/messages/zh.json create mode 100644 apps/site/project.inlang/.gitignore create mode 100644 apps/site/project.inlang/paraglide.config.js create mode 100644 apps/site/project.inlang/settings.json create mode 100644 apps/site/src/components/Home.astro create mode 100644 apps/site/src/components/LocaleSwitch.astro create mode 100644 apps/site/src/i18n.ts create mode 100644 apps/site/src/middleware.ts create mode 100644 apps/site/src/pages/[locale]/index.astro create mode 100644 apps/site/test/i18n.test.ts 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..30a3d7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,14 @@ All notable changes to BotUI are recorded here. The format follows 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 - **Three playground sliders were broken in the same way, and none of the tests could see diff --git a/CHANGELOG.zh.md b/CHANGELOG.zh.md index 4b5a090..4817047 100644 --- a/CHANGELOG.zh.md +++ b/CHANGELOG.zh.md @@ -30,6 +30,13 @@ BotUI 的所有值得注意的变更都记录在此。格式遵循 - `apps/site/test/playground.test.tsx` 驱动真实控件:10 个测试派发 input 事件并断言场确实变了。 一个渲染出来但不干活的滑杆,在截图和 DOM dump 里和一个正常工作的滑杆无法区分。 +- **站点现在支持双语。** 英文在 `/`,中文在 `/zh/`,文案来自 `apps/site/messages/` 下的 Paraglide + 消息目录;两个语言之间是真实链接,页面带各自的 `hreflang`,`` 与文案一致。切换器 + 指向另一个语言的**文件**,而不是客户端 toggle —— 这样关掉 JavaScript 也能到达 `/zh/`,搜索引擎 + 也能抓到。 +- `pnpm i18n` 编译消息目录。`apps/site/src/paraglide` 是生成产物且被 gitignore,因此 `typecheck` + 和 `verify` 现在会先跑这一步:全新 clone 时它们原本会因为引用尚不存在的文件而失败。 + ### 修复 - **三个 playground 滑杆以同一种方式坏掉,而当时的测试全都看不出来。** `radius`、`aspect`、 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..50c2f62 100644 --- a/apps/site/astro.config.mjs +++ b/apps/site/astro.config.mjs @@ -1,6 +1,7 @@ // @ts-check import { defineConfig } from "astro/config"; import react from "@astrojs/react"; +import { paraglideVitePlugin } from "@inlang/paraglide-js"; /** * Static output, no adapter. @@ -8,22 +9,51 @@ 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 are given EXPLICITLY here rather than left to + // project.inlang/paraglide.config.js, because the CLI and the plugin must + // produce identical output — a `pnpm paraglide compile` that disagrees with + // `astro build` means the type declarations describe a different runtime + // than the one that ships. + paraglideVitePlugin({ + project: "./project.inlang", + outdir: "./src/paraglide", + emitTsDeclarations: true, + // `globalVariable` must come before `baseLocale` so setLocale() can hold the + // locale during a STATIC render — there is no browser to read a URL from + strategy: ["url", "globalVariable", "baseLocale"], + urlPatterns: [ + { + pattern: "/:path(.*)?", + localized: [ + ["en", "/:path(.*)?"], + ["zh", "/zh/:path(.*)?"], + ], + }, + ], + }), + ], }, }); 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..09a3d38 --- /dev/null +++ b/apps/site/project.inlang/paraglide.config.js @@ -0,0 +1,26 @@ +/** + * Paraglide compiler options, read from here by the CLI and by every bundler plugin. + * + * `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. + * + * Every locale is URL-prefixed, which SSG requires: `/en/` 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. + */ +export default { + outdir: "./src/paraglide", + emitTsDeclarations: true, + strategy: ["url", "globalVariable", "baseLocale"], + urlPatterns: [ + { + pattern: "/:path(.*)?", + localized: [ + ["en", "/en/:path(.*)?"], + ["zh", "/zh/:path(.*)?"], + ], + }, + ], +}; 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({