Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub i18n Tool 🌍

GitHub 项目自动国际化工具 — 为开源项目一键添加多语言支持。

功能特性

  • 🔍 智能扫描 - AST 分析识别硬编码字符串
  • 🤖 AI 翻译 - 支持 OpenAI/Anthropic/Gemini
  • 📦 多语言支持 - 英/中/西/法/俄
  • 🚀 多框架 - React/Vue/纯 JS 项目
  • 🛡️ 安全设计 - API Key 不存储,仅会话使用

快速开始

安装

git clone <repository>
cd github-i18n-tool
npm install
npm run build

代码项目翻译(React/Vue/JS)

# 扫描项目
npx i18n-tool scan --path ./my-project

# 完整翻译流程
npx i18n-tool translate --path ./my-project --output ./locales

文档项目翻译(Markdown)

# 翻译 Markdown 文档目录
npx i18n-tool docs --input ./docs --output ./docs-i18n

文档翻译模式特点:

  • 保留 Markdown 格式(标题、列表、代码块、链接等)
  • 不翻译代码块内容
  • 保留 frontmatter 结构
  • 支持多语言目录结构生成

交互式翻译

npx i18n-tool translate
#
npx i18n-tool docs
# 按提示选择配置

支持的语言

代码 语言
en English
zh 中文
es Español
fr Français
ru Русский

技术栈

  • Node.js + TypeScript
  • Babel AST Parser
  • i18next 格式输出

项目结构

github-i18n-tool/
├── src/
│   ├── index.ts              # CLI 入口
│   ├── scanner.ts            # AST 扫描
│   ├── translator.ts         # 翻译 API
│   ├── generator.ts          # i18n 文件生成
│   ├── markdown-translator.ts # Markdown 文档翻译
│   └── types.ts              # 类型定义
├── memory/
│   └── i18n-log.md           # 执行日志
├── locales/                  # 生成的翻译文件
├── docs-i18n/                # 生成的文档翻译
├── examples/                 # 示例项目
├── I18N_PROJECT.md           # 项目文档
└── README.md

CLI 命令参考

scan - 扫描代码项目

npx i18n-tool scan [options]

选项:

  • -p, --path <path> - 项目路径 (默认: .)
  • -e, --extensions <extensions> - 文件扩展名 (默认: js,jsx,ts,tsx,vue)

translate - 翻译代码项目

npx i18n-tool translate [options]

选项:

  • -p, --path <path> - 项目路径 (默认: .)
  • -o, --output <output> - 输出目录 (默认: ./locales)
  • -l, --languages <langs> - 目标语言,逗号分隔 (默认: en,zh,es,fr,ru)
  • --provider <provider> - 翻译提供商 (openai/anthropic/gemini)
  • --api-key <key> - API Key
  • --model <model> - 模型名称

docs - 翻译 Markdown 文档

npx i18n-tool docs [options]

选项:

  • -i, --input <input> - 输入目录 (默认: ./docs)
  • -o, --output <output> - 输出目录 (默认: ./docs-i18n)
  • -l, --languages <langs> - 目标语言 (默认: en,zh,es,fr,ru)
  • --provider <provider> - 翻译提供商
  • --api-key <key> - API Key
  • --model <model> - 模型名称

config - 显示配置信息

npx i18n-tool config

安全说明

  • API Key 仅临时使用,绝不存储
  • 建议使用环境变量: OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY

由 [后羿 - 四神战队] 创建

About

🌍 GitHub 项目自动 i18n 工具 - 为开源项目添加多语言支持

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages