Skip to content

Commit 2e11132

Browse files
committed
feat(i18n): Add i18n
1 parent 29550a8 commit 2e11132

25 files changed

+1356
-380
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[English](./README_EN.md) | 中文
44

5-
一个快速切换Claude Code配置的管理工具,多个中转站之间快速切换URL、API_KEY、AUTH_TOKEN、Model... 支持环境变量管理,延迟测速与自动择优线路切换
5+
一个快速切换Claude Code配置的管理工具,多个中转站之间快速切换URL、API_KEY、AUTH_TOKEN、Model... 支持环境变量管理,延迟测速,自动择优线路切换与国际化支持
66

77
## 功能特性
88

@@ -14,6 +14,7 @@
1414
- 🧠 **智能识别** - 自动识别当前使用的配置和最优路线
1515
- 📄 **多格式支持** - 支持 JSON、JSON5、YAML、TOML 配置文件
1616
- 🔧 **数组支持** - 支持多个URL、Key、Token、Model等字段的数组配置
17+
- 🌍 **国际化支持** - 支持中文和英文界面语言切换
1718

1819
## 安装
1920

@@ -409,9 +410,29 @@ cc
409410
ccapi update
410411
```
411412

412-
### 11. 完整的ccapi-config.json配置
413+
### 11. 语言设置 (国际化)
413414

414-
该文件是ccapi使用的配置文件,可在此进行选项配置
415+
程序支持中英文双语界面,可以根据需要切换显示语言,默认中文:
416+
417+
```bash
418+
# 查看当前语言设置
419+
ccapi lang
420+
421+
# 切换为中文
422+
ccapi lang zh
423+
424+
# 切换为英文
425+
ccapi lang en
426+
427+
# 也可直接在配置文件修改 ~/.ccapi-config.json
428+
{
429+
"language": "zh"
430+
}
431+
```
432+
433+
### 12. 完整的ccapi-config.json配置
434+
435+
该文件是ccapi使用的配置文件,可在此进行选项配置,具体文件在 ~/.ccapi-config.json。
415436

416437
```bash
417438
{
@@ -428,7 +449,9 @@ ccapi update
428449
# 是否需要更新提示
429450
"update": true,
430451
# 使用use命令时是否同步修改系统环境变量
431-
"useNoEnv": true
452+
"useNoEnv": true,
453+
# 界面语言设置 (zh: 中文, en: 英文)
454+
"language": "zh"
432455
}
433456
```
434457

README_EN.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
English | [中文](./README.md)
44

5-
A CLI tool for managing Claude Code configurations, allowing users to quickly switch between different API endpoints, keys, tokens, models, and test network latency to automatically select optimal configurations.
5+
A CLI tool for managing Claude Code configurations, allowing users to quickly switch between different API endpoints, keys, tokens, models, and test network latency to automatically select optimal configurations with internationalization support.
66

77
## Features
88

@@ -14,6 +14,7 @@ A CLI tool for managing Claude Code configurations, allowing users to quickly sw
1414
- 🧠 **Smart Recognition** - Automatically identify currently used configuration and optimal routes
1515
- 📄 **Multi-format Support** - Supports JSON, JSON5, YAML, TOML configuration files
1616
- 🔧 **Array Support** - Supports array configurations for multiple URLs, Keys, Tokens, Models and other fields
17+
- 🌍 **Internationalization** - Supports Chinese and English interface language switching
1718

1819
## Installation
1920

@@ -409,9 +410,29 @@ The program has built-in version checking. If a new version is published on npm,
409410
ccapi update
410411
```
411412

412-
### 11. Complete ccapi-config.json Configuration
413+
### 11. Language Settings (Internationalization)
413414

414-
This file is the configuration file used by ccapi, where you can configure options
415+
The program supports bilingual interface in Chinese and English, you can switch display language as needed:
416+
417+
```bash
418+
# View current language settings
419+
ccapi lang
420+
421+
# Switch to Chinese
422+
ccapi lang zh
423+
424+
# Switch to English
425+
ccapi lang en
426+
427+
# You can also modify directly in configuration file ~/.ccapi-config.json
428+
{
429+
"language": "en"
430+
}
431+
```
432+
433+
### 12. Complete ccapi-config.json Configuration
434+
435+
This file is the configuration file used by ccapi, where you can configure options. The specific file is located at ~/.ccapi-config.json.
415436

