vue-i18n-automatic-translation 1.0.0 → 1.0.2
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 +113 -18
- package/README.zh-CN.md +113 -18
- package/package.json +1 -1
- package/src/offline-en.mjs +35 -703
- package/src/translate-en.mjs +3 -325
package/README.md
CHANGED
|
@@ -58,27 +58,122 @@ If `i18nAuto` is omitted, defaults scan `src` and use the built-in locale set (s
|
|
|
58
58
|
|
|
59
59
|
## Commands
|
|
60
60
|
|
|
61
|
-
Run inside the consumer project (directory with `vite.config` / `package.json`):
|
|
61
|
+
Run inside the consumer project (directory with `vite.config` / `package.json`). Help: `npx i18n-auto --help`.
|
|
62
|
+
|
|
63
|
+
### `scan` — full / path-scoped scan
|
|
64
|
+
|
|
65
|
+
Scan Chinese in `include` (or CLI paths) → write locale JSON → optionally wrap `$t()` / `t()` → `sync` → offline EN dict → online translate (EN + target locales).
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npx i18n-auto scan # scan include (default: src)
|
|
69
|
+
npx i18n-auto scan src/views/workbench # one or more paths override include
|
|
70
|
+
npx i18n-auto scan --dry # report only; no file writes
|
|
71
|
+
npx i18n-auto scan --no-replace # write locales, do not wrap source
|
|
72
|
+
npx i18n-auto scan --no-translate # extract + sync + offline EN; skip online
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
| Option | Description |
|
|
76
|
+
|--------|-------------|
|
|
77
|
+
| `[path...]` | Override `include`; only these paths |
|
|
78
|
+
| `--dry` | Dry-run: scan + report, touch nothing |
|
|
79
|
+
| `--no-replace` | Write locales but leave source alone (also `replace: false`) |
|
|
80
|
+
| `--no-translate` | Skip online EN / multi-locale translate (also `translate: false`) |
|
|
81
|
+
|
|
82
|
+
Pipeline: `extract` → `sync` → `offline-en` → (optional) `fill-en` + `fill-locales` for new/pending keys. Reports: `reports/i18n-extract.json`, `reports/i18n-scan-keys.json`.
|
|
83
|
+
|
|
84
|
+
### `changed` — Git-changed files only
|
|
85
|
+
|
|
86
|
+
Only `.vue` / `.ts` / `.js` (etc.) under `include` that changed in git. Default translate scope is keys from those files — good for incremental work.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npx i18n-auto changed # unstaged + staged vs HEAD
|
|
90
|
+
npx i18n-auto changed --staged # staged files only
|
|
91
|
+
npx i18n-auto changed --dry # list + scan, no writes
|
|
92
|
+
npx i18n-auto changed --no-translate # extract + sync, no online translate
|
|
93
|
+
npx i18n-auto changed --fill-all # translate full locale backlog
|
|
94
|
+
npx i18n-auto changed --online-en # online-translate all pending EN (not just changed keys)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Option | Description |
|
|
98
|
+
|--------|-------------|
|
|
99
|
+
| `--dry` | Dry-run; no locale / source writes |
|
|
100
|
+
| `--staged` | Staged changes only (pre-commit friendly) |
|
|
101
|
+
| `--no-translate` | Skip online translation |
|
|
102
|
+
| `--fill-all` | Fill entire multi-locale backlog (`--locales` / `--translate` aliases) |
|
|
103
|
+
| `--online-en` | Force online for all pending English, not changed-key scope |
|
|
104
|
+
|
|
105
|
+
Reports: `reports/i18n-changed-keys.json`, etc.
|
|
106
|
+
|
|
107
|
+
### `sync` — align locale keys
|
|
108
|
+
|
|
109
|
+
Use source locale (default `zh-CN`) as the key set; add missing keys to each target (placeholder = Chinese by default).
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npx i18n-auto sync # missing keys ← source text
|
|
113
|
+
npx i18n-auto sync --fill=empty # missing keys ← empty string
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### `inject-meta` — locale metadata
|
|
117
|
+
|
|
118
|
+
Inject/update display-name meta fields (`name` / `nameZh`, …) into each locale JSON.
|
|
62
119
|
|
|
63
120
|
```bash
|
|
64
|
-
# Scan include paths (or pass a path), extract Chinese, wrap $t, sync, translate
|
|
65
|
-
npx i18n-auto scan
|
|
66
|
-
npx i18n-auto scan src/views/workbench
|
|
67
|
-
npx i18n-auto scan --dry
|
|
68
|
-
npx i18n-auto scan --no-translate
|
|
69
|
-
|
|
70
|
-
# Only git-changed source files under include
|
|
71
|
-
npx i18n-auto changed
|
|
72
|
-
npx i18n-auto changed --staged
|
|
73
|
-
npx i18n-auto changed --no-translate
|
|
74
|
-
npx i18n-auto changed --fill-all
|
|
75
|
-
|
|
76
|
-
# Helpers
|
|
77
|
-
npx i18n-auto sync
|
|
78
121
|
npx i18n-auto inject-meta
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### `fill-en` — fill English pack
|
|
125
|
+
|
|
126
|
+
For `en-US`: dictionary first, then online. **Does not overwrite existing non-Chinese English** unless `--force`.
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npx i18n-auto fill-en --check # counts only, no writes
|
|
130
|
+
npx i18n-auto fill-en --auto # dict + online for pending
|
|
131
|
+
npx i18n-auto fill-en --auto --limit=50 # cap this run at 50 keys
|
|
132
|
+
npx i18n-auto fill-en --auto --keys-file=reports/i18n-scan-keys.json
|
|
133
|
+
npx i18n-auto fill-en --auto --delay=300 # request delay (ms)
|
|
134
|
+
npx i18n-auto fill-en --force --auto # caution: may overwrite EN
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
| Option | Description |
|
|
138
|
+
|--------|-------------|
|
|
139
|
+
| `--check` | Inspect only |
|
|
140
|
+
| `--auto` | Auto-translate pending |
|
|
141
|
+
| `--limit=N` | Max keys this run |
|
|
142
|
+
| `--delay=N` | Delay between requests (ms) |
|
|
143
|
+
| `--keys-file=...` | Restrict to keys in a report file |
|
|
144
|
+
| `--force` | Allow overwriting existing English |
|
|
145
|
+
|
|
146
|
+
### `fill-locales` — fill other target locales
|
|
147
|
+
|
|
148
|
+
Online-translate `targetLocales` (e.g. `de-DE`, `ja-JP`). Existing non-Chinese values are kept.
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npx i18n-auto fill-locales --check # pending counts per locale
|
|
152
|
+
npx i18n-auto fill-locales # same as --all
|
|
153
|
+
npx i18n-auto fill-locales --all --delay=200 --concurrency=2
|
|
154
|
+
npx i18n-auto fill-locales --all --limit=30
|
|
155
|
+
npx i18n-auto fill-locales --all --keys-file=reports/i18n-changed-keys.json
|
|
156
|
+
npx i18n-auto fill-locales --locale=ja-JP # one locale (repeatable)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| Option | Description |
|
|
160
|
+
|--------|-------------|
|
|
161
|
+
| `--check` | Counts only |
|
|
162
|
+
| `--all` | All `targetLocales` (default) |
|
|
163
|
+
| `--locale=xx-XX` | Limit to one locale (overrides `--all`) |
|
|
164
|
+
| `--delay=N` | Request delay (ms) |
|
|
165
|
+
| `--concurrency=N` | Parallelism |
|
|
166
|
+
| `--limit=N` | Per-locale cap |
|
|
167
|
+
| `--keys-file=...` | Only keys listed in the report |
|
|
168
|
+
| `--save-every=N` | Flush to disk every N keys |
|
|
169
|
+
|
|
170
|
+
### `offline-en` — offline English dictionary
|
|
171
|
+
|
|
172
|
+
No network: fill Chinese-placeholder EN entries from the built-in / extra dictionary.
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
npx i18n-auto offline-en # apply dict and write en-US
|
|
176
|
+
npx i18n-auto offline-en --check # stats only (would-fill / leftover)
|
|
82
177
|
```
|
|
83
178
|
|
|
84
179
|
### package.json scripts (optional)
|
package/README.zh-CN.md
CHANGED
|
@@ -58,27 +58,122 @@ export default defineConfig({
|
|
|
58
58
|
|
|
59
59
|
## 命令
|
|
60
60
|
|
|
61
|
-
在消费方项目根目录执行(有 `vite.config` / `package.json`
|
|
61
|
+
在消费方项目根目录执行(有 `vite.config` / `package.json` 的目录)。查看帮助:`npx i18n-auto --help`。
|
|
62
|
+
|
|
63
|
+
### `scan` — 全量 / 指定路径扫描
|
|
64
|
+
|
|
65
|
+
按 `include`(或命令行传入的路径)扫描源码中文 → 写入语言包 → 可选替换为 `$t()` / `t()` → `sync` → 离线英文字典 → 在线翻译(英 + 目标语言)。
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npx i18n-auto scan # 扫描配置里的 include(默认 src)
|
|
69
|
+
npx i18n-auto scan src/views/workbench # 只扫指定目录/文件(可多个)
|
|
70
|
+
npx i18n-auto scan --dry # 只报告,不写语言包、不改源码
|
|
71
|
+
npx i18n-auto scan --no-replace # 写语言包,但不把源码包成 $t()/t()
|
|
72
|
+
npx i18n-auto scan --no-translate # 抽取 + sync + 离线英译,跳过在线翻译
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
| 选项 | 说明 |
|
|
76
|
+
|------|------|
|
|
77
|
+
| `[path...]` | 覆盖 `include`,只处理给出的路径 |
|
|
78
|
+
| `--dry` | 干跑:只扫描并写报告,不改任何文件 |
|
|
79
|
+
| `--no-replace` | 写入 locales,但不改源码(也受配置 `replace: false` 影响) |
|
|
80
|
+
| `--no-translate` | 跳过在线英译 / 多语言翻译(也受配置 `translate: false` 影响) |
|
|
81
|
+
|
|
82
|
+
流水线:`extract` → `sync` → `offline-en` →(可选)`fill-en` + `fill-locales`(仅本次新增/待译 key)。报告:`reports/i18n-extract.json`、`reports/i18n-scan-keys.json`。
|
|
83
|
+
|
|
84
|
+
### `changed` — 仅处理 Git 变更文件
|
|
85
|
+
|
|
86
|
+
只处理 git 变更且落在 `include` 内的 `.vue` / `.ts` / `.js` 等源码;抽取后默认只翻译「本次变更相关」的 key,适合日常增量。
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npx i18n-auto changed # 工作区 + 未暂存变更(相对 HEAD)
|
|
90
|
+
npx i18n-auto changed --staged # 只处理已 git add 的文件
|
|
91
|
+
npx i18n-auto changed --dry # 只列出变更文件并扫描,不写盘
|
|
92
|
+
npx i18n-auto changed --no-translate # 抽取 + sync,不做在线翻译
|
|
93
|
+
npx i18n-auto changed --fill-all # 翻译整份语言包积压,不只变更 key
|
|
94
|
+
npx i18n-auto changed --online-en # 强制对全部待译英文走在线(不只变更 scope)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| 选项 | 说明 |
|
|
98
|
+
|------|------|
|
|
99
|
+
| `--dry` | 干跑,不写语言包 / 不改源码 |
|
|
100
|
+
| `--staged` | 仅 staged 变更(适合 pre-commit) |
|
|
101
|
+
| `--no-translate` | 跳过在线翻译 |
|
|
102
|
+
| `--fill-all` | 多语言填满整包 backlog(`--locales` / `--translate` 同义) |
|
|
103
|
+
| `--online-en` | 英文侧对全部 pending 做在线翻译,不限变更 key |
|
|
104
|
+
|
|
105
|
+
报告:`reports/i18n-changed-keys.json` 等。
|
|
106
|
+
|
|
107
|
+
### `sync` — 语言包 key 对齐
|
|
108
|
+
|
|
109
|
+
以源语言(默认 `zh-CN`)为基准,给各目标语言补上缺失的 key;缺省用中文占位。
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npx i18n-auto sync # 补缺失 key(值为源文案)
|
|
113
|
+
npx i18n-auto sync --fill=empty # 补缺失 key,值为空字符串
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### `inject-meta` — 写入语言元信息
|
|
117
|
+
|
|
118
|
+
向各 locale JSON 注入/更新语言显示名等 meta 字段(如 `name` / `nameZh`)。
|
|
62
119
|
|
|
63
120
|
```bash
|
|
64
|
-
# 按 include(或指定 path)扫描中文 → 写语言包 → 包 $t → 同步 → 翻译
|
|
65
|
-
npx i18n-auto scan
|
|
66
|
-
npx i18n-auto scan src/views/workbench
|
|
67
|
-
npx i18n-auto scan --dry
|
|
68
|
-
npx i18n-auto scan --no-translate
|
|
69
|
-
|
|
70
|
-
# 只处理 git 变更的源码文件(且落在 include 内)
|
|
71
|
-
npx i18n-auto changed
|
|
72
|
-
npx i18n-auto changed --staged
|
|
73
|
-
npx i18n-auto changed --no-translate
|
|
74
|
-
npx i18n-auto changed --fill-all
|
|
75
|
-
|
|
76
|
-
# 辅助命令
|
|
77
|
-
npx i18n-auto sync
|
|
78
121
|
npx i18n-auto inject-meta
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### `fill-en` — 填充英文包
|
|
125
|
+
|
|
126
|
+
对 `en-US`:优先词典,再用在线翻译;**不会覆盖已有非中文英文译文**(除非 `--force`)。
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npx i18n-auto fill-en --check # 只统计待译数量,不写文件
|
|
130
|
+
npx i18n-auto fill-en --auto # 词典 + 在线翻译未译项
|
|
131
|
+
npx i18n-auto fill-en --auto --limit=50 # 本轮最多处理 50 条(试跑)
|
|
132
|
+
npx i18n-auto fill-en --auto --keys-file=reports/i18n-scan-keys.json # 只处理报告里的 key
|
|
133
|
+
npx i18n-auto fill-en --auto --delay=300 # 请求间隔(毫秒)
|
|
134
|
+
npx i18n-auto fill-en --force --auto # 慎用:词典可覆盖已有英文
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
| 选项 | 说明 |
|
|
138
|
+
|------|------|
|
|
139
|
+
| `--check` | 只检查,不写文件 |
|
|
140
|
+
| `--auto` | 自动翻译 pending |
|
|
141
|
+
| `--limit=N` | 限制本轮条数 |
|
|
142
|
+
| `--delay=N` | 请求间隔 ms |
|
|
143
|
+
| `--keys-file=...` | 只处理指定报告中的 key |
|
|
144
|
+
| `--force` | 允许覆盖已有英文(慎用) |
|
|
145
|
+
|
|
146
|
+
### `fill-locales` — 填充其他目标语言
|
|
147
|
+
|
|
148
|
+
按源语言 + 英文等对 `targetLocales`(如 `de-DE`、`ja-JP`)做在线翻译;已有非中文译文不覆盖。
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npx i18n-auto fill-locales --check # 各语言 pending 统计
|
|
152
|
+
npx i18n-auto fill-locales # 等同 --all,翻译全部目标语言
|
|
153
|
+
npx i18n-auto fill-locales --all --delay=200 --concurrency=2
|
|
154
|
+
npx i18n-auto fill-locales --all --limit=30 # 每语言本轮最多 30 条
|
|
155
|
+
npx i18n-auto fill-locales --all --keys-file=reports/i18n-changed-keys.json
|
|
156
|
+
npx i18n-auto fill-locales --locale=ja-JP # 只处理指定语言(可多次)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| 选项 | 说明 |
|
|
160
|
+
|------|------|
|
|
161
|
+
| `--check` | 只检查 pending,不翻译 |
|
|
162
|
+
| `--all` | 处理全部 `targetLocales`(默认行为) |
|
|
163
|
+
| `--locale=xx-XX` | 限定单个语言(可重复;优先于 `--all`) |
|
|
164
|
+
| `--delay=N` | 请求间隔 ms |
|
|
165
|
+
| `--concurrency=N` | 并发数 |
|
|
166
|
+
| `--limit=N` | 每语言条数上限 |
|
|
167
|
+
| `--keys-file=...` | 只翻译报告中的 key |
|
|
168
|
+
| `--save-every=N` | 每处理 N 条落盘一次 |
|
|
169
|
+
|
|
170
|
+
### `offline-en` — 离线英文字典
|
|
171
|
+
|
|
172
|
+
不访问网络,用内置/扩展词典把仍是中文占位的英文条目尽量填上。
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
npx i18n-auto offline-en # 应用词典并写回 en-US
|
|
176
|
+
npx i18n-auto offline-en --check # 只统计会填充 / 仍剩余的条数
|
|
82
177
|
```
|
|
83
178
|
|
|
84
179
|
### package.json scripts(可选)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-i18n-automatic-translation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Scan Chinese text in Vue projects, wrap with $t(), and auto-translate locale JSON files. Configure via vite.config i18nAuto.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|