CLI

The @autoglot/cli package provides both a command-line tool and a programmatic library for translating locale files. Zero runtime dependencies.

Install

bash
npm install @autoglot/cli

Usage

bash
# Translate en.json into Spanish and French
npx @autoglot/cli en.json --lang es,fr

# Translate a PO file with a project glossary
npx @autoglot/cli messages/en.po --lang de,it,ja --project myorg/my-app

# Keep a build moving with cached translations after two minutes
npx @autoglot/cli messages/en.po --lang de,it,ja --project myorg/my-app --timeout 120

# Output to a specific directory
npx @autoglot/cli locales/en.yaml --lang zh,pt --output dist/locales

# Skip cache to force re-translation
npx @autoglot/cli en.json --lang es --no-cache

Options

OptionAliasDescription
--lang-lComma-separated target languages (required)
--source-sSource language (default: auto-detect from filename)
--output-oOutput directory (default: same as input file)
--project-pProject for glossary/style guide (owner/repo format)
--api-key-kAPI key (default: AUTOGLOT_API_KEY env var)
--no-cacheSkip translation cache

Library usage

The translate() function can be used programmatically in Node.js scripts and build tools:

typescript
import { translate } from '@autoglot/cli';
import { readFileSync } from 'fs';

const files = await translate({
  files: [{ filename: 'en.json', content: readFileSync('en.json', 'utf-8') }],
  targetLanguages: ['es', 'fr', 'de'],
  sourceLanguage: 'en',
  apiKey: process.env.AUTOGLOT_API_KEY,
  project: 'myorg/my-app',
  timeoutSeconds: 120,
  onProgress: (status) => {
    console.log(`${status.completed_strings}/${status.total_strings}`);
  },
});

// files: [{ filename: 'es.json', content: '...' }, ...]

Environment variables

VariableDescription
AUTOGLOT_API_KEYAPI key for authentication
AUTOGLOT_API_URLOverride API base URL (default: https://api.autoglot.app)