autoglot 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,14 +16,15 @@
16
16
  <p align="center">
17
17
  <a href="#quickstart">Quickstart</a> ·
18
18
  <a href="#how-it-works">How it works</a> ·
19
+ <a href="#providers">Providers</a> ·
19
20
  <a href="#configuration">Configuration</a> ·
20
21
  <a href="#cli-flags">CLI reference</a>
21
22
  </p>
22
23
 
23
- autoglot translates JSON message catalogs with Claude. Edit your source locale, then run the CLI or let the GitHub Action commit the updated translations to your branch. Your runtime library, such as [next-intl](https://next-intl.dev/), [react-i18next](https://react.i18next.com/), or [Vue I18n](https://vue-i18n.intlify.dev/), reads the resulting files.
24
+ autoglot translates JSON message catalogs with Claude by default, or with OpenAI, Gemini, a local model, or [another provider](#providers). Edit your source locale, then run the CLI or let the GitHub Action commit the updated translations to your branch. Your runtime library, such as [next-intl](https://next-intl.dev/), [react-i18next](https://react.i18next.com/), or [Vue I18n](https://vue-i18n.intlify.dev/), reads the resulting files.
24
25
 
25
26
  - **Incremental.** A committed lock file tracks source strings. autoglot translates new, changed, and missing keys and removes orphaned entries.
26
- - **Runs where you work.** Use Node.js 20+ locally or in CI. The CLI has zero runtime dependencies and sends translation requests to Anthropic with your API key.
27
+ - **Runs where you work.** Use Node.js 20+ locally or in CI. The CLI has zero runtime dependencies and sends translation requests to the AI provider you choose, with your own API key.
27
28
  - **Reviewable.** The GitHub Action commits JSON changes and can post token usage and estimated cost on an open PR.
28
29
 
29
30
  ## Quickstart
@@ -35,8 +36,8 @@ With Node.js 20 or newer, create an empty directory and preview German translati
35
36
  ```bash
36
37
  mkdir autoglot-demo
37
38
  cd autoglot-demo
38
- npx --yes autoglot@0.4.3 init --locales=de
39
- npx --yes autoglot@0.4.3 --dry-run
39
+ npx --yes autoglot@0.5.0 init --locales=de
40
+ npx --yes autoglot@0.5.0 --dry-run
40
41
  ```
41
42
 
42
43
  `init` creates the English and German JSON catalogs and `translate.config.json`. It also generates a GitHub workflow file that you can ignore for local use. The dry run exits with status `0` and includes these lines for the fresh starter catalog.
@@ -49,7 +50,7 @@ npx --yes autoglot@0.4.3 --dry-run
49
50
  To check whether translations are up to date, run this separately.
50
51
 
51
52
  ```bash
52
- npx --yes autoglot@0.4.3 --check
53
+ npx --yes autoglot@0.5.0 --check
53
54
  ```
54
55
 
55
56
  On this fresh catalog, the check prints `Locales needing updates: de` and exits with status `1` because the German translations are pending. Both commands leave the catalogs and lock file untouched.
@@ -59,16 +60,18 @@ On this fresh catalog, the check prints `Locales needing updates: de` and exits
59
60
  When you're ready to translate, edit `messages/en.json`, set `ANTHROPIC_API_KEY` in your environment, and run the CLI without a preview flag. This sends requests to Anthropic and can incur API charges.
60
61
 
61
62
  ```bash
62
- npx --yes autoglot@0.4.3
63
+ npx --yes autoglot@0.5.0
63
64
  ```
64
65
 
66
+ To translate with a different provider, see [Providers](#providers).
67
+
65
68
  For a dry run with existing catalogs, see the [basic example](https://github.com/ffcabbar/autoglot/tree/main/examples/basic).
66
69
 
67
70
  ### Set up an existing app
68
71
 
69
- Run `npx autoglot init` in your app directory and choose your target locales. To set them without prompts, use `npx --yes autoglot@0.4.3 init --locales=de,pt-BR`. Setup creates missing files and skips existing paths. Add `--install` to install the suggested runtime libraries. If that install fails, unattended setup exits with an error after printing the retry command.
72
+ Run `npx autoglot init` in your app directory and choose your target locales. To set them without prompts, use `npx --yes autoglot@0.5.0 init --locales=de,pt-BR`. Setup creates missing files and skips existing paths. Add `--install` to install the suggested runtime libraries. If that install fails, unattended setup exits with an error after printing the retry command.
70
73
 
71
- For GitHub automation, add `ANTHROPIC_API_KEY` to your repository secrets before pushing changes to the source catalog.
74
+ For GitHub automation, add `ANTHROPIC_API_KEY` to your repository secrets before pushing changes to the source catalog. To scaffold for another provider, pass `--provider=<name>`; setup then writes that provider to the config, uses its secret name in the workflow, and prints which secret to add. For a provider that runs on your machine, such as `ollama`, setup skips the GitHub workflow, because a GitHub runner cannot reach it.
72
75
 
73
76
  ### Supported frameworks
74
77
 
@@ -177,21 +180,127 @@ jobs:
177
180
 
178
181
  The action detects pull_request events automatically and pushes translations to the PR's source branch. If you forget the `ref:` line, autoglot prints an error explaining how to fix it instead of silently doing the wrong thing.
179
182
 
183
+ ### Action inputs
184
+
185
+ | Input | Default | What it does |
186
+ |---|---|---|
187
+ | `anthropic-api-key` | | Anthropic API key. Needed when the provider is `anthropic`. |
188
+ | `api-key` | | Unbound key for a gateway or an `openai-compatible` endpoint. It is sent to whatever `base-url` / `baseUrl` is configured. For a vendor at its own endpoint, use step `env:` with the vendor variable instead (see below). |
189
+ | `provider` | `anthropic` | One of the [providers](#providers). Falls back to `provider` in the config. Providers other than `anthropic` are verified against simulated responses only. |
190
+ | `model` | `claude-haiku-4-5` for Anthropic | Model id. Every other provider needs one, here or in the config. |
191
+ | `base-url` | the provider's endpoint | API base URL. Needed for `openai-compatible`. |
192
+ | `config` | `translate.config.json` | Path to the config file. |
193
+ | `source`, `messages-dir`, `lock-file` | from the config | Path overrides. |
194
+ | `commit` | `true` | Commit and push translation changes to the branch. |
195
+ | `pr-comment` | `true` | Post the cost summary on the open PR. |
196
+ | `package-version` | bundled CLI | Run a specific npm version of the CLI. |
197
+
198
+ Existing workflows that pass `anthropic-api-key` keep working unchanged. For another vendor, pass its key as step `env:` under the vendor's own variable name. `autoglot init --provider=<name>` generates this.
199
+
200
+ ```yaml
201
+ - uses: ffcabbar/autoglot@v1
202
+ env:
203
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
204
+ with:
205
+ provider: openai
206
+ model: <model-id>
207
+ ```
208
+
209
+ A vendor variable (and `anthropic-api-key`, which fills `ANTHROPIC_API_KEY`) is only ever sent to that vendor's own host, so a `baseUrl` added to `translate.config.json` cannot redirect it. Use the `api-key` input only when you mean to send a key to a gateway or an `openai-compatible` endpoint. That key is unbound: it goes to whatever base URL is configured, so review changes to `baseUrl` as carefully as changes to the workflow.
210
+
211
+ ```yaml
212
+ - uses: ffcabbar/autoglot@v1
213
+ with:
214
+ provider: openai-compatible
215
+ base-url: https://<your-gateway>/v1
216
+ model: <model-id>
217
+ api-key: ${{ secrets.AUTOGLOT_API_KEY }}
218
+ ```
219
+
220
+ If the selected provider needs a key and none is passed, the run stops with an error that names the missing variable before any request is sent.
221
+
180
222
  ## vs. the alternatives
181
223
 
182
224
  | | **autoglot** | Languine | Lokalise / Crowdin / Phrase | i18n-ai-translate |
183
225
  |---|:---:|:---:|:---:|:---:|
184
- | License | **MIT** | AGPL-3.0 | Proprietary | MIT |
185
- | SaaS account required | **No** | No (CLI) | **Yes** | No |
186
- | Hosted dashboard | None | Optional | Required | None |
187
- | GitHub Action | **Yes (built-in)** | Yes | Plugin | No |
226
+ | License | **MIT** | MIT | Proprietary | MIT |
227
+ | Accounts needed | Model provider | Vercel (hosting, database, AI Gateway) | Vendor account | Model provider (none with local Ollama) |
228
+ | Server to deploy | **None** | Your own Vercel app + Postgres | n/a (vendor-hosted) | None |
229
+ | Dashboard | None | On your deployment | Vendor-hosted (required) | None |
230
+ | GitHub Action | **Yes (built-in)** | Yes (calls your deployment) | Plugin | No |
188
231
  | Bot commits the diff back | **Yes** | Yes | Manual | No |
189
- | Cost per ~1k-key PR | **<$0.01** | <$0.01 | $5–$50 | <$0.01 |
190
- | Dependencies | **0** | many | n/a (SaaS) | several |
191
- | Multi-provider | v0.2 | Yes | n/a | Yes |
232
+ | Cost | Model usage at provider rates | Model usage via Vercel AI Gateway, plus hosting | $5–$50 per ~1k-key PR | Model usage at provider rates |
233
+ | Dependencies | **0** | 30 (CLI) | n/a (SaaS) | several |
234
+ | Multi-provider | **Yes** (Anthropic run live; others simulated-only) | One model, any Vercel AI Gateway provider | n/a | Yes |
192
235
  | Formats | JSON | 15+ | 15+ | JSON |
193
236
  | Self-hosted | **Yes** | Yes | No | Yes |
194
237
 
238
+ [Languine](https://github.com/languine-ai/languine) v4 is MIT-licensed and self-hosted: you deploy its web app to your own Vercel account with a Postgres database, then point its CLI and Action at that deployment. It reads many more file formats than autoglot. autoglot has no deployment, database, or login: one `npx` command and your own provider key.
239
+
240
+ ## Providers
241
+
242
+ Anthropic is the default, and nothing changes for existing projects. To use another provider, set a provider, a model, and that provider's API key. Catalogs, the lock file, checks, and the Action work the same way with every provider.
243
+
244
+ ```bash
245
+ export OPENAI_API_KEY=... # your own key, read from the environment
246
+ npx autoglot --provider=openai --model=<model-id>
247
+ ```
248
+
249
+ Or keep the choice in `translate.config.json`.
250
+
251
+ ```json
252
+ {
253
+ "provider": "openai",
254
+ "model": "<model-id>"
255
+ }
256
+ ```
257
+
258
+ > **Status.** Only `anthropic` has been run against its live API. Every other provider in this table is verified against simulated responses written from the vendor's documentation, and has not yet been run against the live API. Start with `--dry-run`, then try one small locale with `--locales=<code>` before a full run.
259
+
260
+ | Provider | API key variable | Example | Status | Notes |
261
+ |---|---|---|---|---|
262
+ | `anthropic` *(default)* | `ANTHROPIC_API_KEY` | `--model=claude-haiku-4-5` | Live | Default model `claude-haiku-4-5`. |
263
+ | `openai` | `OPENAI_API_KEY` | `--provider=openai --model=<model-id>` | Simulated only | Responses API, with `store: false` (see the note below). |
264
+ | `gemini` | `GEMINI_API_KEY` or `GOOGLE_API_KEY` | `--provider=gemini --model=<model-id>` | Simulated only | `generateContent` API. If both variables are set, `GOOGLE_API_KEY` wins. |
265
+ | `xai` | `XAI_API_KEY` | `--provider=xai --model=<model-id>` | Simulated only | Responses API, with `store: false`. |
266
+ | `deepseek` | `DEEPSEEK_API_KEY` | `--provider=deepseek --model=<model-id>` | Simulated only | Thinking mode is turned off for the request, because it rejects a forced tool call. |
267
+ | `openrouter` | `OPENROUTER_API_KEY` | `--provider=openrouter --model=<vendor/model-id>` | Simulated only | Pick a model that supports tool calling. |
268
+ | `groq` | `GROQ_API_KEY` | `--provider=groq --model=<model-id>` | Simulated only | |
269
+ | `mistral` | `MISTRAL_API_KEY` | `--provider=mistral --model=<model-id>` | Simulated only | |
270
+ | `together` | `TOGETHER_API_KEY` | `--provider=together --model=<model-id>` | Simulated only | |
271
+ | `ollama` | none | `--provider=ollama --model=<local-model>` | Simulated only | Local server at `http://localhost:11434/v1`. No key. |
272
+ | `openai-compatible` | `AUTOGLOT_API_KEY` (optional) | `--provider=openai-compatible --base-url=<url> --model=<model-id>` | Simulated only | Any endpoint that speaks the OpenAI Chat Completions format. |
273
+
274
+ Use the model ids from your provider's own documentation. Only Anthropic has a default model; every other provider needs `--model` or `"model"` in the config, and autoglot says so if it is missing.
275
+
276
+ **Other vendors and local servers.** `openai-compatible` is for any service that documents an OpenAI-compatible Chat Completions endpoint with tool calling, for example LM Studio's local server at `http://localhost:1234/v1`. If your vendor documents one (Alibaba Qwen on DashScope, Moonshot Kimi, Zhipu GLM, a vLLM server, and so on), take the base URL from its documentation and pass it with `--base-url` or `"baseUrl"`. None of these has been tried, and autoglot ships no preset for them.
277
+
278
+ **Base URLs.**
279
+
280
+ - Give the API base, not the full endpoint: `https://api.example.com/v1`, not `https://api.example.com/v1/chat/completions`. autoglot adds the path and rejects a pasted endpoint, a query string, a fragment, or a URL with a username or password.
281
+ - For `anthropic`, the base is the API root. `https://gateway.example` and `https://gateway.example/v1` both send to `/v1/messages`.
282
+ - A `baseUrl` belongs to the provider it was written for. If the config sets `provider` and `baseUrl` and you pick a different provider with `--provider`, the config's `baseUrl` and `model` are ignored (with a warning for the URL), and you pass `--model` yourself. The same holds for `AUTOGLOT_BASE_URL` and `AUTOGLOT_MODEL` against a provider set in the config.
283
+ - Whenever requests go anywhere other than the provider's own endpoint, the run prints an `Endpoint:` line and adds it to the summary.
284
+ - Redirects are not followed.
285
+
286
+ **API keys.**
287
+
288
+ - Keys are read from environment variables only. autoglot refuses to run if `translate.config.json` contains an `apiKey` field, and there is no key flag.
289
+ - `AUTOGLOT_API_KEY` works for every provider and wins over the provider's own variable.
290
+ - A vendor variable such as `ANTHROPIC_API_KEY` or `OPENAI_API_KEY` is used only for that vendor's own host. **To route any provider through a gateway or proxy, set `AUTOGLOT_API_KEY`** (Action input `api-key`). With a custom base URL and only the vendor variable set, the run stops before any request and names the host. This keeps an edited `baseUrl` from carrying a vendor key to another server.
291
+ - `openai-compatible` and `ollama` read only `AUTOGLOT_API_KEY`.
292
+ - `AUTOGLOT_API_KEY` is sent to whatever base URL is configured. Review changes to `baseUrl` in `translate.config.json` as you would review a change to a workflow.
293
+ - A key is not sent over plain `http` to another machine. Use `https`, or set `"allowInsecureHttp": true` (or `--allow-insecure-http`) if you accept the risk. `http://localhost` is allowed.
294
+ - Your source strings are sent to the provider you select. Check that provider's data-handling terms. For OpenAI and xAI, `store: false` only turns off the stored response object that could be fetched or continued later; it does not change the provider's own retention, such as abuse monitoring.
295
+
296
+ **Structured output is required.** Every provider is asked for a forced tool or function call and autoglot reads only that call. If a model answers in prose, returns arguments that are not valid JSON, omits a key, or returns an empty string for real text (unless `allowEmptyTranslations` is set), autoglot retries once and then fails without writing that locale. If a reply is cut off at the output limit, or the provider refuses, blocks, or reports an error inside the reply, the run fails at once without a second request. One exception: a Gemini reply marked `MALFORMED_FUNCTION_CALL` is retried once like any other malformed call. Ollama's OpenAI-compatible endpoint does not support forcing a tool call, so a local model has to choose the tool by itself; use a model with reliable tool calling. Local models often have small context windows, so lower `chunkSize` (for example `"chunkSize": 25`) if replies are cut off or keys go missing.
297
+
298
+ **Rate limits.** A `429` is retried up to five times. For Anthropic the wait is the `retry-after` seconds, or 60 when the header is missing, exactly as before. For other providers `retry-after` may be seconds or a date, and each wait is kept between 0 and 120 seconds. A `429` that reports exhausted quota or credit is not retried.
299
+
300
+ **Request parameters.** Anthropic requests keep `max_tokens: 8192` and `temperature: 0`. For other providers autoglot sends no output limit unless you set `maxOutputTokens`, because reasoning models count their thinking against it. `temperature: 0` is sent where the provider documents it and left out for OpenAI; set `"temperature"` in the config to a number to send one, or to `null` to leave it out.
301
+
302
+ See [`examples/providers`](https://github.com/ffcabbar/autoglot/tree/main/examples/providers) for a keyless dry run with a non-default provider.
303
+
195
304
  ## Configuration
196
305
 
197
306
  `translate.config.json` (optional — sensible defaults):
@@ -218,7 +327,15 @@ The action detects pull_request events automatically and pushes translations to
218
327
  | `source` | `messages/en.json` | Path to your source-of-truth locale file. |
219
328
  | `messagesDir` | `messages` | Where the other `<locale>.json` files live. |
220
329
  | `lockFile` | `translate.lock` | Where to store md5 fingerprints. Commit it. |
221
- | `model` | `claude-haiku-4-5` | Anthropic model. Haiku is recommended; quality is excellent. |
330
+ | `provider` | `anthropic` | Which [provider](#providers) translates. |
331
+ | `model` | `claude-haiku-4-5` | Model id. The default applies to Anthropic only; other providers need one. |
332
+ | `baseUrl` | the provider's endpoint | API base URL. Required for `openai-compatible`. |
333
+ | `pricing` | built-in for listed Claude models | `{ "input": 1.0, "output": 5.0 }` in USD per 1M tokens. Enables cost reporting for any model. |
334
+ | `chunkSize` | `200` | Keys sent per request. Lower it if a reply is cut off. |
335
+ | `maxOutputTokens` | `8192` for Anthropic, provider default otherwise | Output token limit per request. |
336
+ | `temperature` | per provider | A number to send, or `null` to leave it out of the request. |
337
+ | `allowInsecureHttp` | `false` | Allow sending an API key over plain `http` to a host other than this machine. |
338
+ | `allowEmptyTranslations` | `false` | Accept an empty string as the translation of non-empty source text. By default that is retried once and then rejected. |
222
339
  | `glossary` | `[]` | Product/brand names the model must keep verbatim. |
223
340
  | `namespaceContext` | `{}` | Hint the model about each top-level namespace. Improves quality. |
224
341
  | `namespaces` | `{}` | Map namespaces to their target locale lists. Other namespaces go to all target locales. |
@@ -230,7 +347,12 @@ The action detects pull_request events automatically and pushes translations to
230
347
  --dry-run Preview the translation plan without updating catalogs.
231
348
  --quiet Suppress per-locale and per-chunk progress. CI keeps verbose logs.
232
349
  --locales=de,fr Restrict run to specific locales.
350
+ --provider=<name> Pick the AI provider (default: anthropic).
233
351
  --model=<id> Override the configured model.
352
+ --base-url=<url> Override the provider's API base URL.
353
+ --chunk-size=<n> Keys per request (default: 200).
354
+ --max-output-tokens=<n> Output token limit per request.
355
+ --allow-insecure-http Allow sending an API key over plain http to another machine.
234
356
  --source=<path> Override config.source.
235
357
  --messages-dir=<path> Override config.messagesDir.
236
358
  --lock-file=<path> Override config.lockFile.
@@ -241,6 +363,8 @@ The action detects pull_request events automatically and pushes translations to
241
363
  -h, --help Print help and exit.
242
364
  ```
243
365
 
366
+ Each setting is resolved in this order: CLI flag, then `translate.config.json`, then environment (`AUTOGLOT_PROVIDER`, `AUTOGLOT_MODEL`, `AUTOGLOT_BASE_URL`), then the built-in default. A model or base URL from a lower level is used only if that level was set up for the provider that ends up selected; see [Base URLs](#providers).
367
+
244
368
  Use `--locales=es` to translate only Spanish. Later runs reuse that work if the source string is still the same and the translation is present. After an English edit in a project with Spanish and German catalogs, running `--locales=es` and then running without the flag sends the changed string once for Spanish and once for German. Existing v1 lock files work as-is. Keep the updated lock file with the catalogs so later runs can reuse the recorded progress.
245
369
 
246
370
  On case-insensitive filesystems, `pt-br` refers to an existing `pt-BR.json` in both `--locales` and `namespaces` locale lists. A case-only rename carries the catalog's recorded progress to the new filename. If your filesystem has distinct catalogs that differ only in case, use the exact locale spelling from the filename.
@@ -259,6 +383,18 @@ After a fatal locale error, Autoglot stops starting queued locales and lets acti
259
383
 
260
384
  Cost depends on the catalog, target locales, and token usage. See [Anthropic’s pricing](https://platform.claude.com/docs/en/about-claude/pricing) for current rates.
261
385
 
386
+ Any model id is accepted, for every provider. autoglot has built-in prices for the three models above. For any other model, including every non-Anthropic one, the run reports token counts and shows the cost as `n/a`. To get a cost estimate, add the rates from your provider's pricing page to the config.
387
+
388
+ ```json
389
+ {
390
+ "provider": "openai",
391
+ "model": "<model-id>",
392
+ "pricing": { "input": 1.0, "output": 5.0 }
393
+ }
394
+ ```
395
+
396
+ `pricing` is in USD per 1M tokens. It also overrides the built-in price of a listed model. The estimate uses the input and output token counts the provider reports and does not account for cache or batch discounts.
397
+
262
398
  ## Migrating from Languine
263
399
 
264
400
  ```bash
@@ -266,7 +402,9 @@ npx autoglot --import-languine=languine.lock
266
402
  npx autoglot --dry-run
267
403
  ```
268
404
 
269
- Keep your existing locale files and review the dry-run output before replacing the Languine workflow. Missing translations and strings that changed since the imported hashes will appear in the plan.
405
+ `languine.lock` sits next to `languine.json`. The importer reads the entry for your source JSON catalog and ignores entries for other files.
406
+
407
+ Keep your existing locale files and review the dry-run output before replacing the Languine workflow: it prints how many keys each locale would get. To see key names, run `npx autoglot --check`, which lists the new or changed source keys and the locales that need updates, and exits with status `1` while anything is pending. The import prints the entries it did not carry over. Any key it could not match to your source catalog appears as new and is re-translated, and array values are re-translated on the first run because Languine hashes each array item while autoglot hashes the whole array as one value.
270
408
 
271
409
  ## How it works
272
410
 
@@ -276,7 +414,7 @@ Keep your existing locale files and review the dry-run output before replacing t
276
414
 
277
415
  1. **Flatten** your source JSON to dotted keys: `{ "checkout.cta": "Pay now" }`.
278
416
  2. **Diff** each value's md5 against the lock file. The shared hashes track progress across all applicable locales, and optional per-locale hashes record progress when locales differ.
279
- 3. **For each locale**: collect missing + changed keys, chunk into batches of 200, call Anthropic with forced [tool use](https://docs.anthropic.com/en/docs/build-with-claude/tool-use) so the response is structured JSON (not freeform).
417
+ 3. **For each locale**: collect missing + changed keys, chunk into batches of 200, call the provider with a forced tool call (Anthropic [tool use](https://docs.anthropic.com/en/docs/build-with-claude/tool-use), or function calling elsewhere) so the response is structured JSON (not freeform).
280
418
  4. **Validate** placeholders (`{name}`) match between source and translation; retry on mismatch.
281
419
  5. **Merge** translations back into the locale's JSON, preserving source key order, dropping orphan keys.
282
420
  6. **Update** the lock file, write a markdown summary, exit.
@@ -295,21 +433,21 @@ Yes. `npx autoglot init` has explicit support for **Next.js (App Router & Pages
295
433
  <details>
296
434
  <summary><strong>What about ICU plurals, dates, gender?</strong></summary>
297
435
 
298
- ICU syntax (`{count, plural, one {# day} other {# days}}`) is preserved by the system prompt to Claude. The placeholder validator covers `{name}` tokens; ICU structure is handled by the model and should be reviewed in the resulting JSON.
436
+ ICU syntax (`{count, plural, one {# day} other {# days}}`) is preserved by the system prompt sent to the model. The placeholder validator covers `{name}` tokens; ICU structure is handled by the model and should be reviewed in the resulting JSON.
299
437
 
300
438
  </details>
301
439
 
302
440
  <details>
303
441
  <summary><strong>Why JSON only?</strong></summary>
304
442
 
305
- JSON covers ~95% of JS app i18n. Adding YAML / `.strings` / Android XML triples the test surface. We'd rather do JSON well than 15 formats badly. v0.3+ if there's demand.
443
+ JSON covers ~95% of JS app i18n. Adding YAML / `.strings` / Android XML triples the test surface. We'd rather do JSON well than 15 formats badly. ARB, YAML and Java `.properties` support is in development and has not shipped.
306
444
 
307
445
  </details>
308
446
 
309
447
  <details>
310
- <summary><strong>Why not OpenAI / Gemini?</strong></summary>
448
+ <summary><strong>Can I use OpenAI, Gemini, Grok, DeepSeek, or a local model?</strong></summary>
311
449
 
312
- The current release supports Anthropic. Follow the [roadmap](ROADMAP.md) for provider plans.
450
+ Yes. Anthropic is the default, and `--provider` selects OpenAI, Gemini, xAI, DeepSeek, OpenRouter, Groq, Mistral, Together AI, Ollama, or any OpenAI-compatible endpoint. You bring the key and the model id. These providers are verified against simulated responses only and have not yet been run against the live APIs. See [Providers](#providers).
313
451
 
314
452
  </details>
315
453
 
@@ -330,16 +468,17 @@ Yes. `npx autoglot` works in any CI (GitLab, CircleCI, Jenkins, your laptop). Th
330
468
  <details>
331
469
  <summary><strong>How do I keep brand names from being translated?</strong></summary>
332
470
 
333
- Add them to `glossary` in `translate.config.json`. They'll be passed to Claude with explicit instruction to leave them verbatim.
471
+ Add them to `glossary` in `translate.config.json`. They'll be passed to the model with explicit instruction to leave them verbatim.
334
472
 
335
473
  </details>
336
474
 
337
475
  ## Roadmap
338
476
 
339
- - [x] **v0.1** — Anthropic, JSON, GitHub Action, Languine importer, parallel locales, lock file
340
- - [ ] **v0.2** — Multi-provider (OpenAI, Gemini), provider-fallback chain
341
- - [ ] **v0.3** — YAML / `.strings` / Android XML formats (gated on demand)
342
- - [ ] **v0.4** — Hosted GitHub App (real bot avatar, one-click install) — paid tier, OSS still first-class
477
+ - [x] Anthropic, JSON catalogs, GitHub Action, Languine importer, parallel locales, lock file
478
+ - [x] Multi-provider — OpenAI, Gemini, xAI, DeepSeek, and OpenAI-compatible endpoints (simulated responses only so far)
479
+ - [ ] Run each non-Anthropic provider against its live API
480
+ - [ ] More file formats — ARB, YAML and Java `.properties`: in development
481
+ - [ ] Provider-fallback chain
343
482
 
344
483
  See the [roadmap](ROADMAP.md) for upcoming work and the [open issues](https://github.com/ffcabbar/autoglot/issues) for current maintenance tasks.
345
484
 
@@ -347,7 +486,8 @@ See the [roadmap](ROADMAP.md) for upcoming work and the [open issues](https://gi
347
486
 
348
487
  Issues, PRs, and bug reports welcome. The codebase is intentionally tiny:
349
488
 
350
- - `bin/translate.mjs` (≈ 500 lines) — the entire engine
489
+ - `bin/translate.mjs` (≈ 750 lines) — the translation engine
490
+ - `bin/providers/` — one small module per wire format (Anthropic, OpenAI Responses, OpenAI-compatible Chat Completions, Gemini) plus the preset list
351
491
  - `bin/helpers.mjs` — pure helpers
352
492
  - `tests/helpers.test.mjs` — `node:test` suite, runs offline
353
493
 
@@ -360,7 +500,7 @@ cd examples/basic && node ../../bin/cli.mjs --dry-run
360
500
 
361
501
  ## Sponsor
362
502
 
363
- If `autoglot` saves you the cost of a Languine subscription, consider [sponsoring on GitHub](https://github.com/sponsors/ffcabbar). The whole project is one person's evenings.
503
+ If `autoglot` saves you the cost of a translation SaaS subscription, consider [sponsoring on GitHub](https://github.com/sponsors/ffcabbar). The whole project is one person's evenings.
364
504
 
365
505
  ## License
366
506
 
package/bin/cli.mjs CHANGED
@@ -14,6 +14,7 @@
14
14
  // continues to work without changes.
15
15
 
16
16
  import { readFileSync } from "node:fs";
17
+ import { providerHelpLines } from "./providers/index.mjs";
17
18
 
18
19
  const argv = process.argv.slice(2);
19
20
  const first = argv[0];
@@ -34,6 +35,9 @@ init flags
34
35
  --install Install runtime i18n library after scaffolding.
35
36
  --no-install Skip the interactive install prompt.
36
37
  --pm=npm|yarn|pnpm|bun Override the auto-detected package manager.
38
+ --provider=<name> Scaffold for this AI provider (default: anthropic).
39
+ --model=<id> Model id to write to translate.config.json.
40
+ --base-url=<url> API base URL to write to translate.config.json.
37
41
 
38
42
  extract flags
39
43
  --write Merge candidates into messages/en.json (existing
@@ -49,7 +53,15 @@ Translation flags (when no subcommand given)
49
53
  --quiet Suppress per-locale progress (auto-disabled in CI).
50
54
  --locales=de,fr Restrict run to specific locales.
51
55
  Match filename casing to distinguish case variants.
56
+ --provider=<name> AI provider (default: anthropic). See Providers below.
52
57
  --model=<id> Override the configured model (default: claude-haiku-4-5).
58
+ Required for every provider except anthropic.
59
+ --base-url=<url> Override the provider's API base URL.
60
+ Required for --provider=openai-compatible.
61
+ --chunk-size=<n> Keys per request (default: 200).
62
+ --max-output-tokens=<n> Output token limit per request.
63
+ --allow-insecure-http Allow sending an API key over plain http to a
64
+ host other than this machine.
53
65
  --source=<path> Override config.source (default: messages/en.json).
54
66
  --messages-dir=<path> Override config.messagesDir (default: messages).
55
67
  --lock-file=<path> Override config.lockFile (default: translate.lock).
@@ -57,8 +69,20 @@ Translation flags (when no subcommand given)
57
69
  --import-languine[=<path>] Seed our lock file from a languine.lock and exit.
58
70
  --summary-path=<path> Where to write the markdown summary.
59
71
 
72
+ Providers (--provider=<name>, with the API key variable each one reads)
73
+ ${providerHelpLines().join("\n")}
74
+ Providers other than anthropic are verified against simulated responses
75
+ only. They have not yet been run against the live APIs.
76
+
60
77
  Environment
61
- ANTHROPIC_API_KEY Required when sending translation requests.
78
+ ANTHROPIC_API_KEY Required when sending translation requests to Anthropic.
79
+ AUTOGLOT_API_KEY API key for the selected provider. Wins over the
80
+ provider's own variable, and is the only key read
81
+ when --base-url points away from the provider's
82
+ own endpoint.
83
+ AUTOGLOT_PROVIDER, AUTOGLOT_MODEL, AUTOGLOT_BASE_URL
84
+ Defaults for --provider, --model and --base-url.
85
+ API keys are read from the environment only, never from translate.config.json.
62
86
 
63
87
  Docs
64
88
  https://github.com/ffcabbar/autoglot
package/bin/doctor.mjs CHANGED
@@ -7,6 +7,7 @@ import { readFileSync, existsSync, readdirSync, statSync } from "node:fs";
7
7
  import { join, relative, basename } from "node:path";
8
8
  import { ok, warn, err, info, step } from "./prompts.mjs";
9
9
  import { resolvePaths, parseSharedFlags, findRepoRoot } from "./config.mjs";
10
+ import { GENERIC_KEY_ENV, keyNames, resolveApiKey, resolveProvider } from "./providers/index.mjs";
10
11
 
11
12
  export async function run(argv = []) {
12
13
  const { args } = parseSharedFlags(argv);
@@ -36,6 +37,23 @@ export async function run(argv = []) {
36
37
  w("translate.config.json not found — autoglot will use defaults. Consider `autoglot init`.");
37
38
  }
38
39
 
40
+ // 1b. Provider, model and endpoint (flags > config > environment > default)
41
+ let provider = null;
42
+ try {
43
+ provider = resolveProvider({ args, config: paths.config || {}, env: process.env });
44
+ for (const warning of provider.warnings) w(warning);
45
+ if (provider.name !== "anthropic" || provider.endpoint) {
46
+ ok(`Provider ${provider.name}, model ${provider.model}, endpoint ${provider.baseUrl}.`);
47
+ }
48
+ if (provider.customEndpoint && provider.def.keyEnv.length) {
49
+ info(`The endpoint is not ${provider.label}'s own, so only AUTOGLOT_API_KEY (Action input: api-key) is used as the key.`);
50
+ }
51
+ } catch (errObj) {
52
+ e(errObj.message);
53
+ }
54
+ const keyVars = provider ? keyNames(provider.def, provider.baseUrl) : ["ANTHROPIC_API_KEY"];
55
+ const keyRequired = provider ? provider.def.keyRequired : true;
56
+
39
57
  // 2. Source file
40
58
  const sourceDisplay = relative(cwd, paths.source) || paths.source;
41
59
  if (existsSync(paths.source)) {
@@ -84,10 +102,22 @@ export async function run(argv = []) {
84
102
 
85
103
  if (foundWorkflow) {
86
104
  ok(`Workflow ${relative(cwd, foundWorkflow.path) || foundWorkflow.path} uses ffcabbar/autoglot.`);
87
- if (foundWorkflow.content.includes("ANTHROPIC_API_KEY")) {
88
- ok("Workflow references ANTHROPIC_API_KEY secret.");
105
+ if (!provider) {
106
+ info("Skipping the workflow key check until the provider setting above is fixed.");
107
+ } else if (provider.name === "anthropic" && !provider.customEndpoint) {
108
+ if (foundWorkflow.content.includes("ANTHROPIC_API_KEY")) {
109
+ ok("Workflow references ANTHROPIC_API_KEY secret.");
110
+ } else {
111
+ w("Workflow doesn't reference ANTHROPIC_API_KEY. autoglot will fail without it.");
112
+ }
89
113
  } else {
90
- w("Workflow doesn't reference ANTHROPIC_API_KEY. autoglot will fail without it.");
114
+ const referenced = keyVars.find((name) => foundWorkflow.content.includes(name));
115
+ // `anthropic-api-key` only fills ANTHROPIC_API_KEY, so it does not count here.
116
+ const passesKey = /^\s*api-key\s*:/m.test(foundWorkflow.content);
117
+ if (referenced) ok(`Workflow references ${referenced} secret.`);
118
+ else if (passesKey) ok("Workflow passes an API key to the action.");
119
+ else if (keyRequired) w(`Workflow doesn't reference ${keyVars.join(" or ")}. Provider ${provider.name} will fail without a key.`);
120
+ else info(`Workflow passes no API key — fine if your ${provider.label} endpoint needs none.`);
91
121
  }
92
122
  } else if (existsSync(workflowsDir)) {
93
123
  w(`No workflow in ${relative(cwd, workflowsDir) || workflowsDir}/ references ffcabbar/autoglot. Run \`autoglot init\` or add one manually.`);
@@ -105,11 +135,22 @@ export async function run(argv = []) {
105
135
  }
106
136
  }
107
137
 
108
- // 6. ANTHROPIC_API_KEY in env (only relevant for local runs)
109
- if (process.env.ANTHROPIC_API_KEY) {
110
- ok("ANTHROPIC_API_KEY set in current shell.");
138
+ // 6. API key in env (only relevant for local runs). The value is never printed.
139
+ if (!provider) {
140
+ info("Skipping the API key check until the provider setting above is fixed.");
141
+ } else if (provider.name === "anthropic" && !provider.customEndpoint) {
142
+ if (process.env.ANTHROPIC_API_KEY) {
143
+ ok("ANTHROPIC_API_KEY set in current shell.");
144
+ } else if (process.env[GENERIC_KEY_ENV]) {
145
+ ok(`${GENERIC_KEY_ENV} set in current shell.`);
146
+ } else {
147
+ info("ANTHROPIC_API_KEY not set in this shell — fine for CI; only needed for local runs.");
148
+ }
111
149
  } else {
112
- info("ANTHROPIC_API_KEY not set in this shell — fine for CI; only needed for local runs.");
150
+ const { source } = resolveApiKey(provider.def, process.env, provider.baseUrl);
151
+ if (source) ok(`${source} set in current shell.`);
152
+ else if (keyRequired) info(`${keyVars[0]} not set in this shell — fine for CI; only needed for local runs.`);
153
+ else info(`No API key set in this shell — fine if your ${provider.label} endpoint needs none.`);
113
154
  }
114
155
 
115
156
  // Summary