Skip to content

Commit f2b4a23

Browse files
kangfenmaoclaude
andauthored
refactor: rename i18n commands for better consistency (CherryHQ#11938)
* refactor: rename i18n commands for better consistency - Rename `check:i18n` to `i18n:check` - Rename `sync:i18n` to `i18n:sync` - Rename `update:i18n` to `i18n:translate` (clearer purpose) - Rename `auto:i18n` to `i18n:all` (runs check, sync, and translate) - Update lint script to use new `i18n:check` command name This follows the common naming convention of grouping related commands under a namespace prefix (e.g., `test:main`, `test:renderer`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> * refactor: update i18n command names and improve documentation - Renamed i18n commands for consistency: `sync:i18n` to `i18n:sync`, `check:i18n` to `i18n:check`, and `auto:i18n` to `i18n:translate`. - Updated relevant documentation and scripts to reflect new command names. - Improved formatting and clarity in i18n-related guides and scripts. This change enhances the clarity and usability of i18n commands across the project. --------- Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent b667872 commit f2b4a23

File tree

8 files changed

+65
-82
lines changed

8 files changed

+65
-82
lines changed

.github/workflows/auto-i18n.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
yarn install
5555
5656
- name: 🏃‍♀️ Translate
57-
run: yarn sync:i18n && yarn auto:i18n
57+
run: yarn i18n:sync && yarn i18n:translate
5858

5959
- name: 🔍 Format
6060
run: yarn format

.github/workflows/pr-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
run: yarn typecheck
5959

6060
- name: i18n Check
61-
run: yarn check:i18n
61+
run: yarn i18n:check
6262

6363
- name: Test
6464
run: yarn test

CLAUDE.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ When creating a Pull Request, you MUST:
2828
- **Development**: `yarn dev` - Runs Electron app in development mode with hot reload
2929
- **Debug**: `yarn debug` - Starts with debugging enabled, use `chrome://inspect` to attach debugger
3030
- **Build Check**: `yarn build:check` - **REQUIRED** before commits (lint + test + typecheck)
31-
- If having i18n sort issues, run `yarn sync:i18n` first to sync template
31+
- If having i18n sort issues, run `yarn i18n:sync` first to sync template
3232
- If having formatting issues, run `yarn format` first
3333
- **Test**: `yarn test` - Run all tests (Vitest) across main and renderer processes
3434
- **Single Test**:
@@ -40,20 +40,23 @@ When creating a Pull Request, you MUST:
4040
## Project Architecture
4141

4242
### Electron Structure
43+
4344
- **Main Process** (`src/main/`): Node.js backend with services (MCP, Knowledge, Storage, etc.)
4445
- **Renderer Process** (`src/renderer/`): React UI with Redux state management
4546
- **Preload Scripts** (`src/preload/`): Secure IPC bridge
4647

4748
### Key Components
49+
4850
- **AI Core** (`src/renderer/src/aiCore/`): Middleware pipeline for multiple AI providers.
4951
- **Services** (`src/main/services/`): MCPService, KnowledgeService, WindowService, etc.
5052
- **Build System**: Electron-Vite with experimental rolldown-vite, yarn workspaces.
5153
- **State Management**: Redux Toolkit (`src/renderer/src/store/`) for predictable state.
5254

5355
### Logging
56+
5457
```typescript
55-
import { loggerService } from '@logger'
56-
const logger = loggerService.withContext('moduleName')
58+
import { loggerService } from "@logger";
59+
const logger = loggerService.withContext("moduleName");
5760
// Renderer: loggerService.initWindowSource('windowName') first
58-
logger.info('message', CONTEXT)
61+
logger.info("message", CONTEXT);
5962
```

docs/en/guides/i18n.md

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Tools like i18n Ally cannot parse dynamic content within template strings, resul
7171

7272
```javascript
7373
// Not recommended - Plugin cannot resolve
74-
const message = t(`fruits.${fruit}`)
74+
const message = t(`fruits.${fruit}`);
7575
```
7676

7777
#### 2. **No Real-time Rendering in Editor**
@@ -91,14 +91,14 @@ For example:
9191
```ts
9292
// src/renderer/src/i18n/label.ts
9393
const themeModeKeyMap = {
94-
dark: 'settings.theme.dark',
95-
light: 'settings.theme.light',
96-
system: 'settings.theme.system'
97-
} as const
94+
dark: "settings.theme.dark",
95+
light: "settings.theme.light",
96+
system: "settings.theme.system",
97+
} as const;
9898

9999
export const getThemeModeLabel = (key: string): string => {
100-
return themeModeKeyMap[key] ? t(themeModeKeyMap[key]) : key
101-
}
100+
return themeModeKeyMap[key] ? t(themeModeKeyMap[key]) : key;
101+
};
102102
```
103103

104104
By avoiding template strings, you gain better developer experience, more reliable translation checks, and a more maintainable codebase.
@@ -107,7 +107,7 @@ By avoiding template strings, you gain better developer experience, more reliabl
107107

108108
The project includes several scripts to automate i18n-related tasks:
109109

110-
### `check:i18n` - Validate i18n Structure
110+
### `i18n:check` - Validate i18n Structure
111111

112112
This script checks:
113113

@@ -116,10 +116,10 @@ This script checks:
116116
- Whether keys are properly sorted
117117

118118
```bash
119-
yarn check:i18n
119+
yarn i18n:check
120120
```
121121

122-
### `sync:i18n` - Synchronize JSON Structure and Sort Order
122+
### `i18n:sync` - Synchronize JSON Structure and Sort Order
123123

124124
This script uses `zh-cn.json` as the source of truth to sync structure across all language files, including:
125125

@@ -128,14 +128,14 @@ This script uses `zh-cn.json` as the source of truth to sync structure across al
128128
3. Sorting keys automatically
129129

130130
```bash
131-
yarn sync:i18n
131+
yarn i18n:sync
132132
```
133133

134-
### `auto:i18n` - Automatically Translate Pending Texts
134+
### `i18n:translate` - Automatically Translate Pending Texts
135135

136136
This script fills in texts marked as `[to be translated]` using machine translation.
137137

138-
Typically, after adding new texts in `zh-cn.json`, run `sync:i18n`, then `auto:i18n` to complete translations.
138+
Typically, after adding new texts in `zh-cn.json`, run `i18n:sync`, then `i18n:translate` to complete translations.
139139

140140
Before using this script, set the required environment variables:
141141

@@ -148,30 +148,20 @@ MODEL="qwen-plus-latest"
148148
Alternatively, add these variables directly to your `.env` file.
149149

150150
```bash
151-
yarn auto:i18n
152-
```
153-
154-
### `update:i18n` - Object-level Translation Update
155-
156-
Updates translations in language files under `src/renderer/src/i18n/translate` at the object level, preserving existing translations and only updating new content.
157-
158-
**Not recommended** — prefer `auto:i18n` for translation tasks.
159-
160-
```bash
161-
yarn update:i18n
151+
yarn i18n:translate
162152
```
163153

164154
### Workflow
165155

166156
1. During development, first add the required text in `zh-cn.json`
167157
2. Confirm it displays correctly in the Chinese environment
168-
3. Run `yarn sync:i18n` to propagate the keys to other language files
169-
4. Run `yarn auto:i18n` to perform machine translation
158+
3. Run `yarn i18n:sync` to propagate the keys to other language files
159+
4. Run `yarn i18n:translate` to perform machine translation
170160
5. Grab a coffee and let the magic happen!
171161

172162
## Best Practices
173163

174164
1. **Use Chinese as Source Language**: All development starts in Chinese, then translates to other languages.
175-
2. **Run Check Script Before Commit**: Use `yarn check:i18n` to catch i18n issues early.
165+
2. **Run Check Script Before Commit**: Use `yarn i18n:check` to catch i18n issues early.
176166
3. **Translate in Small Increments**: Avoid accumulating a large backlog of untranslated content.
177167
4. **Keep Keys Semantically Clear**: Keys should clearly express their purpose, e.g., `user.profile.avatar.upload.error`

docs/zh/guides/i18n.md

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# 如何优雅地做好 i18n
22

3-
## 使用i18n ally插件提升开发体验
3+
## 使用 i18n ally 插件提升开发体验
44

5-
i18n ally是一个强大的VSCode插件,它能在开发阶段提供实时反馈,帮助开发者更早发现文案缺失和错译问题。
5+
i18n ally 是一个强大的 VSCode 插件,它能在开发阶段提供实时反馈,帮助开发者更早发现文案缺失和错译问题。
66

77
项目中已经配置好了插件设置,直接安装即可。
88

99
### 开发时优势
1010

1111
- **实时预览**:翻译文案会直接显示在编辑器中
12-
- **错误检测**自动追踪标记出缺失的翻译或未使用的key
13-
- **快速跳转**可通过key直接跳转到定义处(Ctrl/Cmd + click)
14-
- **自动补全**输入i18n key时提供自动补全建议
12+
- **错误检测**自动追踪标记出缺失的翻译或未使用的 key
13+
- **快速跳转**可通过 key 直接跳转到定义处(Ctrl/Cmd + click)
14+
- **自动补全**输入 i18n key 时提供自动补全建议
1515

1616
### 效果展示
1717

@@ -23,9 +23,9 @@ i18n ally是一个强大的VSCode插件,它能在开发阶段提供实时反
2323

2424
## i18n 约定
2525

26-
### **绝对避免使用flat格式**
26+
### **绝对避免使用 flat 格式**
2727

28-
绝对避免使用flat格式,如`"add.button.tip": "添加"`。应采用清晰的嵌套结构:
28+
绝对避免使用 flat 格式,如`"add.button.tip": "添加"`。应采用清晰的嵌套结构:
2929

3030
```json
3131
// 错误示例 - flat结构
@@ -52,26 +52,26 @@ i18n ally是一个强大的VSCode插件,它能在开发阶段提供实时反
5252
#### 为什么要使用嵌套结构
5353

5454
1. **自然分组**:通过对象结构天然能将相关上下文的文案分到一个组别中
55-
2. **插件要求**:i18n ally 插件需要嵌套或flat格式其一的文件才能正常分析
55+
2. **插件要求**:i18n ally 插件需要嵌套或 flat 格式其一的文件才能正常分析
5656

5757
### **避免在`t()`中使用模板字符串**
5858

59-
**强烈建议避免使用模板字符串**进行动态插值。虽然模板字符串在JavaScript开发中非常方便,但在国际化场景下会带来一系列问题。
59+
**强烈建议避免使用模板字符串**进行动态插值。虽然模板字符串在 JavaScript 开发中非常方便,但在国际化场景下会带来一系列问题。
6060

6161
1. **插件无法跟踪**
62-
i18n ally等工具无法解析模板字符串中的动态内容,导致:
62+
i18n ally 等工具无法解析模板字符串中的动态内容,导致:
6363

6464
- 无法正确显示实时预览
6565
- 无法检测翻译缺失
6666
- 无法提供跳转到定义的功能
6767

6868
```javascript
6969
// 不推荐 - 插件无法解析
70-
const message = t(`fruits.${fruit}`)
70+
const message = t(`fruits.${fruit}`);
7171
```
7272

7373
2. **编辑器无法实时渲染**
74-
在IDE中,模板字符串会显示为原始代码而非最终翻译结果,降低了开发体验。
74+
在 IDE 中,模板字符串会显示为原始代码而非最终翻译结果,降低了开发体验。
7575

7676
3. **更难以维护**
7777
由于插件无法跟踪这样的文案,编辑器中也无法渲染,开发者必须人工确认语言文件中是否存在相应的文案。
@@ -85,36 +85,36 @@ i18n ally是一个强大的VSCode插件,它能在开发阶段提供实时反
8585
```ts
8686
// src/renderer/src/i18n/label.ts
8787
const themeModeKeyMap = {
88-
dark: 'settings.theme.dark',
89-
light: 'settings.theme.light',
90-
system: 'settings.theme.system'
91-
} as const
88+
dark: "settings.theme.dark",
89+
light: "settings.theme.light",
90+
system: "settings.theme.system",
91+
} as const;
9292

9393
export const getThemeModeLabel = (key: string): string => {
94-
return themeModeKeyMap[key] ? t(themeModeKeyMap[key]) : key
95-
}
94+
return themeModeKeyMap[key] ? t(themeModeKeyMap[key]) : key;
95+
};
9696
```
9797

9898
通过避免模板字符串,可以获得更好的开发体验、更可靠的翻译检查以及更易维护的代码库。
9999

100100
## 自动化脚本
101101

102-
项目中有一系列脚本来自动化i18n相关任务
102+
项目中有一系列脚本来自动化 i18n 相关任务
103103

104-
### `check:i18n` - 检查i18n结构
104+
### `i18n:check` - 检查 i18n 结构
105105

106106
此脚本会检查:
107107

108108
- 所有语言文件是否为嵌套结构
109-
- 是否存在缺失的key
110-
- 是否存在多余的key
109+
- 是否存在缺失的 key
110+
- 是否存在多余的 key
111111
- 是否已经有序
112112

113113
```bash
114-
yarn check:i18n
114+
yarn i18n:check
115115
```
116116

117-
### `sync:i18n` - 同步json结构与排序
117+
### `i18n:sync` - 同步 json 结构与排序
118118

119119
此脚本以`zh-cn.json`文件为基准,将结构同步到其他语言文件,包括:
120120

@@ -123,14 +123,14 @@ yarn check:i18n
123123
3. 自动排序
124124

125125
```bash
126-
yarn sync:i18n
126+
yarn i18n:sync
127127
```
128128

129-
### `auto:i18n` - 自动翻译待翻译文本
129+
### `i18n:translate` - 自动翻译待翻译文本
130130

131131
次脚本自动将标记为待翻译的文本通过机器翻译填充。
132132

133-
通常,在`zh-cn.json`中添加所需文案后,执行`sync:i18n`即可自动完成翻译。
133+
通常,在`zh-cn.json`中添加所需文案后,执行`i18n:sync`即可自动完成翻译。
134134

135135
使用该脚本前,需要配置环境变量,例如:
136136

@@ -143,29 +143,19 @@ MODEL="qwen-plus-latest"
143143
你也可以通过直接编辑`.env`文件来添加环境变量。
144144

145145
```bash
146-
yarn auto:i18n
147-
```
148-
149-
### `update:i18n` - 对象级别翻译更新
150-
151-
`src/renderer/src/i18n/translate`中的语言文件进行对象级别的翻译更新,保留已有翻译,只更新新增内容。
152-
153-
**不建议**使用该脚本,更推荐使用`auto:i18n`进行翻译。
154-
155-
```bash
156-
yarn update:i18n
146+
yarn i18n:translate
157147
```
158148

159149
### 工作流
160150

161151
1. 开发阶段,先在`zh-cn.json`中添加所需文案
162-
2. 确认在中文环境下显示无误后,使用`yarn sync:i18n`将文案同步到其他语言文件
163-
3. 使用`yarn auto:i18n`进行自动翻译
152+
2. 确认在中文环境下显示无误后,使用`yarn i18n:sync`将文案同步到其他语言文件
153+
3. 使用`yarn i18n:translate`进行自动翻译
164154
4. 喝杯咖啡,等翻译完成吧!
165155

166156
## 最佳实践
167157

168158
1. **以中文为源语言**:所有开发首先使用中文,再翻译为其他语言
169-
2. **提交前运行检查脚本**:使用`yarn check:i18n`检查i18n是否有问题
159+
2. **提交前运行检查脚本**:使用`yarn i18n:check`检查 i18n 是否有问题
170160
3. **小步提交翻译**:避免积累大量未翻译文本
171-
4. **保持key语义明确**key应能清晰表达其用途,如`user.profile.avatar.upload.error`
161+
4. **保持 key 语义明确**key 应能清晰表达其用途,如`user.profile.avatar.upload.error`

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
"typecheck": "concurrently -n \"node,web\" -c \"cyan,magenta\" \"npm run typecheck:node\" \"npm run typecheck:web\"",
5454
"typecheck:node": "tsgo --noEmit -p tsconfig.node.json --composite false",
5555
"typecheck:web": "tsgo --noEmit -p tsconfig.web.json --composite false",
56-
"check:i18n": "dotenv -e .env -- tsx scripts/check-i18n.ts",
57-
"sync:i18n": "dotenv -e .env -- tsx scripts/sync-i18n.ts",
58-
"update:i18n": "dotenv -e .env -- tsx scripts/update-i18n.ts",
59-
"auto:i18n": "dotenv -e .env -- tsx scripts/auto-translate-i18n.ts",
56+
"i18n:check": "dotenv -e .env -- tsx scripts/check-i18n.ts",
57+
"i18n:sync": "dotenv -e .env -- tsx scripts/sync-i18n.ts",
58+
"i18n:translate": "dotenv -e .env -- tsx scripts/auto-translate-i18n.ts",
59+
"i18n:all": "yarn i18n:check && yarn i18n:sync && yarn i18n:translate",
6060
"update:languages": "tsx scripts/update-languages.ts",
6161
"update:upgrade-config": "tsx scripts/update-app-upgrade-config.ts",
6262
"test": "vitest run --silent",
@@ -70,7 +70,7 @@
7070
"test:e2e": "yarn playwright test",
7171
"test:lint": "oxlint --deny-warnings && eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --cache",
7272
"test:scripts": "vitest scripts",
73-
"lint": "oxlint --fix && eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --cache && yarn typecheck && yarn check:i18n && yarn format:check",
73+
"lint": "oxlint --fix && eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --cache && yarn typecheck && yarn i18n:check && yarn format:check",
7474
"format": "biome format --write && biome lint --write",
7575
"format:check": "biome format && biome lint",
7676
"prepare": "git config blame.ignoreRevsFile .git-blame-ignore-revs && husky",

scripts/auto-translate-i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Usage Instructions:
5050
- pt-pt (Portuguese)
5151
5252
Run Command:
53-
yarn auto:i18n
53+
yarn i18n:translate
5454
5555
Performance Optimization Recommendations:
5656
- For stable API services: MAX_CONCURRENT_TRANSLATIONS=8, TRANSLATION_DELAY_MS=50

scripts/check-i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export function main() {
145145
console.log('i18n 检查已通过')
146146
} catch (e) {
147147
console.error(e)
148-
throw new Error(`检查未通过。尝试运行 yarn sync:i18n 以解决问题。`)
148+
throw new Error(`检查未通过。尝试运行 yarn i18n:sync 以解决问题。`)
149149
}
150150
}
151151

0 commit comments

Comments
 (0)