i18n-a11y 1.0.3 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/dist/src/ai.js +21 -21
- package/dist/src/utils/genI18nConfig.js +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# auto-i18n
|
|
2
|
+
|
|
3
|
+
## description
|
|
4
|
+
|
|
5
|
+
node cli tools for auto generate i18n files
|
|
6
|
+
|
|
7
|
+
## install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm i i18n-a11y -D
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## usage
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
"scripts": {
|
|
17
|
+
"i18n": "i18n-a11y scan"
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## configuration
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
entryDirs: ["src/views", "src/components"], // scan entry directory
|
|
26
|
+
extensions: ["vue"], // scan file extensions
|
|
27
|
+
output: "ts", // output file type
|
|
28
|
+
outputDir: "src/i18n/locales", // output file directory
|
|
29
|
+
withFileComment: false, // add file comment on file top
|
|
30
|
+
withKeyFileComment: false, // add key file comment on key top
|
|
31
|
+
i18nFns: ["t", "$t"], // i18n function name
|
|
32
|
+
supportChineseKey: true, // support chinese key
|
|
33
|
+
languages: ["zh-CN", "en-US"], // languages
|
|
34
|
+
};
|
|
35
|
+
```
|
|
36
|
+
## Environment Variables
|
|
37
|
+
|
|
38
|
+
Create a `.env.local` file in the project root and add:
|
|
39
|
+
``` bash
|
|
40
|
+
DEEPSEEK_API_KEY=your-deepseek-key-here
|
|
41
|
+
DEEPSEEK_API_URL=https://api.deepseek.com
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Output
|
|
45
|
+
|
|
46
|
+
After running the CLI, files will be generated in the outputDir, for example `src/i18n/locales`
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
src/i18n/locale/
|
|
50
|
+
├─ zh-CN.ts
|
|
51
|
+
├─ en-US.ts
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
Automatically scans project files to extract translation keys
|
|
58
|
+
|
|
59
|
+
Supports Vue, JS, and TS files
|
|
60
|
+
|
|
61
|
+
Generates multilingual locale files
|
|
62
|
+
|
|
63
|
+
Optional file-level and key-level comments
|
|
64
|
+
|
|
65
|
+
Fully configurable
|
|
66
|
+
|
|
67
|
+
Supports Chinese keys
|
|
68
|
+
|
|
69
|
+
Integrates Deepseek AI for automatic translations
|
package/dist/src/ai.js
CHANGED
|
@@ -5,27 +5,27 @@ const openai = new OpenAI({
|
|
|
5
5
|
baseURL: process.env.DEEPSEEK_API_URL,
|
|
6
6
|
apiKey: process.env.DEEPSEEK_API_KEY,
|
|
7
7
|
});
|
|
8
|
-
const rules = `
|
|
9
|
-
你是一个国际化语言包翻译助手。
|
|
10
|
-
|
|
11
|
-
输入一个 key, 例如:
|
|
12
|
-
- "email"
|
|
13
|
-
- "title"
|
|
14
|
-
- "name"
|
|
15
|
-
- "user.avatar"
|
|
16
|
-
|
|
17
|
-
根据 key 翻译成目标语言,遵循以下
|
|
18
|
-
|
|
19
|
-
规则:
|
|
20
|
-
1. 输出必须是字符串。
|
|
21
|
-
2. 只返回 target 目标语言的内容,不要解释、不要日志、不要 markdown。
|
|
22
|
-
3. 如果 key 包含. 表示嵌套对象的路径,说明是一个页面的模块,只翻译最后一级。
|
|
23
|
-
eg: "user.avatar" 只翻译 "avatar"
|
|
24
|
-
|
|
25
|
-
示例:
|
|
26
|
-
输入 translate ("title", "zh-CN")
|
|
27
|
-
|
|
28
|
-
输出:标题
|
|
8
|
+
const rules = `
|
|
9
|
+
你是一个国际化语言包翻译助手。
|
|
10
|
+
|
|
11
|
+
输入一个 key, 例如:
|
|
12
|
+
- "email"
|
|
13
|
+
- "title"
|
|
14
|
+
- "name"
|
|
15
|
+
- "user.avatar"
|
|
16
|
+
|
|
17
|
+
根据 key 翻译成目标语言,遵循以下
|
|
18
|
+
|
|
19
|
+
规则:
|
|
20
|
+
1. 输出必须是字符串。
|
|
21
|
+
2. 只返回 target 目标语言的内容,不要解释、不要日志、不要 markdown。
|
|
22
|
+
3. 如果 key 包含. 表示嵌套对象的路径,说明是一个页面的模块,只翻译最后一级。
|
|
23
|
+
eg: "user.avatar" 只翻译 "avatar"
|
|
24
|
+
|
|
25
|
+
示例:
|
|
26
|
+
输入 translate ("title", "zh-CN")
|
|
27
|
+
|
|
28
|
+
输出:标题
|
|
29
29
|
`;
|
|
30
30
|
const translate = async (key, target) => {
|
|
31
31
|
const completion = await openai.chat.completions.create({
|
|
@@ -43,7 +43,7 @@ export const genI18nConfig = async () => {
|
|
|
43
43
|
type: "input",
|
|
44
44
|
name: "outputDir",
|
|
45
45
|
message: chalk.green("Step 4: Enter output language directory"),
|
|
46
|
-
default: "src/i18n/
|
|
46
|
+
default: "src/i18n/locales",
|
|
47
47
|
},
|
|
48
48
|
]);
|
|
49
49
|
// Step 5: file header comment
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18n-a11y",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "CLI tool for generating i18n files",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,10 +11,13 @@
|
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"i18n:build": "node dist/src/cli.js scan",
|
|
13
13
|
"i18n:local": "tsx src/cli.ts scan",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
14
|
+
"release:patch": "pnpm version patch",
|
|
15
|
+
"release:minor": "pnpm version minor",
|
|
16
|
+
"release:major": "pnpm version major",
|
|
17
|
+
"publish:npm": "npm publish --access public",
|
|
18
|
+
"push": "git push --follow-tags"
|
|
17
19
|
},
|
|
20
|
+
"prepublishOnly": "npm run build",
|
|
18
21
|
"keywords": [
|
|
19
22
|
"i18n",
|
|
20
23
|
"cli",
|