Skip to content

Commit 654b4aa

Browse files
committed
refactor: enforce English-only comments and strings in codebase for consistency
1 parent 5c65f7c commit 654b4aa

5 files changed

Lines changed: 95 additions & 13 deletions

File tree

‎CLAUDE.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ E2E 在 CI 中依赖 `lint` job 成功后才运行(`needs: lint`)。本地
168168

169169
## 代码规范
170170

171+
- **注释与代码内字符串一律英文**:主体语言是英文,包括行内注释、JSDoc、`it()` /
172+
`describe()` 测试标题、以及代码里拼出来的 UI 文案。标点也用 ASCII(`(` 而不是 `(`)。
173+
中文只允许出现在这几处:`packages/shared/src/i18n.ts` 的 zh-CN 词条、
174+
`public/zh-CN/**` 的中文落地页、语言切换器里的 `中文` 自称标签、双语 `public/404.html`
175+
的那一行,以及 `docs/**` 与本文件。共用页面(如 `public/embed-demo.html`,英文和中文落地页
176+
都链到它)必须用英文。复查见
177+
[docs/explorations/2026-07-25-english-first-comments.md](docs/explorations/2026-07-25-english-first-comments.md)。
171178
- **Lint**:oxlint(规则见 `.oxlintrc.json`)+ TypeScript 6 严格模式
172179
- **格式化**:prettier(配置见 `.prettierrc.json`)
173180
- **TypeScript**:`strict: true`,`noImplicitAny: true`,目标 ESNext,模块解析 bundler
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# 注释/代码内文案统一英文(i18n 与语言切换器除外)
2+
3+
日期:2026-07-25
4+
分支:feat/premium-ui
5+
涉及:`packages/converter/src/docx-zip.ts`、`test/unit/docx-zip.test.ts`、
6+
`packages/agent-core/src/llm/webllm.ts`、`lib/agent-plugin/ui/panel.ts`、
7+
`public/embed-demo.html`、`CLAUDE.md`
8+
9+
## 问题(用户指出)
10+
11+
项目注释应优先使用英文,主体是英文,只有真正的多语言内容才用其他语言。
12+
实际扫描发现代码里残留中文的地方有三类,其中两类是真问题。
13+
14+
扫描方式(后续复查同样可用):
15+
16+
```bash
17+
rg -l '[\p{Han}]' -g '*.{ts,tsx,js,mjs,cjs,css,sh,html,yml,yaml}' \
18+
-g '!public/{sdkjs,web-apps,wasm,libs}/**'
19+
# 全角标点单独查一遍(em-dash 会误报,要排除)
20+
rg -n '[()「」,。、:;!?]' -g '*.{ts,tsx,js,html}' ...
21+
```
22+
23+
## 三类中文,只有前两类要改
24+
25+
**1. 纯中文注释 —— 改**
26+
27+
- `packages/converter/src/docx-zip.ts`:文件头 ZIP/OOXML 说明、`rewriteXmlEntries`
28+
的 JSDoc、媒体目录与 `readZipEntry` 返回 null 的两处行内注释
29+
- `test/unit/docx-zip.test.ts`:文件头测试策略说明、`FixtureEntry` 字段 JSDoc、
30+
`buildZip` 说明、流式写入器注释、`beforeAll` 里的 jsdom 说明,以及 **12 个
31+
`it()` 标题**(测试标题是失败输出里的开发者可读文案,同样算注释范畴)
32+
33+
**2. 硬编码进代码的中文 UI 文案 —— 改(这是真 bug,不只是风格)**
34+
35+
- `packages/agent-core/src/llm/webllm.ts`:`WEBLLM_MODELS` 的两个 label 带
36+
`(推荐,工具最佳)`/`(最小)`。这些没走 i18n,**所有语言的用户**在 agent
37+
面板的模型下拉里都会看到中文注解。改为 `(recommended, best at tools)` /
38+
`(smallest)`。
39+
- `lib/agent-plugin/ui/panel.ts:174`:拼接下拉 label 时用了全角括号
40+
`${model.label}(${model.size})`,同理改 ASCII 括号。
41+
- `public/embed-demo.html`:整页中文,但它是**英文落地页和中文落地页共用的同一个
42+
demo**(`public/embed-document-editor.html` 的 "Open the live demo →" 和
43+
`public/zh-CN/embed-document-editor.html` 的"打开在线 demo →"都指向它)。
44+
英文用户点进来看到满屏中文。整页改英文并把 `<html lang>` 从 `zh-CN` 改成 `en`,
45+
示例 Excel 数据(表头/客户名/状态/sheet 名)一并英文化。
46+
47+
**3. 合法的多语言内容 —— 不动**
48+
49+
- `packages/shared/src/i18n.ts` 的 zh-CN 词条、`test/unit/i18n.test.ts` 里断言
50+
zh-CN 译文的那一行
51+
- 各页面语言切换器里的 `<r-option value="zh-CN">中文</r-option>`(含
52+
`public/lang-switch.js` 注释里的示例 markup)——语言名用其自身写法(endonym)
53+
是正确做法,翻成 "Chinese" 反而是退步
54+
- `public/404.html`:刻意的双语兜底页(英文为主体 + 一行 `.nf-zh` 中文),
55+
因为单个 404 同时服务两个 locale
56+
- `docs/**`、`CLAUDE.md`:中文文档是项目约定(与"对话中文、commit 英文"一致),
57+
本轮不在范围内
58+
59+
## 规范落地
60+
61+
在 `CLAUDE.md` 的「代码规范」里补了一条,避免下次又漂回去:注释与代码内字符串
62+
默认英文;中文只出现在 i18n 词条、`public/zh-CN/**`、语言切换器 endonym、
63+
双语 404 与 `docs/**`。
64+
65+
## 验证
66+
67+
- `format:check` / `lint:ts` 全过
68+
- 20 个测试文件 252 个单测全过(改的是 `it()` 标题与注释,无行为变更)
69+
- 逐一复查残留中文:只剩 12 处语言切换器的 `中文` 标签,全部符合预期

