一个用于管理国际化翻译的命令行工具,支持 JSON 与 Excel 之间的相互转换,并集成了 DeepL 翻译功能。
npm install -g next-translate-excel
- 将 JSON 格式的翻译文件导出为 Excel 表格
- 自动使用 DeepL API 进行中英文翻译
- 从 Excel 表格导入翻译并生成对应的 JSON 文件
- 支持嵌套的 JSON 结构
- 使用 TypeScript 编写,提供完整的类型支持
- 支持的语言:zh, en, ko, id, th, tw, vi
- 新功能: 从 Git commit 中提取翻译变化并生成 Excel
next-translate-execel export -k your-deepl-api-key -s ./zh -o translations.xlsx
选项说明:
-
-k, --api-key
: DeepL API Key(必需) -
-s, --source
: 源 JSON 文件目录,默认为 "./zh" -
-o, --output
: 输出的 Excel 文件路径,默认为 "translations.xlsx"
next-translate-execel import -s translations.xlsx -o ./messages
next-translate-excel update -k your-deepl-api-key -s ./messages/zh -e translations.xlsx -o translations_updated.xlsx
next-translate-excel collect -s ./messages -o translations_collected.xlsx
选项说明:
-
-s, --source
: 源目录,包含各语言子目录,默认为 "./messages" -
-o, --output
: 输出的 Excel 文件路径,默认为 "translations_collected.xlsx"
# 从单个 commit 提取
next-translate-excel extract -p ~/code/my-project -c bcd7281d84dfdaf09f4c62d78f79401729e699f8 -o changes.xlsx
# 从多个 commit 提取
next-translate-excel extract -p ../my-project -c commit1,commit2,commit3 -o multi_changes.xlsx
选项说明:
-
-p, --project
: Git 项目路径,默认为当前目录 -
-c, --commits
: 逗号分隔的 commit ID 列表(必需) -
-o, --output
: 输出的 Excel 文件路径,默认为 "extracted_translations.xlsx"
此命令会:
- 检查指定的 Git 仓库和 commit ID 是否有效
- 提取指定 commit 中
messages/
文件夹下的 JSON 文件变化 - 将嵌套的 JSON 结构扁平化(如
errors.deposit.400683
) - 生成包含所有语言列的 Excel 文件:key, zh_CN, en_US, ko_KR, in_ID, th_TH, zh_TW, vi_VN
npm install
npm run build
npm run start
npm run test
npm run build
npm link
然后在项目中使用 next-translate-excel
命令:
npm link next-translate-excel
next-translate-excel export -k your-deepl-api-key -s ./zh -o translations.xlsx