416437
```bash
417438
{
@@ -428,7 +449,9 @@ This file is the configuration file used by ccapi, where you can configure optio
428449
# whether update prompts are needed
429450
"update": true,
430451
# whether to synchronously modify system environment variables when using use command
431-
"useNoEnv": true
452+
"useNoEnv": true,
453+
# interface language setting (zh: Chinese, en: English)
454+
"language": "en"
432455
}
433456
```
434457

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@4xian/ccapi",
33
"version": "1.0.6",
44
"author": "4xian (https://github.com/4xian)",
5-
"description": "一个快速切换Claude Code配置的工具,支持URL、API_KEYAUTH_TOKEN、MODEL快速切换、延迟测速、自动择优线路",
5+
"description": "A tool for quickly switching Claude Code configurations, supporting URL, API_KEY, AUTH_TOKEN, MODEL quick switching, one-click management of system environment variables, delay speed measurement, automatic optimal line selection, and internationalization support",
66
"repository": {
77
"url": "git+https://github.com/4xian/claude-auto-api.git"
88
},
@@ -56,7 +56,8 @@
5656
"2. 新增ping命令,测试厂商URL延迟",
5757
"3. 调整test命令,最真实反映能否在Claude Code中使用",
5858
"4. 新增一键修改系统环境变量",
59-
"5. 具体更新内容请查看README.md"
59+
"5. 新增i18n国际化支持",
60+
"6. 具体更新内容请查看README.md"
6061
],
6162
"files": [
6263
"dist",

src/commands/auto.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const testCommand = require('./test')
44
const useCommand = require('./use')
55
const { validateConfig } = require('../utils/config')
66
const { readConfigFile } = require('../utils/file')
7+
const { t } = require('../utils/i18n')
78

89
/**
910
* 分析测试结果,从已排序的结果中选择最优配置
@@ -68,19 +69,6 @@ function analyzeBestConfig(sortedResults, isTestMode = false) {
6869
return allValidResults[0]
6970
}
7071

71-
/**
72-
* 获取延迟显示颜色
73-
*/
74-
function getLatencyColor(latency) {
75-
if (latency <= 300) {
76-
return chalk.green.bold(`${latency}ms`)
77-
} else if (latency <= 800) {
78-
return chalk.yellow.bold(`${latency}ms`)
79-
} else {
80-
return chalk.red.bold(`${latency}ms`)
81-
}
82-
}
83-
8472
/**
8573
* 构建use命令的选项对象
8674
*/
@@ -136,20 +124,20 @@ async function autoCommand(configName = null, options = {}) {
136124
}
137125

138126
if (!sortedResults || sortedResults.length === 0) {
139-
console.error(chalk.red('错误:'), '暂无可用的配置进行测试')
127+
console.error(chalk.red(await t('test.ERROR') + ':'), await t('auto.NO_CONFIGS_AVAILABLE'))
140128
process.exit(1)
141129
}
142130

143131
// 从已排序的结果中选择最优配置
144132
const bestResult = analyzeBestConfig(sortedResults, isTestMode)
145133

146134
if (!bestResult.configName) {
147-
const tip = configName ? `${configName}: 配置测试异常!` : '所有配置测试异常!'
135+
const tip = configName ? `${configName}: ${await t('test.ERROR')}!` : await t('test.NO_AVAILABLE_CONFIG') + '!'
148136
console.error(chalk.red.bold(tip))
149137
process.exit(1)
150138
}
151139

152-
console.log(chalk.green.bold('已找到最优配置,开始切换中...'))
140+
console.log(chalk.green.bold(await t('auto.FOUND_OPTIMAL_CONFIG')))
153141

154142
// 读取配置文件以构建use命令参数
155143
const config = await validateConfig()
@@ -161,7 +149,7 @@ async function autoCommand(configName = null, options = {}) {
161149
// 执行切换
162150
await useCommand(bestResult.configName, useOptions)
163151
} catch (error) {
164-
console.error(chalk.red('自动切换配置失败:'), error.message)
152+
console.error(chalk.red(await t('auto.AUTO_SWITCH_FAILED')), error.message)
165153
process.exit(1)
166154
}
167155
}

src/commands/clear.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ const readline = require('readline')
33
const { validateConfig } = require('../utils/config')
44
const { readConfigFile, writeConfigFile, backupFile } = require('../utils/file')
55
const { validateSettingsConfig } = require('../utils/validator')
6-
const { CLAUDE_ENV_KEYS, SUCCESS_MESSAGES } = require('../utils/constants')
6+
const { CLAUDE_ENV_KEYS } = require('../utils/constants')
77
const {
88
clearSystemEnvVars,
99
checkEnvStatus,
1010
getCurrentConfigName
1111
} = require('../utils/env')
12+
const { t } = require('../utils/i18n')
1213
const maxText = 30
1314

