@ autoglot/ cli (英语)
从命令行翻译出i18n文件. 支持JSON,YAML,PO/POT,和Xcode字符串目录.
快开始
npx @autoglot/cli en.json --lang es,fr,de
传递多个文件或一个 shell glob 来一起翻译它们 :
npx @autoglot/cli ios/Layers/**/*.xcstrings --lang es,fr,de
设置
- 报名到 自动glot.app
- 转到 仪表板/ API 密钥 创建密钥
- 导出 :
export AUTOGLOT_API_KEY=your_key_here
CLI 使用情况
autoglot <files...> --lang <codes> [options]
参数
| 参数 | 说明 |
|---|---|
files | 要翻译的源文件在一个任务中(例如. en.json, (中文(简体) ), en.po, (中文(简体) ), messages.yaml(中文(简体) ) |
选项
| 选项 | 别名 | 默认 | 说明 |
|---|---|---|---|
--lang | -l | (必须) | 逗号分隔目标语言 |
--source | -s | 从文件名自动检测, 回落 en | 源语言代码 |
--output | -o | 输入根 | 翻译文件输出目录; 保存相对输入路径 |
--input-root | 可能时使用当前目录 | 在翻译上下文、分析、和活动中用于稳定源路径的根 | |
--project | -p | 词汇/类型指南项目(owner/repo 格式) | |
--branch | 活动记录的源分支;要求 --deployment-type 财务报告和审定财务报表 --project | ||
--deployment-type | preview 或者说 release需要; 需要 --branch | ||
--api-key | -k | AUTOGLOT_API_KEY 环境 var | API 密钥 |
--api-url | https://api.autoglot.app | API 基础 URL | |
--timeout | 最多等待数秒, 然后返回最新的兼容缓存文物 。 要求数 --project | ||
--no-cache | false | 跳过翻译缓存 | |
--help | -h | 显示帮助 | |
--version | -v | 显示版本 |
实例
将JSON文件翻译成西班牙文、法文和德文:
npx @autoglot/cli src/locales/en.json --lang es,fr,de
翻译带有明确源语言和输出目录的 PO 文件 :
npx @autoglot/cli messages.po --lang ja,ko --source en --output ./translations
使用项目词汇表和样式指南:
npx @autoglot/cli en.json --lang es,fr --project acme/my-app
如果新译名需要2分钟以上, 保留带有缓存翻译的构建移动 :
npx @autoglot/cli en.json --lang es,fr --project acme/my-app --timeout 120
跳过缓存以强制再翻译 :
npx @autoglot/cli en.yaml --lang pt-BR --no-cache
在一个任务中翻译多个 Xcode 字符串目录, 并有一个超时:
npx @autoglot/cli ios/Layers/**/*.xcstrings --lang de,fr --project acme/ios --input-root . --branch main --deployment-type release --timeout 120
图书馆使用情况
@autoglot/cli 出口a translate() 函数用于节点脚本和其他工具(如 @autoglot/next) (中文(简体) ).
import { translate } from '@autoglot/cli';
import { readFileSync } from 'fs';
const files = await translate({
files: [{
filename: 'frontend/apps/web/locales/en.json',
content: readFileSync('en.json', 'utf-8'),
}],
targetLanguages: ['es', 'fr', 'de'],
sourceLanguage: 'en',
apiKey: process.env.AUTOGLOT_API_KEY!,
project: 'myorg/my-app',
branch: 'main',
deploymentType: 'release',
timeoutSeconds: 120,
onProgress: (status) => {
console.log(`${status.completed_strings}/${status.total_strings}`);
},
});
for (const file of files) {
console.log(file.filename, file.content.length);
}
translate(options)
| 参数 | 类型 | 需求 | 默认 | 说明 |
|---|---|---|---|---|
files | { filename: string; content: string }[] | 对 | 要翻译的文件 。 使用稳定的项目相对文件名进行分析和活动. | |
targetLanguages | string[] | 对 | 目标语言代码 | |
sourceLanguage | string | 对 | 源语言代码 | |
apiKey | string | 对 | API 密钥 | |
apiUrl | string | 没有 | https://api.autoglot.app | API 基础 URL |
project | string | 没有 | 词汇/类型指南项目(owner/repo(中文(简体) ) | |
branch | string | 没有 | 活动记录的源分支;要求 deploymentType 财务报告和审定财务报表 project | |
deploymentType | 'preview' | 'release' | 没有 | 构建活动记录的类型; 需要 branch | |
timeoutSeconds | number | 没有 | 在返回最近兼容的缓存文物之前, 最多等待 。 要求数 project | |
skipCache | boolean | 没有 | false | 跳过翻译缓存 |
onProgress | (status: JobStatus) => void | 没有 | 进度回调 |
回返 Promise<{ filename: string; content: string }[]> ——译出的文件.
JobStatus
对象传递到 onProgress数字 :
| 外地 | 类型 | 说明 |
|---|---|---|
job_id | string | 任务标识符 |
status | string | processing, (中文(简体) ), completed,或 failed |
progress | number | 百分比(0-100) |
total_strings | number | 要翻译的字符串总数 |
completed_strings | number | 迄今翻译的字符串 |
error_message | string? | 失败时出错细节 |
支持的文件格式
| 格式 | 延长 |
|---|---|
| 贾森 | .json |
| 也门 | .yml, (中文(简体) ), .yaml |
| 邮政/邮政 | .po, (中文(简体) ), .pot |
| Xcode 字符串目录 | .xcstrings |
支持的语言
| 代码 | 语言 | 代码 | 语言 |
|---|---|---|---|
de | 德语 | ja | 日本语 |
fr | 法语 | ko | 韩文 |
es | 西班牙语 | zh-Hans | 简化中文 |
it | 意大利语 | zh-Hant | 传统汉语 |
pt | 葡萄牙语 | ar | 阿拉伯语 |
pt-BR | 巴西葡萄牙语 | he | 希伯来语Name |
nl | 荷兰语Name | hi | 印地语 |
pl | 波兰语Name | th | 泰国语Name |
ru | 俄语 | vi | 越南语Name |
uk | 乌克兰语Name | id | 印度尼西亚语Name |
tr | 土耳其语Name | ms | 马来语Name |
sv | 瑞典语 | cs | 捷克语 |
da | 丹麦语Name | hu | 匈牙利语Name |
fi | 芬兰语 | ro | 罗马尼亚语Name |
nb | 挪威语 | sk | 斯洛伐克语 |
el | 希腊语Name | bg | 保加利亚语Name |