auto-vue-i18n-tools
v0.1.1
Published
Coding i18n build tools: snapshot pull/diff/audit + Vite plugin, shared by all hosts.
Readme
auto-vue-i18n-tools
Coding i18n 构建期工具:把 snapshot 拉取 / 对比 / 审计从宿主仓库抽出来,任何前端项目与 CI 都可直接用。
- Manual 负责运行时拉包(
/config→ pack → localStorage)。 - 本包 负责构建期:
pull/diff/audit/sync+ Vite 插件。 - MCP + Api 负责控制面:写 DB、gen、分发。
安装
npm i -D auto-vue-i18n-tools零运行时依赖;Node >= 18。
配置
在宿主根目录创建 i18n.config.json:
{
"root": "src",
"snapshot": "src/languages/snapshot",
"api": "http://localhost:10000",
"languages": ["zh-CN", "en-US"],
"limit": 10
}root:扫描T()的源码根目录。snapshot:快照目录(zh-CN.json/en-US.json)。api:Api 地址;也可用I18N_API环境变量或--api覆盖。- 路径相对配置文件目录;CLI 传入的
--root/--snapshot相对当前目录。
命令
# 拉取 pack → snapshot + .version(写盘)
i18n pull --config i18n.config.json
# 只读:pack ↔ snapshot 逐键对比,不一致 exit 1
i18n diff --config i18n.config.json
# 离线:缺失 T() / 重复值 / 疑似整句 / 孤儿 key / 模板自引用率
i18n audit --config i18n.config.json
# pull + audit(先确认 MCP i18n_gen 已在同一 Api 执行)
i18n sync --config i18n.config.json常用参数:
| 参数 | 说明 |
|---|---|
| --root <dir> | 覆盖源码根 |
| --snapshot <dir> | 覆盖快照目录 |
| --api <url> | 覆盖 Api 地址 |
| --languages zh-CN,en-US | 覆盖语言列表 |
| --templates <json> | 模板导出(i18n_template_list 结果),统计自引用率 |
| --limit <n> | 报告条数(默认 10) |
| --orphans | 展开孤儿 key |
| --strict | 缺失 key 时 exit 1 |
| --json | 输出 JSON 报告 |
audit 默认只报告;--strict 才失败。diff 不一致固定 exit 1。
Vite 插件
// vite.config.ts
import { i18nAudit } from 'auto-vue-i18n-tools/vite';
export default defineConfig({
plugins: [
i18nAudit({
config: 'i18n.config.json',
strict: true, // 缺失 key 阻断构建(默认 true)
diff: false, // true = 额外对比 live pack(需要网络)
log: true
})
]
});插件只在 buildStart 执行,不影响 dev server。
迁移(Workbench)
// package.json
"i18n:pull": "i18n pull --config i18n.config.json",
"i18n:diff": "i18n diff --config i18n.config.json",
"i18n:sync": "i18n sync --config i18n.config.json",
"i18n:audit": "i18n audit --config i18n.config.json"旧 scripts/i18n-*.mjs 保留一版 wrapper;验证后删除。
发布
首次(当前 0.1.0):
npm login # 手动登录
npm run publish:first后续 patch:
npm run build:pub # check → npm version patch → npm publish预检:
npm run release:dryprepublishOnly自动跑npm test && npm run check。- 包名与
auto-vue-manual/auto-vue-basic同族,未使用 scope。
边界
- 不在浏览器运行;不替代 Manual 的运行时拉包。
- 不写 DB;写入 / gen 仍走 MCP + Api。
audit离线;diff/pull/sync需要 Api 可达。
