# @autoglot/cli 中文文档

规范地址：https://npmcn.com/package/%40autoglot/cli/

版本：0\.1\.8
npm 元数据更新时间：2026-09-01T17:38:26.309Z
中文译文更新时间：2026-11-07T06:34:56.753Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40autoglot/cli
原文对照：https://npmcn.com/package/%40autoglot/cli/?lang=original
项目主页：https://github.com/autoglot/cli#readme
源码仓库：https://github.com/autoglot/cli

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：30.7 kB，12 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2026-02-22T21:58:09.893Z
- 最新版本发布：2026-09-01T17:38:25.970Z
- 近 30 天下载量：10763（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 3 个）

## 中文简介

使用自动 glot 翻译 i18n 文件

## 安装

```sh
npm install @autoglot/cli
```

也可以使用：`pnpm add @autoglot/cli`、`yarn add @autoglot/cli`、`bun add @autoglot/cli`

## README

# @ autoglot/ cli (英语)

从命令行翻译出i18n文件. 支持JSON,YAML,PO/POT,和Xcode字符串目录.

## 快开始

```bash
npx @autoglot/cli en.json --lang es,fr,de
```

传递多个文件或一个 shell glob 来一起翻译它们 :

```bash
npx @autoglot/cli ios/Layers/**/*.xcstrings --lang es,fr,de
```

## 设置

1.  报名到 [自动glot.app](https://autoglot.app/)
2.  转到 [仪表板/ API 密钥](https://autoglot.app/dashboard/api-keys) 创建密钥
3.  导出 :

```bash
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文件翻译成西班牙文、法文和德文:

```bash
npx @autoglot/cli src/locales/en.json --lang es,fr,de
```

翻译带有明确源语言和输出目录的 PO 文件 :

```bash
npx @autoglot/cli messages.po --lang ja,ko --source en --output ./translations
```

使用项目词汇表和样式指南:

```bash
npx @autoglot/cli en.json --lang es,fr --project acme/my-app
```

如果新译名需要2分钟以上, 保留带有缓存翻译的构建移动 :

```bash
npx @autoglot/cli en.json --lang es,fr --project acme/my-app --timeout 120
```

跳过缓存以强制再翻译 :

```bash
npx @autoglot/cli en.yaml --lang pt-BR --no-cache
```

在一个任务中翻译多个 Xcode 字符串目录, 并有一个超时:

```bash
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`) (中文(简体) ).

```typescript
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 |

## 链接

-   [自动格洛特仪表板](https://autoglot.app/dashboard)
-   [获取 API 密钥](https://autoglot.app/dashboard/api-keys)
-   [报告问题](https://github.com/autoglot/cli/issues)

## 常见问题

### @autoglot/cli 是什么？

使用自动 glot 翻译 i18n 文件

### 如何安装 @autoglot/cli？

在项目目录运行 npm install @autoglot/cli，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 autoglot，可以用 npx autoglot 直接运行。

### @autoglot/cli 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @autoglot/cli 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @autoglot/cli 可以商用吗？

@autoglot/cli 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @autoglot/cli 的下载量有多少？

根据 npm 官方下载统计，@autoglot/cli 在 2026/10/07 – 2026/11/05 这 30 天内被下载 10,763 次，日均约 359 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @autoglot/cli 还在维护吗？

最新版本 0\.1\.8 发布于 2026/09/02（2 个月前）；至今共发布 3 个版本，其中过去 12 个月发布了 3 个；首次发布于 2026/02/23。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

