Translate i18n files from the command line. Supports JSON, YAML, PO/POT, and Xcode String Catalogs.
npx @autoglot/cli en.json --lang es,fr,de- Sign up at autoglot.app
- Go to dashboard / API keys and create a key
- Export it:
export AUTOGLOT_API_KEY=your_key_hereautoglot <file> --lang <codes> [options]
| Argument | Description |
|---|---|
file |
Source file to translate (e.g. en.json, en.po, messages.yaml) |
| Option | Alias | Default | Description |
|---|---|---|---|
--lang |
-l |
(required) | Comma-separated target languages |
--source |
-s |
Auto-detect from filename, fallback en |
Source language code |
--output |
-o |
Same directory as input file | Output directory for translated files |
--project |
-p |
Project for glossary/style guide (owner/repo format) |
|
--api-key |
-k |
AUTOGLOT_API_KEY env var |
API key |
--api-url |
https://api.autoglot.app |
API base URL | |
--no-cache |
false |
Skip translation cache | |
--help |
-h |
Show help | |
--version |
-v |
Show version |
Translate a JSON file into Spanish, French, and German:
npx @autoglot/cli src/locales/en.json --lang es,fr,deTranslate a PO file with explicit source language and output directory:
npx @autoglot/cli messages.po --lang ja,ko --source en --output ./translationsUse a project's glossary and style guide:
npx @autoglot/cli en.json --lang es,fr --project acme/my-appSkip cache to force re-translation:
npx @autoglot/cli en.yaml --lang pt-BR --no-cache@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: 'en.json', content: readFileSync('en.json', 'utf-8') }],
targetLanguages: ['es', 'fr', 'de'],
sourceLanguage: 'en',
apiKey: process.env.AUTOGLOT_API_KEY!,
onProgress: (status) => {
console.log(`${status.completed_strings}/${status.total_strings}`);
},
});
for (const file of files) {
console.log(file.filename, file.content.length);
}| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
files |
{ filename: string; content: string }[] |
Yes | Files to translate | |
targetLanguages |
string[] |
Yes | Target language codes | |
sourceLanguage |
string |
Yes | Source language code | |
apiKey |
string |
Yes | API key | |
apiUrl |
string |
No | https://api.autoglot.app |
API base URL |
project |
string |
No | Project for glossary/style guide (owner/repo) |
|
skipCache |
boolean |
No | false |
Skip translation cache |
onProgress |
(status: JobStatus) => void |
No | Progress callback |
Returns Promise<{ filename: string; content: string }[]> — the translated files.
The object passed to onProgress:
| Field | Type | Description |
|---|---|---|
job_id |
string |
Job identifier |
status |
string |
processing, completed, or failed |
progress |
number |
Percentage (0–100) |
total_strings |
number |
Total strings to translate |
completed_strings |
number |
Strings translated so far |
error_message |
string? |
Error details if failed |
| Format | Extension |
|---|---|
| JSON | .json |
| YAML | .yml, .yaml |
| PO/POT | .po, .pot |
| Xcode String Catalog | .xcstrings |
| Code | Language | Code | Language |
|---|---|---|---|
de |
German | ja |
Japanese |
fr |
French | ko |
Korean |
es |
Spanish | zh-Hans |
Simplified Chinese |
it |
Italian | zh-Hant |
Traditional Chinese |
pt |
Portuguese | ar |
Arabic |
pt-BR |
Brazilian Portuguese | he |
Hebrew |
nl |
Dutch | hi |
Hindi |
pl |
Polish | th |
Thai |
ru |
Russian | vi |
Vietnamese |
uk |
Ukrainian | id |
Indonesian |
tr |
Turkish | ms |
Malay |
sv |
Swedish | cs |
Czech |
da |
Danish | hu |
Hungarian |
fi |
Finnish | ro |
Romanian |
nb |
Norwegian | sk |
Slovak |
el |
Greek | bg |
Bulgarian |