@verbaly/compiler 0.29.0 → 0.31.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
@@ -11,7 +11,9 @@
11
11
 
12
12
  ---
13
13
 
14
- The compiler behind [Verbaly](https://github.com/AronSoto/verbaly): AST extraction of `t\`...\``**and JSX`<Trans>` children** into stable hashed keys (or **readable keys** via `` t.id('inbox.title')`…` `` and `<Trans id="inbox.title">…</Trans>`), flat JSON catalog sync, and typed codegen. It also ships the **`verbaly`CLI**. Extraction covers`.js/.ts/.jsx/.tsx`**and`.svelte`/`.vue`single-file components** (script blocks and markup, including Svelte's`$t` store form).
14
+ The compiler behind [Verbaly](https://github.com/AronSoto/verbaly): AST extraction of `` t`…` `` **and JSX `<Trans>` children** into stable hashed keys (or **readable keys** via `` t.id('inbox.title')`…` `` and `<Trans id="inbox.title">…</Trans>`), flat JSON catalog sync, and typed codegen. It also ships the **`verbaly` CLI**.
15
+
16
+ Extraction covers `.js`/`.ts`/`.jsx`/`.tsx` **and `.svelte`, `.vue` and `.astro` single-file components**: script blocks and frontmatter, plus markup expressions (Svelte's `$t` store form included). Text that only sits on screen is never extracted, so a documented snippet cannot become a real key.
15
17
 
16
18
  > Most projects don't install this directly: [`@verbaly/vite`](https://www.npmjs.com/package/@verbaly/vite) wraps it with zero config. Reach for it when scripting extraction/checks yourself.
17
19
 
@@ -19,13 +21,15 @@ The compiler behind [Verbaly](https://github.com/AronSoto/verbaly): AST extracti
19
21
 
20
22
  ```bash
21
23
  npx verbaly init # scaffold config + locale catalogs (detects your bundler)
22
- npx verbaly doctor # diagnose the setup (config, catalogs, plugin, types, keys)
24
+ npx verbaly doctor # diagnose the setup (config, catalogs, wiring, types, translations)
25
+ npx verbaly wrap # onboarding codemod: report plain JSX text, --write wraps it in t``
23
26
  npx verbaly extract # sync catalogs + types
24
27
  npx verbaly extract --watch # keep extracting as you code (dev loop)
25
28
  npx verbaly extract --prune # drop orphaned keys
26
- npx verbaly status # translation coverage per locale, at a glance
27
- npx verbaly check # exit 1 if anything is missing (CI)
28
- npx verbaly translate # fill missing translations via Claude (or your provider)
29
+ npx verbaly status # coverage per locale, plus unreviewed and broken counts
30
+ npx verbaly check # exit 1 if anything is missing or broken (CI)
31
+ npx verbaly translate # fill missing translations via Claude (or your provider), as drafts
32
+ npx verbaly review # list machine drafts, --approve accepts them
29
33
  npx verbaly export # translator files (XLIFF 2.0, CSV, gettext PO) or mobile resources (Android, iOS)
30
34
  npx verbaly import <files> # fill catalogs back from translated XLIFF/CSV/PO files
31
35
  npx verbaly pseudo # generate a pseudo-locale catalog for i18n QA (en-XA)
@@ -34,9 +38,38 @@ npx verbaly render # pre-fill data-verbaly HTML per locale (SSG, kills t
34
38
 
35
39
  Reads `verbaly.config.{js,mjs,ts,mts,json}` (TS configs need `esbuild` installed). Generates `locales/<locale>.json` (flat, portable, no proprietary format) and `verbaly.d.ts` with params typed per key.
36
40
 
41
+ ## 🚦 The build gate
42
+
43
+ `verbaly check` is the only command that exits 1, and it asks two questions, not one.
44
+
45
+ **Is every message translated?** A missing key or an empty value fails the build, so raw keys never reach production.
46
+
47
+ **Can the translation render what the source renders?** Presence is not correctness. These fail too, each with the reason in plain words:
48
+
49
+ | The translation… | Why it fails |
50
+ | --------------------------------------- | ---------------------------------------------- |
51
+ | lost a `{param}`, or renamed it | the value never reaches the text |
52
+ | lost an `<em>` (or gained one) | the emphasis, code or link marker is gone |
53
+ | turned a plural block into plain text | one form for every count |
54
+ | has a plural block with no `other` case | every count it does not list renders **empty** |
55
+
56
+ Two more are reported as **warnings** and keep the exit code at 0, because the text still renders: a plural set missing forms the target language needs (Polish or Arabic want more than English), and a dropped `=0` style case that now falls back to `other`.
57
+
58
+ ```bash
59
+ npx verbaly check # text report
60
+ npx verbaly check --reporter github # ::error and ::warning annotations on the PR, at the source line
61
+ npx verbaly check --drafts # also fail while machine translations await review
62
+ ```
63
+
64
+ Hand-edited catalogs get the same treatment as imported files: the gate does not care where a translation came from.
65
+
37
66
  ## 🤖 Machine translation
38
67
 
39
- `verbaly translate` fills the `""` holes `check` reports. The default provider uses Claude via the official SDK; install it as a dev dependency (translation is a build-time step, not an app runtime dependency): `pnpm add -D @anthropic-ai/sdk` (or `npm i -D`), plus `ANTHROPIC_API_KEY`. Default model is `claude-sonnet-5` (balanced quality/cost); override with `translate.model` in config or `--model <id>`. Placeholders, variants and tags are validated after translation: anything not preserved verbatim stays `""` so `check` keeps failing. Plug your own provider in `verbaly.config.ts`:
68
+ `verbaly translate` fills the `""` holes `check` reports. The default provider uses Claude via the official SDK; install it as a dev dependency (translation is a build-time step, not an app runtime dependency): `pnpm add -D @anthropic-ai/sdk` (or `npm i -D`), plus `ANTHROPIC_API_KEY`. Default model is `claude-sonnet-5` (balanced quality/cost); override with `translate.model` in config or `--model <id>`. Placeholders, variants and tags are validated after translation: anything not preserved verbatim stays `""` so `check` keeps failing.
69
+
70
+ **Machine output is a draft until a human says yes.** Everything `translate` writes is recorded in `locales/.verbaly-drafts.json` (commit it, never edit it by hand). `verbaly review` lists the drafts, `--approve` accepts them, and importing a translator's file clears the flag because a human already reviewed it. `verbaly check --drafts` turns "nothing unreviewed ships" into a CI rule; plain `check` leaves it alone, since a draft has a value and is therefore not missing.
71
+
72
+ Plug your own provider in `verbaly.config.ts`:
40
73
 
41
74
  ```ts
42
75
  translate: {
@@ -87,7 +120,7 @@ Per-element `data-verbaly-links='{"repo":"https://…"}'` merges over the config
87
120
 
88
121
  `verbaly pseudo` fills a QA catalog (`en-XA` by default, `--locale <id>` to change) from the source: accented letters, `⟦…⟧` markers and ~33% length padding reveal hardcoded strings, clipped layouts and concatenation bugs. Params, variant blocks and tags survive verbatim, with the same structural validation as `translate`.
89
122
 
90
- 📖 Docs: **https://verbaly-web.vercel.app/docs/cli**
123
+ 📖 Docs: **https://verbaly-web.vercel.app/docs/reference/cli**
91
124
 
92
125
  > ⚠️ Early development (`0.x`): API not stable yet.
93
126