‎public/home.css‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
--ink-2: var(--ran-color-text-secondary);
1919
--muted: var(--ran-gray-800);
2020
--rule: var(--ran-color-border);
21-
/* Blue accent. ranui 0.4 repurposed --ran-color-primary as the monochrome action
22-
colour (near-black ↔ near-white); the blue lives in --ran-color-link. */
23-
--accent: var(--ran-color-link);
2421
--signal: var(--ran-color-success);
2522
/* editor-selection ground: theme-flipped by ran-tokens (light #dfefff / dark #002f62) */
2623
--sel: var(--ran-blue-300);
@@ -378,13 +375,15 @@
378375
box-decoration-break: clone;
379376
-webkit-box-decoration-break: clone;
380377
}
378+
/* A text caret is ink, not an accent — matching what the mocked-up editor would really show.
379+
The selection ground below stays blue, because that is what a real editor's selection is. */
381380
#landing-hero .dw-text .caret {
382381
display: inline-block;
383382
width: 2px;
384383
height: 1.05em;
385384
margin-left: 1px;
386385
vertical-align: -0.15em;
387-
background: var(--accent);
386+
background: var(--ran-color-text);
388387
}
389388
/* margin annotation, styled like a review comment */
390389
#landing-hero .dw-note {
@@ -540,11 +539,15 @@
540539
#landing-hero .formats .card-body p {
541540
font-size: 13.5px;
542541
}
542+
/* The whole card is the <a>; this is its affordance label, not an inline prose link — the
543+
arrow and the bold mono face already carry that. Rendering it blue while the card title
544+
inside the *same* anchor stays ink would mean blue is decoration here, not link semantics,
545+
which is exactly what ranui's design standard reserves blue against. */
543546
#landing-hero .fmt-go {
544547
display: inline-block;
545548
margin-top: var(--ran-space-4);
546549
font: 600 12.5px/1 var(--mono);
547-
color: var(--accent);
550+
color: var(--ran-color-text);
548551
}
549552
@media (max-width: 900px) {
550553
#landing-hero .formats {
@@ -792,6 +795,8 @@
792795
}
793796

794797
/* live caret in the document window */
798+
/* A text caret is ink, not an accent — matching what the mocked-up editor would really show.
799+
The selection ground below stays blue, because that is what a real editor's selection is. */
795800
#landing-hero .dw-text .caret {
796801
animation: lh-blink 1.1s steps(2, start) infinite;
797802
}

‎public/landing.css‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
--ink-2: var(--ran-color-text-secondary);
1717
--muted: var(--ran-gray-800);
1818
--rule: var(--ran-color-border);
19-
/* Blue accent. ranui 0.4 repurposed --ran-color-primary as the monochrome action
20-
colour (near-black ↔ near-white); the blue lives in --ran-color-link. */
21-
--accent: var(--ran-color-link);
19+
/* Named --link, not --accent: it feeds only `a {}` and the focus ring, which are the two
20+
places ranui's design standard reserves blue for. Everything else on the page is
21+
monochrome by design. */
22+
--link: var(--ran-color-link);
2223
--signal: var(--ran-color-success);
2324
--sans: var(--ran-font-family);
2425
--mono: var(--ran-font-mono);
@@ -34,10 +35,10 @@ body {
3435
text-rendering: optimizeLegibility;
3536
}
3637
a {
37-
color: var(--accent);
38+
color: var(--link);
3839
}
3940
a:focus-visible {
40-
outline: 2px solid var(--accent);
41+
outline: 2px solid var(--link);
4142
outline-offset: 2px;
4243
}
4344

‎styles/base.css‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ r-button[type='text']::part(content) {
235235
backdrop-filter: blur(2px);
236236
}
237237
.loading-mask r-loading {
238-
/* Accent spinner. ranui 0.4 repurposed --ran-color-primary as the monochrome
239-
action colour; the blue accent now lives in --ran-color-link. */
240-
color: var(--ran-color-link);
238+
/* Monochrome, per ranui's design standard: blue is reserved for links and the focus
239+
ring; a loading indicator is neither. --ran-color-primary flips with the theme. */
240+
color: var(--ran-color-primary);
241241
font-size: 24px;
242242
}
243243

0 commit comments

Comments
 (0)