1415
/**
@@ -31,16 +32,17 @@ function clearSettingsConfig(settingsData) {
3132
/**
3233
* 获取用户确认
3334
*/
34-
async function getUserConfirmation(message, confirmText = 'y') {
35+
async function getUserConfirmation() {
3536
const rl = readline.createInterface({
3637
input: process.stdin,
3738
output: process.stdout
3839
})
3940

40-
return new Promise((resolve) => {
41-
rl.question(chalk.red(`${message} (输入${confirmText}确认): `), (answer) => {
41+
return new Promise(async (resolve) => {
42+
const message = await t('clear.CONFIRM')
43+
rl.question(chalk.red(message), (answer) => {
4244
rl.close()
43-
resolve(answer.toLowerCase() === confirmText.toLowerCase())
45+
resolve(answer.toLowerCase() === 'y')
4446
})
4547
})
4648
}
@@ -53,7 +55,7 @@ async function showClearPreview() {
5355
const status = await checkEnvStatus()
5456
const currentConfig = getCurrentConfigName()
5557

56-
console.log(chalk.blue.bold('准备清除以下内容:'))
58+
console.log(chalk.blue.bold(await t('clear.PREPARE_TO_CLEAR')))
5759
console.log()
5860

5961
// 显示settings.json中的配置
@@ -62,7 +64,7 @@ async function showClearPreview() {
6264
const settingsData = await readConfigFile(config.settingsPath)
6365

6466
if (settingsData.env && Object.keys(settingsData.env).length > 0) {
65-
console.log(chalk.yellow.bold('settings.json 中的环境变量配置:'))
67+
console.log(chalk.yellow.bold(await t('clear.SETTINGS_ENV_CONFIG')))
6668
for (const [key, value] of Object.entries(settingsData.env)) {
6769
if (Object.values(CLAUDE_ENV_KEYS).includes(key)) {
6870
let displayValue = value
@@ -74,17 +76,17 @@ async function showClearPreview() {
7476
}
7577
console.log()
7678
} else {
77-
console.log(chalk.dim('settings.json 中未检测到相关配置'))
79+
console.log(chalk.dim(await t('clear.NO_SETTINGS_CONFIG')))
7880
console.log()
7981
}
8082
} catch (error) {
81-
console.log(chalk.yellow('警告: 无法读取 settings.json 文件'))
83+
console.log(chalk.yellow(await t('clear.CANT_READ_SETTINGS')))
8284
console.log()
8385
}
8486

8587
// 显示系统环境变量
8688
if (status.hasEnvVars || currentConfig) {
87-
console.log(chalk.yellow.bold('系统环境变量:'))
89+
console.log(chalk.yellow.bold(await t('clear.SYSTEM_ENV_VARS')))
8890

8991
for (const [key, value] of Object.entries(status.envVars)) {
9092
if (key !== 'CCAPI_CURRENT_CONFIG') {
@@ -97,13 +99,13 @@ async function showClearPreview() {
9799
}
98100
console.log()
99101
} else {
100-
console.log(chalk.dim('系统环境变量中未检测到相关配置'))
102+
console.log(chalk.dim(await t('clear.NO_SYSTEM_ENV_VARS')))
101103
console.log()
102104
}
103105

104106
return status.hasEnvVars || currentConfig || false
105107
} catch (error) {
106-
console.error(chalk.red('获取清除预览失败:'), error.message)
108+
console.error(chalk.red(await t('clear.CLEAR_PREVIEW_FAILED')), error.message)
107109
return false
108110
}
109111
}
@@ -130,18 +132,18 @@ async function clearCommand() {
130132
}
131133

132134
if (!hasSettingsConfig) {
133-
console.log(chalk.green('未检测到任何需要清除的配置'))
135+
console.log(chalk.green(await t('clear.NO_CONFIG_TO_CLEAR')))
134136
return
135137
}
136138
}
137139

138-
console.log(chalk.red.bold('⚠️ 警告: 此操作将完全清除所有相关配置'))
139-
console.log(chalk.red(' • 清除 settings.json 中的环境变量配置'))
140-
console.log(chalk.red(' • 清除系统中的相关环境变量'))
140+
console.log(chalk.red.bold(await t('clear.WARNING_CLEAR_ALL')))
141+
console.log(chalk.red(await t('clear.WILL_CLEAR_SETTINGS')))
142+
console.log(chalk.red(await t('clear.WILL_CLEAR_SYSTEM')))
141143
console.log()
142144

143145
// 第一次确认
144-
const firstConfirm = await getUserConfirmation('确认要执行完全清理操作吗?', 'y')
146+
const firstConfirm = await getUserConfirmation()
145147
if (!firstConfirm) {
146148
return
147149
}
@@ -159,17 +161,17 @@ async function clearCommand() {
159161
if (validateSettingsConfig(settingsData)) {
160162
// 备份 settings.json
161163
const backupPath = await backupFile(config.settingsPath)
162-
console.log(`settings.json 已备份到: ${backupPath}`)
164+
console.log(await t('clear.SETTINGS_BACKED_UP', backupPath))
163165

164166
// 清理配置
165167
const clearedSettings = clearSettingsConfig(settingsData)
166168
await writeConfigFile(config.settingsPath, clearedSettings)
167169

168-
console.log(chalk.green.bold('✓ settings.json 配置已清除'))
170+
console.log(chalk.green.bold(await t('clear.SETTINGS_CONFIG_CLEARED')))
169171
settingsCleared = true
170172
}
171173
} catch (error) {
172-
console.log(chalk.yellow('警告: settings.json 清理失败'), error.message)
174+
console.log(chalk.yellow(await t('clear.SETTINGS_CLEAR_FAILED')), error.message)
173175
}
174176

175177
// 清理系统环境变量
@@ -180,7 +182,7 @@ async function clearCommand() {
180182
}
181183

182184
} catch (error) {
183-
console.error(chalk.red('清理命令执行失败:'), error.message)
185+
console.error(chalk.red(await t('clear.CLEAR_CMD_FAILED')), error.message)
184186
process.exit(1)
185187
}
186188
}

0 commit comments

Comments
 (0)