autoglot 0.5.0 → 0.6.1
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 +116 -16
- package/bin/add.mjs +42 -6
- package/bin/catalogs.mjs +207 -0
- package/bin/cli.mjs +4 -0
- package/bin/config.mjs +43 -7
- package/bin/doctor.mjs +53 -9
- package/bin/extract.mjs +5 -1
- package/bin/formats/arb.mjs +176 -0
- package/bin/formats/index.mjs +78 -0
- package/bin/formats/json.mjs +15 -0
- package/bin/formats/properties.mjs +127 -0
- package/bin/formats/shared.mjs +22 -0
- package/bin/formats/yaml.mjs +660 -0
- package/bin/helpers.mjs +17 -9
- package/bin/init.mjs +45 -8
- package/bin/templates/common.mjs +7 -3
- package/bin/translate.mjs +250 -45
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
<a href="#cli-flags">CLI reference</a>
|
|
22
22
|
</p>
|
|
23
23
|
|
|
24
|
-
autoglot translates
|
|
24
|
+
autoglot translates message catalogs (JSON, Flutter ARB, YAML, Java `.properties`; see [File formats](#file-formats)) 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.
|
|
25
25
|
|
|
26
26
|
- **Incremental.** A committed lock file tracks source strings. autoglot translates new, changed, and missing keys and removes orphaned entries.
|
|
27
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.
|
|
28
|
-
- **Reviewable.** The GitHub Action commits
|
|
28
|
+
- **Reviewable.** The GitHub Action commits the translated catalog files and can post token usage and estimated cost on an open PR.
|
|
29
29
|
|
|
30
30
|
## Quickstart
|
|
31
31
|
|
|
@@ -36,8 +36,8 @@ With Node.js 20 or newer, create an empty directory and preview German translati
|
|
|
36
36
|
```bash
|
|
37
37
|
mkdir autoglot-demo
|
|
38
38
|
cd autoglot-demo
|
|
39
|
-
npx --yes autoglot@0.
|
|
40
|
-
npx --yes autoglot@0.
|
|
39
|
+
npx --yes autoglot@0.6.1 init --locales=de
|
|
40
|
+
npx --yes autoglot@0.6.1 --dry-run
|
|
41
41
|
```
|
|
42
42
|
|
|
43
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.
|
|
@@ -50,7 +50,7 @@ npx --yes autoglot@0.5.0 --dry-run
|
|
|
50
50
|
To check whether translations are up to date, run this separately.
|
|
51
51
|
|
|
52
52
|
```bash
|
|
53
|
-
npx --yes autoglot@0.
|
|
53
|
+
npx --yes autoglot@0.6.1 --check
|
|
54
54
|
```
|
|
55
55
|
|
|
56
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.
|
|
@@ -60,7 +60,7 @@ On this fresh catalog, the check prints `Locales needing updates: de` and exits
|
|
|
60
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.
|
|
61
61
|
|
|
62
62
|
```bash
|
|
63
|
-
npx --yes autoglot@0.
|
|
63
|
+
npx --yes autoglot@0.6.1
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
To translate with a different provider, see [Providers](#providers).
|
|
@@ -69,7 +69,7 @@ For a dry run with existing catalogs, see the [basic example](https://github.com
|
|
|
69
69
|
|
|
70
70
|
### Set up an existing app
|
|
71
71
|
|
|
72
|
-
Run `npx autoglot init` in your app directory and choose your target locales. To set them without prompts, use `npx --yes autoglot@0.
|
|
72
|
+
Run `npx autoglot init` in your app directory and choose your target locales. To set them without prompts, use `npx --yes autoglot@0.6.1 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.
|
|
73
73
|
|
|
74
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.
|
|
75
75
|
|
|
@@ -104,7 +104,7 @@ gh secret set ANTHROPIC_API_KEY
|
|
|
104
104
|
npx autoglot # run translation (the default; same as before)
|
|
105
105
|
npx autoglot init # interactive scaffold (above)
|
|
106
106
|
npx autoglot init --install # …and auto-install runtime libs (--pm=pnpm to override)
|
|
107
|
-
npx autoglot add tr ja zh # add new target locales (creates empty
|
|
107
|
+
npx autoglot add tr ja zh # add new target locales (creates empty catalog files)
|
|
108
108
|
npx autoglot doctor # health check the setup
|
|
109
109
|
npx autoglot extract # scan source for hardcoded strings and suggest keys
|
|
110
110
|
npx autoglot extract --write # …and merge them into messages/en.json (existing keys protected)
|
|
@@ -190,7 +190,7 @@ The action detects pull_request events automatically and pushes translations to
|
|
|
190
190
|
| `model` | `claude-haiku-4-5` for Anthropic | Model id. Every other provider needs one, here or in the config. |
|
|
191
191
|
| `base-url` | the provider's endpoint | API base URL. Needed for `openai-compatible`. |
|
|
192
192
|
| `config` | `translate.config.json` | Path to the config file. |
|
|
193
|
-
| `source`, `messages-dir`, `lock-file` | from the config | Path overrides. |
|
|
193
|
+
| `source`, `messages-dir`, `files`, `lock-file` | from the config | Path overrides. `files` is a catalog path pattern with one `[locale]` in the file name and replaces `messages-dir`. |
|
|
194
194
|
| `commit` | `true` | Commit and push translation changes to the branch. |
|
|
195
195
|
| `pr-comment` | `true` | Post the cost summary on the open PR. |
|
|
196
196
|
| `package-version` | bundled CLI | Run a specific npm version of the CLI. |
|
|
@@ -232,7 +232,7 @@ If the selected provider needs a key and none is passed, the run stops with an e
|
|
|
232
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
233
|
| Dependencies | **0** | 30 (CLI) | n/a (SaaS) | several |
|
|
234
234
|
| Multi-provider | **Yes** (Anthropic run live; others simulated-only) | One model, any Vercel AI Gateway provider | n/a | Yes |
|
|
235
|
-
| Formats | JSON | 15+ | 15+ | JSON |
|
|
235
|
+
| Formats | JSON, ARB, YAML, `.properties` | 15+ | 15+ | JSON |
|
|
236
236
|
| Self-hosted | **Yes** | Yes | No | Yes |
|
|
237
237
|
|
|
238
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.
|
|
@@ -324,8 +324,10 @@ See [`examples/providers`](https://github.com/ffcabbar/autoglot/tree/main/exampl
|
|
|
324
324
|
|
|
325
325
|
| Field | Default | What it does |
|
|
326
326
|
|---|---|---|
|
|
327
|
-
| `source` | `messages/en.json` | Path to your source-of-truth locale file. |
|
|
327
|
+
| `source` | `messages/en.json` | Path to your source-of-truth locale file. Its extension picks the [file format](#file-formats). |
|
|
328
328
|
| `messagesDir` | `messages` | Where the other `<locale>.json` files live. |
|
|
329
|
+
| `files` | none | Catalog path pattern with one `[locale]` in the file name, such as `lib/l10n/app_[locale].arb`. Replaces `messagesDir`. See [File formats](#file-formats). |
|
|
330
|
+
| `locales` | none | The exact list of target locales, such as `["de", "fr", "pt-BR"]`. Without it, target files are found by name. See [File names](#file-names). |
|
|
329
331
|
| `lockFile` | `translate.lock` | Where to store md5 fingerprints. Commit it. |
|
|
330
332
|
| `provider` | `anthropic` | Which [provider](#providers) translates. |
|
|
331
333
|
| `model` | `claude-haiku-4-5` | Model id. The default applies to Anthropic only; other providers need one. |
|
|
@@ -340,6 +342,96 @@ See [`examples/providers`](https://github.com/ffcabbar/autoglot/tree/main/exampl
|
|
|
340
342
|
| `namespaceContext` | `{}` | Hint the model about each top-level namespace. Improves quality. |
|
|
341
343
|
| `namespaces` | `{}` | Map namespaces to their target locale lists. Other namespaces go to all target locales. |
|
|
342
344
|
|
|
345
|
+
## File formats
|
|
346
|
+
|
|
347
|
+
The format is chosen from the extension of the source file. Target files use the same extension. A source file with any other extension, or none, is read as JSON, as in earlier versions; a `files` pattern with an unsupported extension is an error.
|
|
348
|
+
|
|
349
|
+
| Format | Extensions | What is translated | What a target file keeps | Limits |
|
|
350
|
+
|---|---|---|---|---|
|
|
351
|
+
| JSON | `.json` | Every value of a nested object | Source key order | Unchanged from earlier versions. |
|
|
352
|
+
| ARB (Flutter) | `.arb` | Every key that does not start with `@` | `@@locale` set to the target's own locale; the target's own other `@@` entries, and its `@key` entries for messages that still exist | Message values must be strings. The source's `@key` entries (descriptions, placeholders) are not copied: Flutter reads them from the template file. A key that is a whole number (`"404"`) is written before the other keys. |
|
|
353
|
+
| YAML (Rails, i18next) | `.yaml`, `.yml` | String values of nested mappings; lists of strings, item by item | Source structure, key order and key spelling; the Rails locale root, rewritten to the target locale; values that are not text | A documented subset, see below. Comments are not copied. |
|
|
354
|
+
| Java properties | `.properties` | Every value | Source key order | Read and written as UTF-8. Comments are not copied. |
|
|
355
|
+
|
|
356
|
+
Not supported: gettext PO, Apple `.strings` / `.stringsdict` / `.xcstrings`, Android XML, XLIFF, Markdown. One directory per locale (`locales/de/common.json`, `values-de/strings.xml`) is not supported yet either: catalogs are one file per locale in one directory.
|
|
357
|
+
|
|
358
|
+
Rules that hold for every format:
|
|
359
|
+
|
|
360
|
+
- `translate.lock` is the same for all of them: one md5 per dotted key. A JSON project's lock file does not change.
|
|
361
|
+
- A source file that cannot be read stops the run before anything is sent or written.
|
|
362
|
+
- A target file that cannot be read is reported with its file and line, left untouched and kept pending. The other locales are still translated, and the run exits with status `1`.
|
|
363
|
+
- Every ARB, YAML and `.properties` file is checked before it is written: it must read back as exactly the translations it was made from, whatever characters a translation contains. JSON files are written as before, without this check.
|
|
364
|
+
- **First run on a project that already has translations.** `translate.lock` is what tells autoglot that a translation is current. Without a lock file, the first run translates every key again and overwrites the translations already in the target files, and it removes keys that only a target has. This is how JSON projects have always behaved. Commit your target files before the first run and review the diff.
|
|
365
|
+
- A key that exists only in a target file is removed on the next write (with one exception for Rails plural forms, below), and comments in target files are not kept.
|
|
366
|
+
- Target files are written with LF line endings. Source files may use LF or CRLF.
|
|
367
|
+
- Files other than JSON must be valid UTF-8.
|
|
368
|
+
|
|
369
|
+
### File names
|
|
370
|
+
|
|
371
|
+
By default a catalog is `<messagesDir>/<locale>` plus the source file's extension, so a Rails project needs no extra setting:
|
|
372
|
+
|
|
373
|
+
```json
|
|
374
|
+
{ "source": "config/locales/en.yml", "messagesDir": "config/locales" }
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
When the file name holds more than the locale, give the pattern in `files` (or `--files=`, or the Action's `files` input) instead of `messagesDir`:
|
|
378
|
+
|
|
379
|
+
```json
|
|
380
|
+
{ "files": "lib/l10n/app_[locale].arb" }
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
```json
|
|
384
|
+
{ "source": "src/main/resources/messages.properties", "files": "src/main/resources/messages_[locale].properties" }
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
- `[locale]` must appear exactly once, in the file name. A pattern with `[locale]` in a directory name is refused.
|
|
388
|
+
- Without `source`, the source file is the pattern with `en` as the locale. Set `source` when it is another file, for example Java's `messages.properties`.
|
|
389
|
+
- `files` together with a `messagesDir` that names another directory, or a `source` with another extension, is an error. autoglot never picks one of two contradicting settings.
|
|
390
|
+
|
|
391
|
+
Which files are targets:
|
|
392
|
+
|
|
393
|
+
- **JSON projects without `files`:** every `*.json` in `messagesDir` except the source, as before.
|
|
394
|
+
- **Every other project** (ARB, YAML, `.properties`, or any project that sets `files`): a file is a target only if the locale part of its name is a known language code, optionally followed by a known script and a known region: `de`, `pt-BR`, `pt_BR`, `zh-Hans`, `zh_Hant_TW`. `models.yml`, `faq.yml`, `app_config.yml`, `devise.en.yml` or `messages_dev.properties` next to your catalogs are not targets and are never written.
|
|
395
|
+
- Some ordinary words are also language codes (`nav`, `bak`, `new`). So a file found by name that already has content and no history in `translate.lock` is a target only if at least half of its own keys are keys of the source catalog (a real translation is a subset of the source, apart from a few stale keys). Every value counts as content, including numbers and flags. Otherwise the file is skipped with a warning and never written or staged; the run lists the skipped files in its summary and still exits with status `0`, `--check` does not count them as pending, and `autoglot doctor` names them. An empty file is always a target.
|
|
396
|
+
- **`"locales"` in the config** replaces all of this with an exact list: `"locales": ["de", "fr", "pt-BR"]`. Only the listed locales are targets, in every format including JSON; a listed locale without a file gets one on the next run; no other file is read or written. Use it to include a file the rules above skip, or to keep autoglot away from everything else in the directory. `--locales=` selects from the list and refuses a locale that is not on it. A list with no target locale in it is an error; the source locale in the list is ignored with a warning.
|
|
397
|
+
- Outside the JSON default layout, `pt-BR`, `pt_BR` and `PT-br` name the same catalog in `--locales`, in `"locales"`, and in `add` and `init`: the file that exists is used, and a new file gets the spelling and letter case of its ecosystem (`add fr-ca` creates `app_fr_CA.arb`). Two files for one locale (`app_pt_BR.arb` and `app_pt-BR.arb`) stop the run until one is removed.
|
|
398
|
+
|
|
399
|
+
`autoglot add <locale>` creates an empty target with the right name and shape (`de: {}` for Rails, `"@@locale": "de"` for ARB). `add` and `init` accept both `pt-BR` and `pt_BR` for these formats and write the spelling each ecosystem uses: `app_pt_BR.arb` and `messages_pt_BR.properties` with an underscore, `pt-BR.yml` with a hyphen. `autoglot doctor` prints the detected format and pattern. `autoglot init` scaffolds starter catalogs for JSON only; for another format, write `translate.config.json` by hand, then run `autoglot add <locale>`. Running `init` on such a project adds the empty targets and a workflow that triggers on your catalog files. `--import-languine` and `autoglot extract --write` work with JSON catalogs only.
|
|
400
|
+
|
|
401
|
+
Runnable examples: [`examples/flutter-arb`](https://github.com/ffcabbar/autoglot/tree/main/examples/flutter-arb) and [`examples/rails-yaml`](https://github.com/ffcabbar/autoglot/tree/main/examples/rails-yaml).
|
|
402
|
+
|
|
403
|
+
### ARB
|
|
404
|
+
|
|
405
|
+
Keys that start with `@` are never sent to the model. A target's `@@` entries always stay; its `@key` entry stays as long as the message `key` exists and is removed together with a message that was deleted from the source. A target gets `@@locale` when the source file or the target already has one. ICU messages are checked by argument: a translation of `{count, plural, one{item} other{{count} items}}` must still contain `count` as a plural and `{count}` as a plain argument. Plural and select branch keywords (`one`, `few`, `=0`, `male`) and the text inside branches are not checked, because languages need different plural categories. Text that is not well-formed ICU falls back to the plain `{name}` check. An apostrophe is read both ways, as text (Flutter's default, so `l'{item}` keeps its placeholder) and as ICU quoting (`use-escaping: true`); a translation passes if either reading has the source's arguments.
|
|
406
|
+
|
|
407
|
+
### YAML
|
|
408
|
+
|
|
409
|
+
autoglot reads YAML with its own parser for a strict subset, and stops with the file, line and construct for anything outside it.
|
|
410
|
+
|
|
411
|
+
- Supported: one document (optionally opened with `---`); nested block mappings; plain, single-quoted and double-quoted keys and values, on one line or folded over several, with all double-quote escapes; literal `|` and folded `>` block scalars with `+` / `-` chomping and an indentation digit; lists of scalars written as `- item` lines or as a one-line `[a, b]`; comments; empty values; `{}` and `[]`.
|
|
412
|
+
- Refused: anchors `&`, aliases `*`, tags `!`, merge keys `<<`, complex keys `?`, flow mappings `{a: b}`, lists that contain mappings or lists, `[ ]` lists over several lines, more than one document, `%` directives, tabs used for indentation, duplicate keys, and a few things that YAML readers disagree about (a block scalar on the last line of a file that has no final line break; a raw U+2028, U+2029 or U+0085 character, which Ruby reads as a line break).
|
|
413
|
+
- A list is translated item by item. The items of `day_names` are the lock keys `day_names.0`, `day_names.1`, and so on. This differs from JSON catalogs, where an array is one value with one hash.
|
|
414
|
+
- Values that are not text are never sent and never retyped: numbers and anything shaped like one, `true` / `false`, `null` / `~` / an empty value, dates, and Ruby symbols (a plain value that starts with a colon, like `:year`). A target keeps its own such value if it has one and otherwise gets the source's, character for character.
|
|
415
|
+
- A plain `yes`, `no`, `on`, `off`, `y` or `n` is a boolean for YAML 1.1 readers such as Ruby and a string for YAML 1.2 readers. autoglot refuses it and asks you to quote it.
|
|
416
|
+
- Rails locale root: when the only top-level key of a file is its own locale (`en:` in `en.yml`), the messages are what is under it and each target is written under its own locale (`de:`). The root is not part of the lock keys. A target that is rooted differently from the source is refused instead of being rewritten.
|
|
417
|
+
- Rails plural forms: under a mapping whose source keys are all plural categories (`zero`, `one`, `two`, `few`, `many`, `other`), plural categories that only the target has are kept, after the source's keys. A Russian file keeps the `few` and `many` a translator added. autoglot does not create missing categories: it translates the keys the source has (`one`, `other`), and the extra forms a language needs must be added by hand. Kept forms are also not refreshed: when the source's plural text changes, `one` and `other` are translated again and `few` and `many` stay as they were until someone updates them.
|
|
418
|
+
- A value with an ICU plural or select (`{n, plural, one {file} other {files}}`) is checked by its arguments, as in ARB, so the words in its branches are free.
|
|
419
|
+
- Placeholders are compared as written: `%{name}`, a bare `{name}` and `%<name>d` are different things, and `%<name>d` must keep its conversion letter. Their order, and the width or precision of `%<name>d`, are free. `printf`-style `%s` and `%d` are not checked.
|
|
420
|
+
- Typing that only Ruby's YAML reader applies is not modelled: a mixed-case `tRue`, or a multi-line unquoted value in which one line is exactly `yes`, is text to autoglot.
|
|
421
|
+
- Unicode spaces (a no-break space, an ideographic space) are content, never trimmed. In targets they are written as escapes inside double quotes (`"Prix\_:"`) so they stay visible.
|
|
422
|
+
- Writing: keys are copied exactly as the source spells them. A translated string is written plain only when that is safe for both YAML 1.1 and YAML 1.2 readers; otherwise it is double-quoted with escapes. Block scalars in the source become double-quoted strings in targets.
|
|
423
|
+
|
|
424
|
+
### Java properties
|
|
425
|
+
|
|
426
|
+
Files are read the way `java.util.Properties` reads them: `key=value`, `key:value` and `key value`; `#` and `!` comments; a trailing backslash continuing a line; the escapes `\t`, `\n`, `\r`, `\f`, `\uXXXX` and a backslash before any other character. A key that appears twice keeps its last value. A malformed `\uXXXX` is an error.
|
|
427
|
+
|
|
428
|
+
- Keys are flat. `checkout.title` is one key, dots included, and that is its key in `translate.lock`.
|
|
429
|
+
- Encoding: files are read and written as UTF-8, and text outside ASCII is written as it is. If the source file itself uses `\uXXXX` escapes and contains no character outside ASCII, targets use `\uXXXX` too. Invisible characters (no-break spaces, zero-width characters, the byte order mark) are always written as `\uXXXX`. A file in ISO-8859-1 is refused; convert it to UTF-8 first.
|
|
430
|
+
- A value with an ICU plural or select is checked by its arguments, as in ARB, so the words in its branches are free.
|
|
431
|
+
- Placeholders: numbered arguments (`{0}`, `{1,number}`) and named ones (`{name}`) must appear in the translation with the same format type (`number`, `date`, `choice`); their order and the format style are free. `printf`-style `%s` is not checked, and neither is `MessageFormat` quoting such as `'{0}'`.
|
|
432
|
+
- `MessageFormat` rules such as doubling an apostrophe in a message with arguments are not checked. The model is told to follow the source's convention.
|
|
433
|
+
- The parser follows the `java.util.Properties` specification and was compared with two JavaScript parsers; it has not been run against a Java runtime.
|
|
434
|
+
|
|
343
435
|
## CLI flags
|
|
344
436
|
|
|
345
437
|
```
|
|
@@ -355,6 +447,8 @@ See [`examples/providers`](https://github.com/ffcabbar/autoglot/tree/main/exampl
|
|
|
355
447
|
--allow-insecure-http Allow sending an API key over plain http to another machine.
|
|
356
448
|
--source=<path> Override config.source.
|
|
357
449
|
--messages-dir=<path> Override config.messagesDir.
|
|
450
|
+
--files=<pattern> Catalog path pattern with one [locale] in the file name, e.g.
|
|
451
|
+
lib/l10n/app_[locale].arb. Replaces --messages-dir.
|
|
358
452
|
--lock-file=<path> Override config.lockFile.
|
|
359
453
|
--config=<path> Custom config file path.
|
|
360
454
|
--import-languine[=path] Seed the lock file from languine.lock.
|
|
@@ -404,6 +498,8 @@ npx autoglot --dry-run
|
|
|
404
498
|
|
|
405
499
|
`languine.lock` sits next to `languine.json`. The importer reads the entry for your source JSON catalog and ignores entries for other files.
|
|
406
500
|
|
|
501
|
+
To preview the import first, add `--dry-run`: `npx autoglot --import-languine=languine.lock --dry-run` prints the same report (how many hashes it would import, what it would leave out and the lock file it would write) and writes nothing. The import only creates a lock file. If `translate.lock` already exists and is not empty, the import and its preview stop with an error and leave it untouched, because replacing it would drop the history it records and the next run would translate those keys again. Move or delete it, then run the import again. `--import-languine` cannot be combined with `--check` or `--locales`.
|
|
502
|
+
|
|
407
503
|
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.
|
|
408
504
|
|
|
409
505
|
## How it works
|
|
@@ -433,14 +529,14 @@ Yes. `npx autoglot init` has explicit support for **Next.js (App Router & Pages
|
|
|
433
529
|
<details>
|
|
434
530
|
<summary><strong>What about ICU plurals, dates, gender?</strong></summary>
|
|
435
531
|
|
|
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.
|
|
532
|
+
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. For ARB files the validator also checks ICU arguments by name and kind (see [ARB](#arb)), and YAML and `.properties` values that hold an ICU plural or select are read the same way. JSON catalogs keep the plain check, which has a known limit: a plural or select branch that is a single word in braces, as in `one {file} other {files}`, is taken for a placeholder, so its translation is rejected. Write such branches with more than one word (`one {# file}`), or keep them out of JSON catalogs for now.
|
|
437
533
|
|
|
438
534
|
</details>
|
|
439
535
|
|
|
440
536
|
<details>
|
|
441
|
-
<summary><strong>
|
|
537
|
+
<summary><strong>Which file formats are supported?</strong></summary>
|
|
442
538
|
|
|
443
|
-
JSON
|
|
539
|
+
JSON, Flutter ARB, YAML (Rails and i18next style) and Java `.properties`, one file per locale. See [File formats](#file-formats) for what each one translates and keeps, and for the YAML subset. PO, Apple `.strings` / `.xcstrings`, Android XML and one-directory-per-locale layouts are not supported yet.
|
|
444
540
|
|
|
445
541
|
</details>
|
|
446
542
|
|
|
@@ -476,8 +572,11 @@ Add them to `glossary` in `translate.config.json`. They'll be passed to the mode
|
|
|
476
572
|
|
|
477
573
|
- [x] Anthropic, JSON catalogs, GitHub Action, Languine importer, parallel locales, lock file
|
|
478
574
|
- [x] Multi-provider — OpenAI, Gemini, xAI, DeepSeek, and OpenAI-compatible endpoints (simulated responses only so far)
|
|
575
|
+
- [x] File formats — ARB, YAML and Java `.properties` next to JSON, with a `[locale]` file name pattern
|
|
479
576
|
- [ ] Run each non-Anthropic provider against its live API
|
|
480
|
-
- [ ]
|
|
577
|
+
- [ ] Adopt existing translations into the lock without translating them again (in development)
|
|
578
|
+
- [ ] One directory per locale
|
|
579
|
+
- [ ] More formats — PO, `.strings` / `.xcstrings`, Android XML
|
|
481
580
|
- [ ] Provider-fallback chain
|
|
482
581
|
|
|
483
582
|
See the [roadmap](ROADMAP.md) for upcoming work and the [open issues](https://github.com/ffcabbar/autoglot/issues) for current maintenance tasks.
|
|
@@ -486,7 +585,8 @@ See the [roadmap](ROADMAP.md) for upcoming work and the [open issues](https://gi
|
|
|
486
585
|
|
|
487
586
|
Issues, PRs, and bug reports welcome. The codebase is intentionally tiny:
|
|
488
587
|
|
|
489
|
-
- `bin/translate.mjs` (≈
|
|
588
|
+
- `bin/translate.mjs` (≈ 960 lines) — the translation engine
|
|
589
|
+
- `bin/formats/` — one module per catalog format (JSON, ARB, YAML, `.properties`)
|
|
490
590
|
- `bin/providers/` — one small module per wire format (Anthropic, OpenAI Responses, OpenAI-compatible Chat Completions, Gemini) plus the preset list
|
|
491
591
|
- `bin/helpers.mjs` — pure helpers
|
|
492
592
|
- `tests/helpers.test.mjs` — `node:test` suite, runs offline
|
package/bin/add.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
// `autoglot add <locale> [<locale>...]` — add new target locales.
|
|
2
2
|
//
|
|
3
|
-
// Creates an empty
|
|
4
|
-
//
|
|
3
|
+
// Creates an empty target catalog in the project's format and naming
|
|
4
|
+
// (messages/<locale>.json by default). The next run populates it.
|
|
5
|
+
// Idempotent: if the file already exists, we leave it alone.
|
|
5
6
|
|
|
6
7
|
import { writeFileSync, existsSync } from "node:fs";
|
|
7
8
|
import { join, relative, basename } from "node:path";
|
|
8
9
|
import { info, ok, warn, err, step } from "./prompts.mjs";
|
|
9
10
|
import { resolvePaths, parseSharedFlags } from "./config.mjs";
|
|
11
|
+
import { catalogLayout, isLocaleName } from "./catalogs.mjs";
|
|
12
|
+
import { readCatalog } from "./formats/index.mjs";
|
|
10
13
|
|
|
11
14
|
export async function run(argv = []) {
|
|
12
15
|
const { args, positional } = parseSharedFlags(argv);
|
|
@@ -20,8 +23,10 @@ export async function run(argv = []) {
|
|
|
20
23
|
step("autoglot add");
|
|
21
24
|
|
|
22
25
|
let paths;
|
|
26
|
+
let layout;
|
|
23
27
|
try {
|
|
24
28
|
paths = resolvePaths(args, cwd);
|
|
29
|
+
layout = catalogLayout(paths);
|
|
25
30
|
} catch (e) {
|
|
26
31
|
err(e.message);
|
|
27
32
|
process.exit(1);
|
|
@@ -35,22 +40,53 @@ export async function run(argv = []) {
|
|
|
35
40
|
process.exit(1);
|
|
36
41
|
}
|
|
37
42
|
|
|
43
|
+
// An empty target mirrors the source where the format needs it: the locale
|
|
44
|
+
// root of a Rails YAML file, "@@locale" in ARB. JSON starts as "{}".
|
|
45
|
+
let sourceMeta = null;
|
|
46
|
+
if (!layout.legacyJson) {
|
|
47
|
+
try {
|
|
48
|
+
sourceMeta = readCatalog(layout.format, paths.source, {
|
|
49
|
+
file: relative(cwd, paths.source) || paths.source, locale: layout.sourceLocale,
|
|
50
|
+
}).meta;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
err(e.message);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
38
57
|
let added = 0;
|
|
39
58
|
let already = 0;
|
|
40
|
-
for (const
|
|
41
|
-
|
|
59
|
+
for (const given of positional) {
|
|
60
|
+
// Other formats also take pt_BR, pt-BR and zh-Hans, and the file gets the
|
|
61
|
+
// spelling the format's tools expect (app_pt_BR.arb, pt-BR.yml).
|
|
62
|
+
let code = given;
|
|
63
|
+
try {
|
|
64
|
+
// An existing app_pt_BR.arb is the catalog for both pt-BR and pt_BR.
|
|
65
|
+
if (/^[^\\/]+$/.test(given)) code = layout.resolveName(given);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
err(e.message);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
if (!(layout.legacyJson ? /^[a-z]{2,3}(-[A-Z]{2})?$/.test(code) : isLocaleName(code) || layout.allowlist?.(code))) {
|
|
42
71
|
warn(`"${code}" doesn't look like an ISO locale code. Skipping.`);
|
|
43
72
|
continue;
|
|
44
73
|
}
|
|
45
|
-
const localePath =
|
|
74
|
+
const localePath = layout.pathFor(code);
|
|
75
|
+
if (localePath.toLowerCase() === paths.source.toLowerCase()) {
|
|
76
|
+
warn(`"${code}" is the source locale. Skipping.`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
46
79
|
const displayPath = relative(cwd, localePath) || localePath;
|
|
47
80
|
if (existsSync(localePath)) {
|
|
48
81
|
info(`${displayPath} already exists — leaving it alone.`);
|
|
49
82
|
already++;
|
|
50
83
|
continue;
|
|
51
84
|
}
|
|
52
|
-
writeFileSync(localePath,
|
|
85
|
+
writeFileSync(localePath, layout.format.serialize({}, { meta: null, sourceMeta, locale: code }));
|
|
53
86
|
ok(displayPath);
|
|
87
|
+
if (layout.allowlist && !layout.allowlist(code)) {
|
|
88
|
+
warn(`"${code}" is not in "locales" in translate.config.json. Add it there, or autoglot will not translate this file.`);
|
|
89
|
+
}
|
|
54
90
|
added++;
|
|
55
91
|
}
|
|
56
92
|
|
package/bin/catalogs.mjs
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// Where a project's catalog files are and what they are called. Everything
|
|
2
|
+
// that lists catalogs (translate, --check, --dry-run, --locales, add, doctor,
|
|
3
|
+
// init and the Action's staging step) goes through catalogLayout().
|
|
4
|
+
//
|
|
5
|
+
// One file per locale, all in one directory:
|
|
6
|
+
// default <messagesDir>/<locale><extension of the source file>
|
|
7
|
+
// with "files" the pattern's directory, with [locale] in the file name,
|
|
8
|
+
// for example lib/l10n/app_[locale].arb
|
|
9
|
+
// The format comes from the extension (see ./formats/index.mjs).
|
|
10
|
+
|
|
11
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
12
|
+
import { basename, dirname, extname, join } from "node:path";
|
|
13
|
+
import { flatten } from "./helpers.mjs";
|
|
14
|
+
import { FORMATS, formatForFile } from "./formats/index.mjs";
|
|
15
|
+
import { sameLocale } from "./formats/shared.mjs";
|
|
16
|
+
|
|
17
|
+
export const LOCALE_PLACEHOLDER = "[locale]";
|
|
18
|
+
// What a file name must hold where the locale goes, for a file to be found as
|
|
19
|
+
// a catalog: a known language, optionally a known script and a known region,
|
|
20
|
+
// joined by "-" or "_" (`de`, `pt-BR`, `pt_BR`, `zh-Hans`, `zh_Hant_TW`).
|
|
21
|
+
// Stricter than "any BCP 47 tag" on purpose: every file found this way gets
|
|
22
|
+
// rewritten, so models.yml, faq.yml, app_config.yml or devise.en.yml next to
|
|
23
|
+
// en.yml must never be taken for a locale. Anything else can be named in
|
|
24
|
+
// "locales" in the config.
|
|
25
|
+
const KNOWN = Object.fromEntries(["language", "script", "region"].map((type) => [type, new Intl.DisplayNames(["en"], { type, fallback: "none" })]));
|
|
26
|
+
|
|
27
|
+
export function isLocaleName(name) {
|
|
28
|
+
const [language, ...rest] = String(name).split(/[-_]/);
|
|
29
|
+
if (!/^[A-Za-z]{2,3}$/.test(language)) return false;
|
|
30
|
+
const script = /^[A-Za-z]{4}$/.test(rest[0] ?? "") ? rest.shift() : undefined;
|
|
31
|
+
const region = /^(?:[A-Za-z]{2}|[0-9]{3})$/.test(rest[0] ?? "") ? rest.shift() : undefined;
|
|
32
|
+
if (rest.length) return false;
|
|
33
|
+
try {
|
|
34
|
+
return KNOWN.language.of(language) !== undefined &&
|
|
35
|
+
(script === undefined || KNOWN.script.of(script) !== undefined) &&
|
|
36
|
+
(region === undefined || KNOWN.region.of(region.toUpperCase()) !== undefined);
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Checks the optional "locales" list of the config. Returns it or null.
|
|
43
|
+
export function parseLocaleList(locales) {
|
|
44
|
+
if (locales === undefined || locales === null) return null;
|
|
45
|
+
const valid = Array.isArray(locales) && locales.every((locale) => typeof locale === "string" && /^[^\\/\s]+$/.test(locale) && !locale.startsWith("."));
|
|
46
|
+
if (!valid) throw new Error('"locales" must be a list of target locale codes, for example ["de", "fr", "pt-BR"].');
|
|
47
|
+
return [...new Set(locales)];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// What the run and doctor say about a "locales" list with no target in it.
|
|
51
|
+
export function noTargetsMessage(configPath) {
|
|
52
|
+
return `"locales" in ${configPath} lists no target locale. List the locales to translate into, for example ["de", "fr"], or remove "locales" to find target files by name.`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// A file that looks like a catalog by name but is something else. A real
|
|
56
|
+
// translation is a subset of the source: its keys are source keys, apart from
|
|
57
|
+
// a few stale ones. So a file with messages, with no history in the lock, is
|
|
58
|
+
// a catalog only if at least half of its own keys are keys of the source (or
|
|
59
|
+
// keys the lock file knows from an earlier source). Anything else would have
|
|
60
|
+
// its content replaced by translations of the source, and is skipped.
|
|
61
|
+
//
|
|
62
|
+
// `target` and `source` are what readCatalog returns. Every value counts, not
|
|
63
|
+
// only text: a file of numbers and flags has content too.
|
|
64
|
+
export function isForeignTarget({ format, locale, target, source, lock }) {
|
|
65
|
+
const every = ({ messages, meta }) => format.allKeys?.(meta) ?? Object.keys(flatten(messages));
|
|
66
|
+
const keys = every(target);
|
|
67
|
+
if (!keys.length || Object.hasOwn(lock.localeHashes ?? {}, locale)) return false;
|
|
68
|
+
// Under a rooted source (Rails, `en:` at the top), one top-level key that
|
|
69
|
+
// is this file's locale or the source's locale root (`de: 3`, `de: ""`, a
|
|
70
|
+
// bare `en:` inside de.yml) is a catalog gone wrong, not a neighbour: the
|
|
71
|
+
// format reports it. Under a flat source the format has nothing to report,
|
|
72
|
+
// so `nav: /navigation` in nav.yml is judged by its keys like any file.
|
|
73
|
+
if (format.checkTarget && source.meta?.root != null && keys.length === 1 && [locale, source.meta?.root].some((name) => name && sameLocale(keys[0], name))) return false;
|
|
74
|
+
const sourceKeys = new Set(every(source));
|
|
75
|
+
// A section the target has left empty (`home:` with nothing under it) is
|
|
76
|
+
// one value in the target and a group of keys in the source. Only an empty
|
|
77
|
+
// value counts: `home: /` in nav.yml is a value of its own, not a section.
|
|
78
|
+
const sections = new Set();
|
|
79
|
+
for (const key of sourceKeys) {
|
|
80
|
+
for (let dot = key.indexOf("."); dot !== -1; dot = key.indexOf(".", dot + 1)) sections.add(key.slice(0, dot));
|
|
81
|
+
}
|
|
82
|
+
const empty = new Set(format.emptyKeys?.(target.meta) ?? []);
|
|
83
|
+
const known = (key) => sourceKeys.has(key) || (sections.has(key) && empty.has(key)) || Object.hasOwn(lock.hashes, key);
|
|
84
|
+
// A copy of a rooted source file ("en:" inside es.yml) is a catalog with the
|
|
85
|
+
// wrong root, which the format reports on its own.
|
|
86
|
+
const unrooted = (key) => (format.checkTarget && key.includes(".") ? key.slice(key.indexOf(".") + 1) : key);
|
|
87
|
+
const shared = Math.max(keys.filter(known).length, keys.filter((key) => known(unrooted(key))).length);
|
|
88
|
+
return shared * 2 < keys.length;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Validates a "files" pattern and returns its parts. Throws a one-line error.
|
|
92
|
+
export function parsePattern(pattern) {
|
|
93
|
+
if (typeof pattern !== "string" || !pattern) throw new Error('"files" must be a path with one [locale] placeholder, for example "lib/l10n/app_[locale].arb".');
|
|
94
|
+
const name = basename(pattern);
|
|
95
|
+
const count = pattern.split(LOCALE_PLACEHOLDER).length - 1;
|
|
96
|
+
if (count === 0) throw new Error(`"files" (${pattern}) needs a ${LOCALE_PLACEHOLDER} placeholder in the file name, for example "lib/l10n/app_[locale].arb".`);
|
|
97
|
+
if (!name.includes(LOCALE_PLACEHOLDER)) {
|
|
98
|
+
throw new Error(`"files" (${pattern}) has ${LOCALE_PLACEHOLDER} in a directory name. One directory per locale is not supported yet: ${LOCALE_PLACEHOLDER} must be in the file name.`);
|
|
99
|
+
}
|
|
100
|
+
if (count > 1) throw new Error(`"files" (${pattern}) must contain ${LOCALE_PLACEHOLDER} exactly once, in the file name.`);
|
|
101
|
+
const at = name.indexOf(LOCALE_PLACEHOLDER);
|
|
102
|
+
const suffix = name.slice(at + LOCALE_PLACEHOLDER.length);
|
|
103
|
+
if (!suffix.startsWith(".") && !extname(suffix)) {
|
|
104
|
+
throw new Error(`"files" (${pattern}) must end with a file extension after ${LOCALE_PLACEHOLDER}.`);
|
|
105
|
+
}
|
|
106
|
+
formatForFile(pattern);
|
|
107
|
+
return { dir: dirname(pattern), prefix: name.slice(0, at), suffix };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {{ source: string, messagesDir: string, files?: string|null, locales?: string[]|null }} paths from resolvePaths()
|
|
112
|
+
*/
|
|
113
|
+
export function catalogLayout({ source, messagesDir, files = null, locales = null }) {
|
|
114
|
+
// Without a pattern, a source file with any other name is JSON, as it
|
|
115
|
+
// always was: locales/en, en.json5, messages.en.
|
|
116
|
+
let format = FORMATS[0];
|
|
117
|
+
let unknownExtension = false;
|
|
118
|
+
try {
|
|
119
|
+
format = formatForFile(files ?? source);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (files) throw error;
|
|
122
|
+
unknownExtension = true;
|
|
123
|
+
}
|
|
124
|
+
// The layout autoglot has always had. Nothing about it may change.
|
|
125
|
+
const legacyJson = !files && format.name === "json";
|
|
126
|
+
// pt-BR and pt_BR (and PT-br) name the same catalog everywhere except in
|
|
127
|
+
// the legacy JSON layout, where names are compared as they always were.
|
|
128
|
+
const same = (a, b) => (legacyJson ? a === b : sameLocale(a, b));
|
|
129
|
+
const listed = locales ? (locale) => locales.some((entry) => same(entry, locale)) : null;
|
|
130
|
+
// A new file also gets the usual letter case: fr-ca becomes fr_CA or fr-CA,
|
|
131
|
+
// zh-hans-cn becomes zh_Hans_CN. Existing files keep their own spelling.
|
|
132
|
+
const cased = (locale) => locale.split(/([-_])/).map((part, index) => (index === 0 ? part.toLowerCase()
|
|
133
|
+
: /^[A-Za-z]{4}$/.test(part) ? part[0].toUpperCase() + part.slice(1).toLowerCase()
|
|
134
|
+
: /^[A-Za-z]{2}$/.test(part) ? part.toUpperCase() : part)).join("");
|
|
135
|
+
const spell = (locale) => (legacyJson ? locale
|
|
136
|
+
: format.name === "arb" || format.name === "properties" ? cased(locale).replaceAll("-", "_")
|
|
137
|
+
: format.name === "yaml" ? cased(locale).replaceAll("_", "-") : cased(locale));
|
|
138
|
+
const { dir, prefix, suffix } = files
|
|
139
|
+
? parsePattern(files)
|
|
140
|
+
: { dir: messagesDir, prefix: "", suffix: legacyJson ? ".json" : extname(source) };
|
|
141
|
+
const localeOf = (name) => {
|
|
142
|
+
if (name.length < prefix.length + suffix.length || !name.startsWith(prefix) || !name.endsWith(suffix)) return null;
|
|
143
|
+
const locale = name.slice(prefix.length, name.length - suffix.length);
|
|
144
|
+
if (listed) return listed(locale) ? locale : null;
|
|
145
|
+
return legacyJson || isLocaleName(locale) ? locale : null;
|
|
146
|
+
};
|
|
147
|
+
const sourceLocaleOf = (name) => {
|
|
148
|
+
if (name.length <= prefix.length + suffix.length || !name.startsWith(prefix) || !name.endsWith(suffix)) return null;
|
|
149
|
+
const locale = name.slice(prefix.length, name.length - suffix.length);
|
|
150
|
+
return isLocaleName(locale) ? locale : null;
|
|
151
|
+
};
|
|
152
|
+
// Two files for one locale (app_pt_BR.arb and app_pt-BR.arb) cannot both
|
|
153
|
+
// be the catalog. Refuse to pick.
|
|
154
|
+
const unique = (found) => {
|
|
155
|
+
if (legacyJson) return found;
|
|
156
|
+
for (const [index, locale] of found.entries()) {
|
|
157
|
+
const twin = found.slice(index + 1).find((other) => sameLocale(other, locale));
|
|
158
|
+
if (twin) throw new Error(`${join(dir, `${prefix}${locale}${suffix}`)} and ${join(dir, `${prefix}${twin}${suffix}`)} are two files for the same locale. Keep one of them.`);
|
|
159
|
+
}
|
|
160
|
+
return found;
|
|
161
|
+
};
|
|
162
|
+
const onDisk = () => unique(existsSync(dir) ? readdirSync(dir).map(localeOf).filter((locale) => locale !== null) : []);
|
|
163
|
+
// In directory order, as the file system returns them. With a "locales"
|
|
164
|
+
// list, exactly the listed locales, whether their files exist yet or not.
|
|
165
|
+
const names = () => {
|
|
166
|
+
const found = onDisk();
|
|
167
|
+
if (!listed) return found;
|
|
168
|
+
// ["de", "DE"] or ["pt-BR", "pt_BR"] is one locale, not two.
|
|
169
|
+
const missing = locales.filter((entry, index) => !found.some((locale) => same(locale, entry)) &&
|
|
170
|
+
!locales.slice(0, index).some((earlier) => same(earlier, entry))).map((entry) => (legacyJson ? entry : spell(entry)));
|
|
171
|
+
return [...new Set([...found, ...missing])];
|
|
172
|
+
};
|
|
173
|
+
// The catalog name a locale given by a person stands for: the spelling of
|
|
174
|
+
// its existing file, or for a new file the spelling the format's tools use.
|
|
175
|
+
const resolveName = (locale) => {
|
|
176
|
+
if (legacyJson) return locale;
|
|
177
|
+
if (!existsSync(dir)) return spell(locale);
|
|
178
|
+
const candidates = unique(readdirSync(dir).map((name) => {
|
|
179
|
+
if (name.length <= prefix.length + suffix.length || !name.startsWith(prefix) || !name.endsWith(suffix)) return null;
|
|
180
|
+
return name.slice(prefix.length, name.length - suffix.length);
|
|
181
|
+
}).filter((name) => name !== null && sameLocale(name, locale)));
|
|
182
|
+
return candidates[0] ?? spell(locale);
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
format,
|
|
186
|
+
legacyJson,
|
|
187
|
+
// True when the source file's extension names no format and JSON is assumed.
|
|
188
|
+
unknownExtension,
|
|
189
|
+
// The "locales" list of the config, or null when catalogs are discovered.
|
|
190
|
+
allowlist: listed,
|
|
191
|
+
// The spelling this format's tools expect in a file name: Flutter and
|
|
192
|
+
// Java write pt_BR, Rails writes pt-BR. JSON names are left as given.
|
|
193
|
+
spell,
|
|
194
|
+
resolveName,
|
|
195
|
+
dir,
|
|
196
|
+
prefix,
|
|
197
|
+
suffix,
|
|
198
|
+
// For messages: "app_[locale].arb".
|
|
199
|
+
pattern: `${prefix}${LOCALE_PLACEHOLDER}${suffix}`,
|
|
200
|
+
// The source's own locale never depends on the "locales" list of targets.
|
|
201
|
+
sourceLocale: legacyJson ? basename(source, ".json") : sourceLocaleOf(basename(source)),
|
|
202
|
+
pathFor: (locale) => join(dir, `${prefix}${locale}${suffix}`),
|
|
203
|
+
localeOf,
|
|
204
|
+
names,
|
|
205
|
+
list: () => names().sort(),
|
|
206
|
+
};
|
|
207
|
+
}
|
package/bin/cli.mjs
CHANGED
|
@@ -64,6 +64,10 @@ Translation flags (when no subcommand given)
|
|
|
64
64
|
host other than this machine.
|
|
65
65
|
--source=<path> Override config.source (default: messages/en.json).
|
|
66
66
|
--messages-dir=<path> Override config.messagesDir (default: messages).
|
|
67
|
+
--files=<pattern> Catalog path pattern with one [locale] in the file
|
|
68
|
+
name, e.g. lib/l10n/app_[locale].arb. Replaces
|
|
69
|
+
--messages-dir. Formats: .json .arb .yaml .yml
|
|
70
|
+
.properties (chosen from the source file).
|
|
67
71
|
--lock-file=<path> Override config.lockFile (default: translate.lock).
|
|
68
72
|
--config=<path> Custom config file path (default: translate.config.json).
|
|
69
73
|
--import-languine[=<path>] Seed our lock file from a languine.lock and exit.
|