verbaly 0.77.0 → 0.79.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.
Files changed (2) hide show
  1. package/README.md +15 -136
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -4,10 +4,6 @@
4
4
 
5
5
  <h3 align="center">Write your text in the code. Ship it in every language.</h3>
6
6
 
7
- <p align="center">
8
- The runtime of Verbaly: an i18n compiler and a tiny runtime for React, Vue, Svelte, Next.js, Nuxt, SvelteKit, Astro and plain HTML.
9
- </p>
10
-
11
7
  <p align="center">
12
8
  <a href="https://www.npmjs.com/package/verbaly"><img src="https://img.shields.io/npm/v/verbaly?logo=npm&color=cb3837" alt="npm version" /></a>
13
9
  <img src="https://img.shields.io/badge/gzip-3.35KB-3fb950" alt="3.35KB gzip" />
@@ -16,28 +12,20 @@
16
12
  </p>
17
13
 
18
14
  <p align="center">
19
- <img src="https://raw.githubusercontent.com/AronSoto/verbaly/develop/assets/demo.gif" alt="A terminal session: the code writes t`Welcome back, ${name}`, verbaly extract writes the catalogs, verbaly check fails on the missing Spanish, then on a translation that dropped {name}, and passes once it is fixed" width="760" />
15
+ <img src="https://raw.githubusercontent.com/AronSoto/verbaly/develop/assets/hero.gif" alt="On the left, a component that writes t`Welcome back, ${name}`, t`You have ${count} new messages` and t`Open inbox`. On the right, the same page in a browser switching from English to Spanish to Portuguese. Below, the four steps: write, extract, translate, check." width="760" />
20
16
  </p>
21
17
 
22
- Most i18n tools ask you to invent a key for every sentence and keep a file per language in step with the code by hand. **Verbaly turns that around:** you write the sentence where it is used, and the compiler gives it a stable key, writes your translation files, types every param and splits one module per language. This package is the runtime: **a 3.35 KB runtime** on its own (`createVerbaly`), and a site with no framework, which also pulls the DOM interpreter and the url helpers, ships **6.17 KB**. Both are measured on every release by `pnpm --filter verbaly size`, never estimated.
18
+ You write the sentence where it is used, and the compiler gives it a stable key, writes your translation files and types every param. This package is the runtime: **a 3.35 KB runtime** with zero dependencies, and a site with no framework ships **6.17 KB**, both measured on every release.
23
19
 
24
20
  ```ts
25
- // with key files: name it, write it in en.json, es.json, pt.json, keep them in sync
26
- t('dashboard.welcome_back', { name });
27
-
28
21
  // with Verbaly: write the sentence where it is used
29
22
  t`Welcome back, ${name}`;
30
23
 
31
24
  // and the compiler writes a stable key and a typed call for you
32
25
  t('ESsQIvlA', { name });
33
-
34
- // prefer a readable key? Opt in per message
35
- t.id('inbox.title')`Hello ${name}`; // → t('inbox.title', { name })
36
26
  ```
37
27
 
38
- Missing a translation? **Every build says which ones**, and `verbaly check` stops your CI on them, so a raw key never reaches a release. A translation that dropped your `{name}` or flattened a plural block fails `check` too: being filled in is not the same as working.
39
-
40
- ## 🚀 Try it in 30 seconds
28
+ ## Install
41
29
 
42
30
  ```bash
43
31
  pnpm add verbaly @verbaly/vite
@@ -53,136 +41,27 @@ export default { plugins: [verbaly()] };
53
41
  ```
54
42
 
55
43
  ```ts
56
- // verbaly.config.ts, created by npx verbaly init: list your languages, the build and `verbaly check` read them
57
- export default { sourceLocale: 'en', locales: ['en', 'es', 'pt'] };
58
- ```
59
-
60
- ```ts
61
- // anywhere in your app, extracted + typed on save
62
- import { t, setLocale } from 'virtual:verbaly';
44
+ // verbaly/app is your project's module: the plugin writes it from your config
45
+ import { t, setLocale } from 'verbaly/app';
63
46
 
64
47
  t`Hello ${name}`;
65
- await setLocale('es'); // per-locale bundle loaded on demand
66
- ```
67
-
68
- With the compiler, every `t` your project holds is typed by its catalog: the generated types fill in `Register`, so `Translate` and `Locale` (both exported here, types only, zero bytes) are your keys and your locales, and an instance's `t` checks keys and params too.
69
-
70
- ### 🎛️ Standalone runtime (no compiler)
71
-
72
- `verbaly` also works on its own for dynamic/CMS content:
73
-
74
- ```ts
75
- import { createVerbaly } from 'verbaly';
76
-
77
- const v = createVerbaly({
78
- locale: 'en',
79
- messages: { en: { greeting: 'Hello {name}' } },
80
- loaders: { es: () => import('./locales/es.json') }, // lazy catalogs
81
- });
82
-
83
- v.t('greeting', { name: 'Aron' }); // "Hello Aron"
84
- v.setLocale('es'); // auto-loads the catalog; or: await v.loadLocale('es') first
48
+ await setLocale('es'); // loads only the Spanish module
85
49
  ```
