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/cliUsage
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-cacheOptions
| Option | Alias | Description |
|---|---|---|
--lang | -l | Comma-separated target languages (required) |
--source | -s | Source language (default: auto-detect from filename) |
--output | -o | Output directory (default: same as input file) |
--project | -p | Project for glossary/style guide (owner/repo format) |
--api-key | -k | API key (default: AUTOGLOT_API_KEY env var) |
--no-cache | Skip 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
| Variable | Description |
|---|---|
AUTOGLOT_API_KEY | API key for authentication |
AUTOGLOT_API_URL | Override API base URL (default: https://api.autoglot.app) |