@autoglot/cli

中文文档
0.1.8发布于 2026/09/02MITTypeScriptCommonJS零依赖构建来源已验证近 30 天下载 1.1万

Translate i18n files using autoglot

原始使用文档
文档目录12 节
  1. Quick start
  2. Setup
  3. CLI usage
  4. Arguments
  5. Options
  6. Examples
  7. Library usage
  8. translate(options)
  9. JobStatus
  10. Supported file formats
  11. Supported languages
  12. Links

@autoglot/cli

Translate i18n files from the command line. Supports JSON, YAML, PO/POT, and Xcode String Catalogs.

Quick start

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

Pass multiple files or a shell glob to translate them together in one job:

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

Setup

  1. Sign up at autoglot.app
  2. Go to dashboard / API keys and create a key
  3. Export it:
export AUTOGLOT_API_KEY=your_key_here

CLI usage

autoglot <files...> --lang <codes> [options]

Arguments

ArgumentDescription
filesSource files to translate in one job (e.g. en.json, en.po, messages.yaml)

Options

OptionAliasDefaultDescription
--lang-l(required)Comma-separated target languages
--source-sAuto-detect from filename, fallback enSource language code
--output-oInput rootOutput directory for translated files; relative input paths are preserved
--input-rootCurrent directory when possibleRoot used for stable source paths in translation context, analytics, and activity
--project-pProject for glossary/style guide (owner/repo format)
--branchSource branch recorded with activity; requires --deployment-type and --project
--deployment-typepreview or release; requires --branch
--api-key-kAUTOGLOT_API_KEY env varAPI key
--api-urlhttps://api.autoglot.appAPI base URL
--timeoutMaximum wait in seconds, then return the latest compatible cached artifact. Requires --project
--no-cachefalseSkip translation cache
--help-hShow help
--version-vShow version

Examples

Translate a JSON file into Spanish, French, and German:

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

Translate a PO file with explicit source language and output directory:

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

Use a project's glossary and style guide:

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

Keep a build moving with cached translations if fresh translation takes more than two minutes:

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

Skip cache to force re-translation:

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

Translate multiple Xcode String Catalogs in one job with one timeout:

npx @autoglot/cli ios/Layers/**/*.xcstrings --lang de,fr --project acme/ios --input-root . --branch main --deployment-type release --timeout 120

Library usage

@autoglot/cli also exports a translate() function for use in Node.js scripts and other tools (like @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)

ParameterTypeRequiredDefaultDescription
files{ filename: string; content: string }[]YesFiles to translate. Use stable project-relative filenames for analytics and activity.
targetLanguagesstring[]YesTarget language codes
sourceLanguagestringYesSource language code
apiKeystringYesAPI key
apiUrlstringNohttps://api.autoglot.appAPI base URL
projectstringNoProject for glossary/style guide (owner/repo)
branchstringNoSource branch recorded with activity; requires deploymentType and project
deploymentType'preview' | 'release'NoBuild type recorded with activity; requires branch
timeoutSecondsnumberNoMaximum wait before returning the latest compatible cached artifact. Requires project
skipCachebooleanNofalseSkip translation cache
onProgress(status: JobStatus) => voidNoProgress callback

Returns Promise<{ filename: string; content: string }[]> — the translated files.

JobStatus

The object passed to onProgress:

FieldTypeDescription
job_idstringJob identifier
statusstringprocessing, completed, or failed
progressnumberPercentage (0–100)
total_stringsnumberTotal strings to translate
completed_stringsnumberStrings translated so far
error_messagestring?Error details if failed

Supported file formats

FormatExtension
JSON.json
YAML.yml, .yaml
PO/POT.po, .pot
Xcode String Catalog.xcstrings

Supported languages

CodeLanguageCodeLanguage
deGermanjaJapanese
frFrenchkoKorean
esSpanishzh-HansSimplified Chinese
itItalianzh-HantTraditional Chinese
ptPortuguesearArabic
pt-BRBrazilian PortugueseheHebrew
nlDutchhiHindi
plPolishthThai
ruRussianviVietnamese
ukUkrainianidIndonesian
trTurkishmsMalay
svSwedishcsCzech
daDanishhuHungarian
fiFinnishroRomanian
nbNorwegianskSlovak
elGreekbgBulgarian

版本与发布记录

@autoglot/cli 共发布 3 个版本,首次发布于 2026/02/23;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.8latest2026/09/022 个月前
0.1.62026/08/232 个月前
0.1.22026/02/238 个月前

关于 @autoglot/cli 的常见问题

@autoglot/cli 是什么?

Translate i18n files using autoglot

如何安装 @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 和提交记录判断。