86
50
 
87
- ### 🌐 Plain HTML, no framework needed
88
-
89
- ```html
90
- <h1 data-verbaly="home.title"></h1>
91
- <p data-verbaly="home.intro" data-verbaly-rich></p>
92
- <!-- rich: 'The build <em>gate</em>' renders a real <em> (whitelist, XSS-safe) -->
93
- <p
94
- data-verbaly="home.cta"
95
- data-verbaly-rich
96
- data-verbaly-links='{"repo":"https://github.com/x"}'
97
- ></p>
98
- <!-- links: 'See the <repo>repo</repo>' renders <a href>; hrefs from you, never from messages -->
99
- ```
100
-
101
- ```ts
102
- import { bindDom, createVerbaly, persistLocale, resolveLocale } from 'verbaly';
103
-
104
- const v = createVerbaly({
105
- locale: resolveLocale({ supported: ['en', 'es', 'pt'] }), // storage → navigator → fallback
106
- /* … */
107
- });
108
- // the whole document by default: the <title> and the meta description translate with the page
109
- bindDom(v, {
110
- richLinks: { docs: { href: '/docs', target: '_blank', rel: 'noopener' } }, // named links
111
- }); // renders + re-renders on locale change
112
-
113
- v.setLocale('es');
114
- persistLocale('es'); // localStorage + <html lang> + <html dir>
115
- ```
116
-
117
- ```ts
118
- // locale switchers without hardcoded names or direction tables
119
- import { localeDirection, localeName } from 'verbaly';
120
-
121
- localeName('es'); // 'español' (endonym, via Intl.DisplayNames)
122
- localeName('de', 'en'); // 'German'
123
- localeDirection('ar'); // 'rtl': switchLocale/persistLocale already apply it to <html dir>
124
- // switchLocale is the whole switch: navigation or in-place swap, then both persistence channels
125
- ```
126
-
127
- ```ts
128
- // server-side (SSR): one instance per request, locale from the request itself
129
- import { createVerbaly, resolveRequestLocale } from 'verbaly';
130
-
131
- // the address wins when it carries the language: a url is public, a cookie is one visitor
132
- const locale = resolveRequestLocale({
133
- supported: ['en', 'es', 'pt'],
134
- path: url.pathname,
135
- routing: 'prefix-except-source',
136
- cookie: cookies.get('verbaly-locale'),
137
- header: request.headers.get('accept-language'),
138
- fallback: 'en',
139
- });
140
- const v = createVerbaly({ locale, fallback: 'en', messages });
141
- ```
142
-
143
- ```ts
144
- // the url helpers, all pure and safe on a server
145
- import { alternateLinks, localePath, stripLocalePath } from 'verbaly';
146
-
147
- localePath('pt', { supported, sourceLocale: 'en', path: '/es/docs' }); // '/pt/docs'
148
- // your framework's own trailing slash, which the Astro and Next integrations pass for you
149
- localePath('es', { supported, sourceLocale: 'en', path: '/', trailingSlash: 'never' }); // '/es'
150
- stripLocalePath({ supported, path: '/es/docs' }); // '/docs', the route behind the url
151
- alternateLinks({ supported, sourceLocale: 'en', path: '/docs', baseUrl: 'https://x.dev' });
152
- // one hreflang entry per locale plus x-default, the same set `verbaly render` writes
153
- ```
154
-
155
- ## ✨ What you get
156
-
157
- - **Type-safe params**: `{name}`, plurals, currency and dates inferred from the message; a wrong or missing param fails to compile.
158
- - **`Intl` all the way**: number, currency, date, time, relative time, lists and units, CLDR plurals and select, with zero dependencies. ICU and relative time are wired only when your catalogs use them.
159
- - **Static text compiled, dynamic text at runtime**: a real runtime path for CMS content, with lazy catalogs per language.
160
- - **Plain HTML**: a DOM interpreter with opt-in rich text (a whitelist, never `innerHTML`) and named links whose hrefs come from your code.
161
- - **RTL and language names built in**: `localeDirection` keeps `<html dir>` right, and `localeName` gives your switcher real names through `Intl.DisplayNames`.
162
- - **Devtools**: opt-in `verbaly/devtools` answers "what key is this text?" in the browser, tree-shaken out of production.
163
- - **Fast, with receipts**: a memoized hot path, benchmarked against i18next on every release (`pnpm --filter verbaly bench`).
164
-
165
- ## 🧩 Ecosystem
51
+ **Works with** [React](https://verbaly-web.vercel.app/docs/frameworks/react) · [Next.js](https://verbaly-web.vercel.app/docs/frameworks/react#next) · [Vue](https://verbaly-web.vercel.app/docs/frameworks/vue) · [Nuxt](https://verbaly-web.vercel.app/docs/frameworks/vue#nuxt) · [Svelte](https://verbaly-web.vercel.app/docs/frameworks/svelte) · [SvelteKit](https://verbaly-web.vercel.app/docs/frameworks/svelte#sveltekit) · [Astro](https://verbaly-web.vercel.app/docs/frameworks/astro) · [webpack, Rollup, esbuild, Rspack](https://verbaly-web.vercel.app/docs/frameworks/vite#unplugin) · [plain HTML](https://verbaly-web.vercel.app/docs/frameworks/dom), and on its own for text that comes from a CMS.
166
52
 
167
- | Package | Description |
168
- | -------------------------------------------------------- | ------------------------------------------------------- |
169
- | `verbaly` | Core runtime (this package) |
170
- | `@verbaly/vite` | Zero-config Vite plugin |
171
- | `@verbaly/unplugin` | webpack · Rollup · esbuild · Rspack |
172
- | `@verbaly/compiler` | Extraction + codegen + the `verbaly` CLI |
173
- | `@verbaly/react` · `@verbaly/vue` · `@verbaly/svelte` | Framework adapters (React also covers Preact) |
174
- | `@verbaly/astro` | Astro integration + per-locale static build |
175
- | `@verbaly/next` · `@verbaly/nuxt` · `@verbaly/sveltekit` | SSR: locale per request, hydration with no flash |
176
- | `@verbaly/mcp` | MCP server: the translation cycle as tools for an agent |
177
- | `@verbaly/studio` | Local review server over your catalogs |
53
+ ## Why
178
54
 
179
- All thirteen share one version number, so you never match compatible ranges.
55
+ - **No key files to maintain:** the compiler names each text and keeps every language file in step.
56
+ - **Typed from the text:** a wrong or missing param fails to compile.
57
+ - **Broken translations never ship:** `verbaly check` stops a missing translation, and one that lost a `{param}` or a plural case, in CI.
58
+ - **`Intl` all the way:** numbers, currency, dates, relative time, lists and plurals, with no dependency.
180
59
 
181
- 📖 **Docs:** https://verbaly-web.vercel.app/docs/reference/api
60
+ ## Learn more
182
61
 
183
- 🔁 **Coming from i18next?** Keep your keys and catalogs: the [migration guide](https://verbaly-web.vercel.app/docs/guide/migrate) maps everything one-to-one.
62
+ 📖 [Docs](https://verbaly-web.vercel.app/docs) · 🧩 [API reference](https://verbaly-web.vercel.app/docs/reference/api) · 🔁 [Coming from i18next](https://verbaly-web.vercel.app/docs/guide/migrate) · ⭐ [GitHub](https://github.com/AronSoto/verbaly)
184
63
 
185
- > ⚠️ Early development (`0.x`): API not stable yet.
64
+ All packages share one version number. Verbaly is `0.x`, and every change is in the [changelog](https://github.com/AronSoto/verbaly/blob/develop/changelog/CHANGELOG.md).
186
65
 
187
66
  ## License
188
67
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verbaly",
3
- "version": "0.77.0",
3
+ "version": "0.79.0",
4
4
  "description": "Effortless i18n: write natural text, ship type-safe, tree-shakeable translations.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -74,8 +74,8 @@
74
74
  "esbuild": "^0.28.2",
75
75
  "fast-check": "^4.10.2",
76
76
  "happy-dom": "^21.0.4",
77
- "i18next": "^26.5.12",
78
- "tinybench": "^6.2.2"
77
+ "i18next": "^26.7.1",
78
+ "tinybench": "^6.2.3"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsdown",