Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

ai-i18n-sync

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai-i18n-sync

AI-powered i18n translation sync tool. Detect missing keys → Translate → Sync.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

ai-i18n

AI 驱动的国际化翻译同步工具 —— 检测缺失 key → AI 翻译 → 同步写入,一条命令搞定。

English | 中文

特性

  • 增量翻译 — 只翻译缺失的 key,不重复翻译已有内容
  • 多 AI 模型 — OpenAI / DeepSeek / Claude / 通义千问 / Gemini / Ollama
  • 完整性检查 — 一键检查所有语言文件的 key 缺失和多余
  • 术语表 — 确保专业术语翻译一致("订单" 始终翻译为 "Order")
  • 嵌套 key — 完整支持 common.buttons.submit 嵌套结构
  • 保留格式 — key 顺序与主文件一致,最小化 git diff
  • 快速翻译translate 命令秒级翻译单条文本
  • 零依赖 — 无 required dependencies,npx 直接用

快速开始

# 1. 配置 API Key
echo 'DEEPSEEK_API_KEY=sk-xxx' >> .env.local

# 2. 同步翻译
npx ai-i18n-sync sync --source locales/zh.json --targets en,ja

# 3. 检查完整性
npx ai-i18n-sync check

安装

# 方式一:项目级安装
npm install -D ai-i18n-sync

# 方式二:全局安装
npm install -g ai-i18n-sync

# 方式三:npx 直接用
npx ai-i18n-sync

安装后可使用短名 ai-i18n 替代 ai-i18n-sync

命令

sync — 同步翻译

以主语言文件为基准,AI 翻译缺失的 key 并写入目标文件。

npx ai-i18n sync --source locales/zh.json --targets en,ja
npx ai-i18n sync --source zh.json --targets en.json --dry-run
npx ai-i18n sync --context "跨境电商平台"
参数说明
--source <file>主语言文件路径
--targets <list>目标语言(逗号分隔:en,ja,ko 或文件路径)
--context <text>翻译上下文(提升翻译准确度)
--dry-run只展示,不写入文件

运行效果

$ npx ai-i18n sync --source locales/zh.json --targets en

🔍  正在扫描 i18n 文件...
📄  Source: zh.json (142 keys)
📄  Target: en.json (130 keys)  ⚠️  12 missing

📋  发现 12 个缺失 key (en.json):
     + mall.order.refund_pending    "退款审核中"
     + mall.order.refund_approved   "退款已通过"
     + mall.coupon.claim_success    "领取成功"
     ... (9 more)

🤖  正在翻译 12 个 key → en...
     mall.order.refund_pending:  "退款审核中" → "Refund Under Review"
     mall.order.refund_approved: "退款已通过" → "Refund Approved"
     mall.coupon.claim_success:  "领取成功" → "Claimed Successfully"
     ... (9 more)

✅  已同步 12 个 key → en.json

🎉  翻译同步完成,共 12 个 key。

check — 检查完整性

npx ai-i18n check
npx ai-i18n check --strict    # 多余 key 也报错
🔍  正在检查 i18n 完整性...

   zh.json                   142 keys  (source)
   en.json                   130 keys  ⚠️  12 missing
   ja.json                   128 keys  ⚠️  14 missing
   ko.json                   142 keys  ✅

❌  存在缺失 key,运行 `ai-i18n sync` 修复。

translate — 快速翻译

npx ai-i18n translate "用户管理" --to en,ja
npx ai-i18n translate "退款审核" --to en --context "电商平台"
🤖  翻译: "用户管理"

   en: User Management
   ja: ユーザー管理

init — 初始化配置

npx ai-i18n init    # 生成 .ai-i18n.json + .ai-i18n-glossary.json

配置文件

运行 ai-i18n init 生成 .ai-i18n.json

{
  "sourceLocale": "zh",                 // 主语言
  "targetLocales": ["en"],              // 目标语言列表
  "localesDir": "src/locales",          // i18n 文件目录
  "filePattern": "{locale}.json",       // 文件命名规则
  "nested": true,                       // 嵌套结构
  "sortKeys": false,                    // 输出时 key 排序
  "context": "",                        // 翻译上下文
  "glossary": ".ai-i18n-glossary.json", // 术语表路径
  "batchSize": 30,                      // 每次 API 调用翻译的 key 数
  "model": ""                           // 指定模型
}

术语表

.ai-i18n-glossary.json 确保专业术语翻译一致:

{
  "zh-en": {
    "订单": "Order",
    "优惠券": "Coupon",
    "购物车": "Shopping Cart",
    "退款": "Refund"
  },
  "zh-ja": {
    "订单": "注文",
    "优惠券": "クーポン"
  }
}

支持的 AI 模型

Provider默认模型环境变量
OpenAIgpt-4o-miniOPENAI_API_KEY
DeepSeekdeepseek-chatDEEPSEEK_API_KEY
Claudeclaude-sonnet-4-20250514ANTHROPIC_API_KEY
通义千问qwen-plusDASHSCOPE_API_KEY
Geminigemini-2.0-flashGEMINI_API_KEY
Ollamaqwen2.5-coder无需 Key

兼容 AI_REVIEW_* 系列环境变量。

工具链

ai-review-pipeline ── 代码质量审查
ai-git-msg         ── 提交信息生成
ai-i18n-sync       ── 国际化翻译同步

English

What is this?

An AI-powered i18n translation sync tool. Detects missing keys → AI translates → Writes to target files. Supports glossary for consistent terminology.

Quick Start

echo 'DEEPSEEK_API_KEY=sk-xxx' >> .env.local
npx ai-i18n-sync sync --source locales/zh.json --targets en,ja

Commands

CommandDescription
syncTranslate and sync missing keys to target locales
checkCheck locale files for missing/extra keys
translateQuickly translate a text string
initInitialize config and glossary files

Install

npm install -D ai-i18n-sync
npx ai-i18n-sync

License

MIT

Keywords

ai

FAQs

Package last updated on 01 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts