verbaly 0.76.0 → 0.78.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 +23 -142
- package/dist/devtools.cjs +1 -2
- package/dist/devtools.d.cts +2 -4
- package/dist/devtools.d.ts +2 -4
- package/dist/devtools.js +1 -2
- package/dist/index.cjs +12 -23
- package/dist/index.d.cts +1 -17
- package/dist/index.d.ts +1 -17
- package/dist/index.js +12 -23
- package/dist/{types-DtKybAU-.d.cts → types-CyvGqCI4.d.cts} +0 -4
- package/dist/{types-DtKybAU-.d.ts → types-CyvGqCI4.d.ts} +0 -4
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/AronSoto/verbaly/develop/assets/logo.png" alt="Verbaly" width="
|
|
2
|
+
<img src="https://raw.githubusercontent.com/AronSoto/verbaly/develop/assets/logo.png" alt="Verbaly" width="300" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
<
|
|
6
|
-
<em>Effortless i18n: write natural text, ship type-safe, tree-shakeable translations.</em>
|
|
7
|
-
</p>
|
|
5
|
+
<h3 align="center">Write your text in the code. Ship it in every language.</h3>
|
|
8
6
|
|
|
9
7
|
<p align="center">
|
|
10
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>
|
|
11
9
|
<img src="https://img.shields.io/badge/gzip-3.35KB-3fb950" alt="3.35KB gzip" />
|
|
12
10
|
<img src="https://img.shields.io/badge/dependencies-0-3fb950" alt="zero dependencies" />
|
|
13
|
-
<img src="https://img.shields.io/badge/types-included-3178C6?logo=typescript&logoColor=white" alt="TypeScript" />
|
|
14
11
|
<a href="https://github.com/AronSoto/verbaly/blob/develop/LICENSE"><img src="https://img.shields.io/npm/l/verbaly?color=blue" alt="MIT" /></a>
|
|
15
12
|
</p>
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
<p align="center">
|
|
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" />
|
|
16
|
+
</p>
|
|
18
17
|
|
|
19
|
-
|
|
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.
|
|
20
19
|
|
|
21
20
|
```ts
|
|
22
|
-
//
|
|
23
|
-
t`
|
|
21
|
+
// with Verbaly: write the sentence where it is used
|
|
22
|
+
t`Welcome back, ${name}`;
|
|
24
23
|
|
|
25
|
-
//
|
|
26
|
-
t('
|
|
27
|
-
|
|
28
|
-
// Prefer readable keys? Opt in per message:
|
|
29
|
-
t.id('inbox.title')`Hello ${name}`; // → t('inbox.title', { name })
|
|
24
|
+
// and the compiler writes a stable key and a typed call for you
|
|
25
|
+
t('ESsQIvlA', { name });
|
|
30
26
|
```
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
## 🚀 Try it in 30 seconds
|
|
28
|
+
## Install
|
|
35
29
|
|
|
36
30
|
```bash
|
|
37
31
|
pnpm add verbaly @verbaly/vite
|
|
@@ -47,140 +41,27 @@ export default { plugins: [verbaly()] };
|
|
|
47
41
|
```
|
|
48
42
|
|
|
49
43
|
```ts
|
|
50
|
-
// verbaly
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
// anywhere in your app, extracted + typed on save
|
|
56
|
-
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';
|
|
57
46
|
|
|
58
47
|
t`Hello ${name}`;
|
|
59
|
-
await setLocale('es'); //
|
|
48
|
+
await setLocale('es'); // loads only the Spanish module
|
|
60
49
|
```
|
|
61
50
|
|
|
62
|
-
|
|
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.
|
|
63
52
|
|
|
64
|
-
|
|
53
|
+
## Why
|
|
65
54
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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.
|
|
70
59
|
|
|
71
|
-
|
|
72
|
-
locale: 'en',
|
|
73
|
-
messages: { en: { greeting: 'Hello {name}' } },
|
|
74
|
-
loaders: { es: () => import('./locales/es.json') }, // lazy catalogs
|
|
75
|
-
});
|
|
60
|
+
## Learn more
|
|
76
61
|
|
|
77
|
-
|
|
78
|
-
v.setLocale('es'); // auto-loads the catalog; or: await v.loadLocale('es') first
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### 🌐 Plain HTML, no framework needed
|
|
82
|
-
|
|
83
|
-
```html
|
|
84
|
-
<h1 data-verbaly="home.title"></h1>
|
|
85
|
-
<p data-verbaly="home.intro" data-verbaly-rich></p>
|
|
86
|
-
<!-- rich: 'The build <em>gate</em>' renders a real <em> (whitelist, XSS-safe) -->
|
|
87
|
-
<p
|
|
88
|
-
data-verbaly="home.cta"
|
|
89
|
-
data-verbaly-rich
|
|
90
|
-
data-verbaly-links='{"repo":"https://github.com/x"}'
|
|
91
|
-
></p>
|
|
92
|
-
<!-- links: 'See the <repo>repo</repo>' renders <a href>; hrefs from you, never from messages -->
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
import { bindDom, createVerbaly, persistLocale, resolveLocale } from 'verbaly';
|
|
97
|
-
|
|
98
|
-
const v = createVerbaly({
|
|
99
|
-
locale: resolveLocale({ supported: ['en', 'es', 'pt'] }), // storage → navigator → fallback
|
|
100
|
-
/* … */
|
|
101
|
-
});
|
|
102
|
-
// { root: document } so the <title> and the meta description translate with the page
|
|
103
|
-
bindDom(v, {
|
|
104
|
-
richLinks: { docs: { href: '/docs', target: '_blank', rel: 'noopener' } }, // named links
|
|
105
|
-
}); // renders + re-renders on locale change
|
|
106
|
-
|
|
107
|
-
v.setLocale('es');
|
|
108
|
-
persistLocale('es'); // localStorage + <html lang> + <html dir>
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
// locale switchers without hardcoded names or direction tables
|
|
113
|
-
import { localeDirection, localeName } from 'verbaly';
|
|
114
|
-
|
|
115
|
-
localeName('es'); // 'español' (endonym, via Intl.DisplayNames)
|
|
116
|
-
localeName('de', 'en'); // 'German'
|
|
117
|
-
localeDirection('ar'); // 'rtl': switchLocale/persistLocale already apply it to <html dir>
|
|
118
|
-
// switchLocale is the whole switch: navigation or in-place swap, then both persistence channels
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
```ts
|
|
122
|
-
// server-side (SSR): one instance per request, locale from the request itself
|
|
123
|
-
import { createVerbaly, resolveRequestLocale } from 'verbaly';
|
|
124
|
-
|
|
125
|
-
// the address wins when it carries the language: a url is public, a cookie is one visitor
|
|
126
|
-
const locale = resolveRequestLocale({
|
|
127
|
-
supported: ['en', 'es', 'pt'],
|
|
128
|
-
path: url.pathname,
|
|
129
|
-
routing: 'prefix-except-source',
|
|
130
|
-
cookie: cookies.get('verbaly-locale'),
|
|
131
|
-
header: request.headers.get('accept-language'),
|
|
132
|
-
fallback: 'en',
|
|
133
|
-
});
|
|
134
|
-
const v = createVerbaly({ locale, fallback: 'en', messages });
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
// the url helpers, all pure and safe on a server
|
|
139
|
-
import { alternateLinks, localePath, stripLocalePath } from 'verbaly';
|
|
140
|
-
|
|
141
|
-
localePath('pt', { supported, sourceLocale: 'en', path: '/es/docs' }); // '/pt/docs'
|
|
142
|
-
// your framework's own trailing slash, which the Astro and Next integrations pass for you
|
|
143
|
-
localePath('es', { supported, sourceLocale: 'en', path: '/', trailingSlash: 'never' }); // '/es'
|
|
144
|
-
stripLocalePath({ supported, path: '/es/docs' }); // '/docs', the route behind the url
|
|
145
|
-
alternateLinks({ supported, sourceLocale: 'en', path: '/docs', baseUrl: 'https://x.dev' });
|
|
146
|
-
// one hreflang entry per locale plus x-default, the same set `verbaly render` writes
|
|
147
|
-
```
|
|
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)
|
|
148
63
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
- **Hybrid compiler + runtime**: static text compiled (types + tree-shaking), dynamic content via a real runtime path.
|
|
152
|
-
- **Type-safe params**: `{name}`, plurals, currency and dates inferred from the message; wrong/missing params fail to compile.
|
|
153
|
-
- **`Intl`-powered format**: number/currency/date/time/relative/list/unit + CLDR plurals and select/gender, tiny surface. `'Updated {when:relative}'` · `'{langs:list}'` · `'{d:unit/kilometer}'`.
|
|
154
|
-
- **Plain, portable JSON catalogs**: no proprietary format, no lock-in.
|
|
155
|
-
- **A custom formatter knows which message it was called for**: the fourth argument carries the param name and the message key, so its own errors can name them.
|
|
156
|
-
- **ICU and relative time are weight you only carry when you use them**: the compiler sees them in your catalogs and wires what is needed, so an app whose messages use neither never ships those 862 bytes. A message that arrives after the build with ICU syntax shows its own source and says why, rather than rendering something that looks almost right.
|
|
157
|
-
- **DOM interpreter** for framework-less HTML, with opt-in rich text (whitelist-based, XSS-safe) and named links (`richLinks` / `data-verbaly-links`; hrefs come from the caller, `javascript:` blocked).
|
|
158
|
-
- **Lazy catalogs**: `loaders` + `loadLocale` load per-locale JSON on demand, in the runtime itself.
|
|
159
|
-
- **RTL and locale names built in**: `localeDirection` keeps `<html dir>` right when you add Arabic or Hebrew (applied by `switchLocale`/`persistLocale` and `verbaly render`), and `localeName` gives your locale switcher real language names via `Intl.DisplayNames`.
|
|
160
|
-
- **Runtime devtools**: opt-in `verbaly/devtools` answers "what key is this text?" in the browser: hover to see any element's key/locale/source, plus a live missing-keys panel. Tree-shaken out of production (its own chunk). Or wire the `onResolve` hook yourself.
|
|
161
|
-
- **Fast, with receipts**: fully memoized hot path, benchmarked every release: 5-35× faster than i18next on lookup, interpolation and plurals.
|
|
162
|
-
|
|
163
|
-
## 🧩 Ecosystem
|
|
164
|
-
|
|
165
|
-
| Package | Description |
|
|
166
|
-
| -------------------------------------------------------- | ------------------------------------------------------- |
|
|
167
|
-
| `verbaly` | Core runtime (this package) |
|
|
168
|
-
| `@verbaly/vite` | Zero-config Vite plugin |
|
|
169
|
-
| `@verbaly/unplugin` | webpack · Rollup · esbuild · Rspack |
|
|
170
|
-
| `@verbaly/compiler` | Extraction + codegen + the `verbaly` CLI |
|
|
171
|
-
| `@verbaly/react` · `@verbaly/vue` · `@verbaly/svelte` | Framework adapters (React also covers Preact) |
|
|
172
|
-
| `@verbaly/astro` | Astro integration + per-locale static build |
|
|
173
|
-
| `@verbaly/next` · `@verbaly/nuxt` · `@verbaly/sveltekit` | SSR: locale per request, hydration with no flash |
|
|
174
|
-
| `@verbaly/mcp` | MCP server: the translation cycle as tools for an agent |
|
|
175
|
-
| `@verbaly/studio` | Local review server over your catalogs |
|
|
176
|
-
|
|
177
|
-
All thirteen share one version number, so you never match compatible ranges.
|
|
178
|
-
|
|
179
|
-
📖 **Docs:** https://verbaly-web.vercel.app/docs/reference/api
|
|
180
|
-
|
|
181
|
-
🔁 **Coming from i18next?** Keep your keys and catalogs: the [migration guide](https://verbaly-web.vercel.app/docs/guide/migrate) maps everything one-to-one.
|
|
182
|
-
|
|
183
|
-
> ⚠️ 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).
|
|
184
65
|
|
|
185
66
|
## License
|
|
186
67
|
|
package/dist/devtools.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// src/devtools.ts
|
|
3
3
|
const HOTKEY = {
|
|
4
4
|
alt: "altKey",
|
|
5
5
|
ctrl: "ctrlKey",
|
|
@@ -109,5 +109,4 @@ const CSS = `
|
|
|
109
109
|
.verbaly-dt-row.hit{color:#7bd88f}
|
|
110
110
|
.verbaly-dt-src{opacity:.75;white-space:pre-wrap;word-break:break-word}
|
|
111
111
|
`;
|
|
112
|
-
//#endregion
|
|
113
112
|
exports.attachDevtools = attachDevtools;
|
package/dist/devtools.d.cts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { b as Verbaly } from "./types-
|
|
2
|
-
//#region src/devtools.d.ts
|
|
1
|
+
import { b as Verbaly } from "./types-CyvGqCI4.cjs";
|
|
3
2
|
export interface DevtoolsOptions {
|
|
4
3
|
root?: ParentNode;
|
|
5
4
|
attribute?: string;
|
|
6
5
|
hotkey?: 'alt' | 'ctrl' | 'shift' | 'meta';
|
|
7
6
|
catalogDir?: string;
|
|
8
7
|
}
|
|
9
|
-
export declare function attachDevtools(instance: Verbaly, options?: DevtoolsOptions): () => void;
|
|
10
|
-
//#endregion
|
|
8
|
+
export declare function attachDevtools(instance: Verbaly, options?: DevtoolsOptions): () => void;
|
package/dist/devtools.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { b as Verbaly } from "./types-
|
|
2
|
-
//#region src/devtools.d.ts
|
|
1
|
+
import { b as Verbaly } from "./types-CyvGqCI4.js";
|
|
3
2
|
export interface DevtoolsOptions {
|
|
4
3
|
root?: ParentNode;
|
|
5
4
|
attribute?: string;
|
|
6
5
|
hotkey?: 'alt' | 'ctrl' | 'shift' | 'meta';
|
|
7
6
|
catalogDir?: string;
|
|
8
7
|
}
|
|
9
|
-
export declare function attachDevtools(instance: Verbaly, options?: DevtoolsOptions): () => void;
|
|
10
|
-
//#endregion
|
|
8
|
+
export declare function attachDevtools(instance: Verbaly, options?: DevtoolsOptions): () => void;
|
package/dist/devtools.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/devtools.ts
|
|
2
2
|
const HOTKEY = {
|
|
3
3
|
alt: "altKey",
|
|
4
4
|
ctrl: "ctrlKey",
|
|
@@ -108,5 +108,4 @@ const CSS = `
|
|
|
108
108
|
.verbaly-dt-row.hit{color:#7bd88f}
|
|
109
109
|
.verbaly-dt-src{opacity:.75;white-space:pre-wrap;word-break:break-word}
|
|
110
110
|
`;
|
|
111
|
-
//#endregion
|
|
112
111
|
export { attachDevtools };
|
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// src/warn.ts
|
|
3
3
|
const warned = /* @__PURE__ */ new Set();
|
|
4
4
|
function warnOnce(message) {
|
|
5
5
|
if (warned.has(message)) return;
|
|
6
6
|
warned.add(message);
|
|
7
7
|
console.warn(`[verbaly] ${message}`);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
//#region src/flatten.ts
|
|
9
|
+
// src/flatten.ts
|
|
11
10
|
function flatten(tree, prefix = "", out = Object.create(null)) {
|
|
12
11
|
if (!isGroup(tree)) return out;
|
|
13
12
|
for (const [key, value] of Object.entries(tree)) {
|
|
@@ -21,8 +20,7 @@ function flatten(tree, prefix = "", out = Object.create(null)) {
|
|
|
21
20
|
function isGroup(value) {
|
|
22
21
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
//#region src/intl.ts
|
|
23
|
+
// src/intl.ts
|
|
26
24
|
const CACHE_CAP = 200;
|
|
27
25
|
const nfCache = /* @__PURE__ */ new Map();
|
|
28
26
|
const dtfCache = /* @__PURE__ */ new Map();
|
|
@@ -69,8 +67,7 @@ function listFormat(locale, type) {
|
|
|
69
67
|
function displayNames(locale) {
|
|
70
68
|
return cached(dnCache, locale, locale, (tag) => new Intl.DisplayNames(tag, { type: "language" }));
|
|
71
69
|
}
|
|
72
|
-
|
|
73
|
-
//#region src/format.ts
|
|
70
|
+
// src/format.ts
|
|
74
71
|
function formatNodes(nodes, ctx) {
|
|
75
72
|
let out = "";
|
|
76
73
|
for (const node of nodes) if (node.kind === "text") out += node.value;
|
|
@@ -206,8 +203,7 @@ function autoFormat(value, locale, ctx) {
|
|
|
206
203
|
function toDate(value) {
|
|
207
204
|
return value instanceof Date ? value : new Date(value);
|
|
208
205
|
}
|
|
209
|
-
|
|
210
|
-
//#region src/locale.ts
|
|
206
|
+
// src/locale.ts
|
|
211
207
|
const LOCALE_STORAGE_KEY = "verbaly-locale";
|
|
212
208
|
function narrowLocales(lang) {
|
|
213
209
|
const out = [];
|
|
@@ -457,8 +453,7 @@ function getStorage() {
|
|
|
457
453
|
return null;
|
|
458
454
|
}
|
|
459
455
|
}
|
|
460
|
-
|
|
461
|
-
//#region src/icu.ts
|
|
456
|
+
// src/icu.ts
|
|
462
457
|
const ICU_ARG = /(^|[^{])\{\s*[a-zA-Z0-9_]+\s*,\s*(?:plural|selectordinal|select|number|date|time)\b/;
|
|
463
458
|
function isIcu(message) {
|
|
464
459
|
return ICU_ARG.test(message);
|
|
@@ -608,8 +603,7 @@ function parseIcu(message) {
|
|
|
608
603
|
}
|
|
609
604
|
return parseBody(false);
|
|
610
605
|
}
|
|
611
|
-
|
|
612
|
-
//#region src/parse.ts
|
|
606
|
+
// src/parse.ts
|
|
613
607
|
const astCache = /* @__PURE__ */ new Map();
|
|
614
608
|
const AST_CACHE_MAX = 5e3;
|
|
615
609
|
const oldest = astCache.keys();
|
|
@@ -776,8 +770,7 @@ function splitTop(input) {
|
|
|
776
770
|
parts.push(buf);
|
|
777
771
|
return parts;
|
|
778
772
|
}
|
|
779
|
-
|
|
780
|
-
//#region src/instance.ts
|
|
773
|
+
// src/instance.ts
|
|
781
774
|
function createVerbaly(options = {}) {
|
|
782
775
|
const dict = Object.setPrototypeOf({}, null);
|
|
783
776
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -939,8 +932,7 @@ function isTemplateStrings(value) {
|
|
|
939
932
|
function detectLocale() {
|
|
940
933
|
return typeof document !== "undefined" && typeof navigator !== "undefined" && navigator.language ? navigator.language : "en";
|
|
941
934
|
}
|
|
942
|
-
|
|
943
|
-
//#region src/tags.ts
|
|
935
|
+
// src/tags.ts
|
|
944
936
|
const TAG = /<(\/?)([a-zA-Z][\w-]*)\s*(\/?)>/g;
|
|
945
937
|
const BREAK = /^(?:br|wbr)$/;
|
|
946
938
|
const ENTITY = /&(?:(lt|gt|amp)|#(\d+)|#[xX]([0-9a-fA-F]+));/g;
|
|
@@ -990,8 +982,7 @@ function parseTags(text) {
|
|
|
990
982
|
}
|
|
991
983
|
return root;
|
|
992
984
|
}
|
|
993
|
-
|
|
994
|
-
//#region src/dom.ts
|
|
985
|
+
// src/dom.ts
|
|
995
986
|
const UNSAFE_HREF = /^[\u0000-\u0020]*(javascript|data|vbscript):/i;
|
|
996
987
|
const URL_ATTR = /^(href|src|xlink:href|action|formaction)$/;
|
|
997
988
|
const BLOCKED_ATTR = /^(style|srcdoc)$/;
|
|
@@ -1067,7 +1058,7 @@ function inlineMessages(root) {
|
|
|
1067
1058
|
function bindDom(instance, options = {}) {
|
|
1068
1059
|
if (typeof document === "undefined") throw new Error("[verbaly] bindDom requires a DOM");
|
|
1069
1060
|
const t = instance.t;
|
|
1070
|
-
const root = options.root ?? document
|
|
1061
|
+
const root = options.root ?? document;
|
|
1071
1062
|
const attr = options.attribute ?? "data-verbaly";
|
|
1072
1063
|
const argsAttr = `${attr}-args`;
|
|
1073
1064
|
const attrsAttr = `${attr}-attr`;
|
|
@@ -1205,8 +1196,7 @@ function parseArgs(raw) {
|
|
|
1205
1196
|
return;
|
|
1206
1197
|
}
|
|
1207
1198
|
}
|
|
1208
|
-
|
|
1209
|
-
//#region src/relative.ts
|
|
1199
|
+
// src/relative.ts
|
|
1210
1200
|
const REL_UNITS = [
|
|
1211
1201
|
["year", 31536e3],
|
|
1212
1202
|
["month", 2592e3],
|
|
@@ -1243,7 +1233,6 @@ const relativeFormatter = (value, locale, arg, info) => {
|
|
|
1243
1233
|
return degrade(`cannot format ${describe(value)} as "${arg}"`);
|
|
1244
1234
|
}
|
|
1245
1235
|
};
|
|
1246
|
-
//#endregion
|
|
1247
1236
|
exports.CATALOG_SCRIPT = CATALOG_SCRIPT;
|
|
1248
1237
|
exports.LOCALE_STORAGE_KEY = LOCALE_STORAGE_KEY;
|
|
1249
1238
|
exports.RICH_TAGS = RICH_TAGS;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { C as MessageNode, S as IcuParser, T as parse, _ as TArgs, a as Formatter, b as Verbaly, c as LocaleLoader, d as MessageValue, f as ParamNames, g as ResolveStatus, h as ResolveInfo, i as FormatInfo, l as MessageAt, m as Register, n as DictionaryInput, o as KeysOf, p as Params, r as FlatKeys, s as Locale, t as AddMessagesOptions, u as MessageTree, v as TFunction, w as ParamNode, x as VerbalyOptions, y as Translate } from "./types-
|
|
2
|
-
//#region src/instance.d.ts
|
|
1
|
+
import { C as MessageNode, S as IcuParser, T as parse, _ as TArgs, a as Formatter, b as Verbaly, c as LocaleLoader, d as MessageValue, f as ParamNames, g as ResolveStatus, h as ResolveInfo, i as FormatInfo, l as MessageAt, m as Register, n as DictionaryInput, o as KeysOf, p as Params, r as FlatKeys, s as Locale, t as AddMessagesOptions, u as MessageTree, v as TFunction, w as ParamNode, x as VerbalyOptions, y as Translate } from "./types-CyvGqCI4.cjs";
|
|
3
2
|
export declare function createVerbaly<const D extends DictionaryInput = DictionaryInput>(options?: VerbalyOptions<D>): Verbaly<D>;
|
|
4
|
-
//#endregion
|
|
5
|
-
//#region src/dom.d.ts
|
|
6
3
|
type RichLink = string | {
|
|
7
4
|
href: string;
|
|
8
5
|
target?: string;
|
|
@@ -26,8 +23,6 @@ export declare const RICH_TAGS: string[];
|
|
|
26
23
|
export declare const CATALOG_SCRIPT = "data-verbaly-catalog";
|
|
27
24
|
export declare function inlineMessages(root?: ParentNode): Record<string, string> | undefined;
|
|
28
25
|
export declare function bindDom<D extends DictionaryInput>(instance: Verbaly<D>, options?: BindDomOptions): () => void;
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/locale.d.ts
|
|
31
26
|
interface ResolveLocaleOptions {
|
|
32
27
|
supported: string[];
|
|
33
28
|
fallback?: string;
|
|
@@ -105,24 +100,13 @@ interface SwitchLocaleOptions {
|
|
|
105
100
|
}
|
|
106
101
|
export declare function switchLocale(instance: Pick<Verbaly, 'loadLocale' | 'setLocale'> & Partial<Pick<Verbaly, 'locales'>>, locale: string, options?: SwitchLocaleOptions): Promise<void>;
|
|
107
102
|
export declare function persistLocale(locale: string, storageKey?: string | false): void;
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/icu.d.ts
|
|
110
103
|
export declare function parseIcu(message: string): MessageNode[];
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/relative.d.ts
|
|
113
104
|
export declare const relativeFormatter: Formatter;
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region src/flatten.d.ts
|
|
116
105
|
export declare function flatten(tree: MessageTree, prefix?: string, out?: Record<string, string>): Record<string, string>;
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/tags.d.ts
|
|
119
106
|
type TagNode = string | {
|
|
120
107
|
name: string;
|
|
121
108
|
children: TagNode[];
|
|
122
109
|
};
|
|
123
110
|
export declare function parseTags(text: string): TagNode[];
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/warn.d.ts
|
|
126
111
|
export declare function warnOnce(message: string): void;
|
|
127
|
-
//#endregion
|
|
128
112
|
export { type AddMessagesOptions, type AlternateLink, type AlternateLinksOptions, type BindDomOptions, type DictionaryInput, type FlatKeys, type FormatInfo, type Formatter, type IcuParser, type KeysOf, type Locale, type LocaleFromPathOptions, type LocaleLoader, type LocalePathOptions, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, type Register, type RequestLocaleOptions, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type Routing, type StripLocalePathOptions, type SwitchLocaleOptions, type TArgs, type TFunction, type TagNode, type TrailingSlash, type Translate, type Verbaly, type VerbalyOptions, parse };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { C as MessageNode, S as IcuParser, T as parse, _ as TArgs, a as Formatter, b as Verbaly, c as LocaleLoader, d as MessageValue, f as ParamNames, g as ResolveStatus, h as ResolveInfo, i as FormatInfo, l as MessageAt, m as Register, n as DictionaryInput, o as KeysOf, p as Params, r as FlatKeys, s as Locale, t as AddMessagesOptions, u as MessageTree, v as TFunction, w as ParamNode, x as VerbalyOptions, y as Translate } from "./types-
|
|
2
|
-
//#region src/instance.d.ts
|
|
1
|
+
import { C as MessageNode, S as IcuParser, T as parse, _ as TArgs, a as Formatter, b as Verbaly, c as LocaleLoader, d as MessageValue, f as ParamNames, g as ResolveStatus, h as ResolveInfo, i as FormatInfo, l as MessageAt, m as Register, n as DictionaryInput, o as KeysOf, p as Params, r as FlatKeys, s as Locale, t as AddMessagesOptions, u as MessageTree, v as TFunction, w as ParamNode, x as VerbalyOptions, y as Translate } from "./types-CyvGqCI4.js";
|
|
3
2
|
export declare function createVerbaly<const D extends DictionaryInput = DictionaryInput>(options?: VerbalyOptions<D>): Verbaly<D>;
|
|
4
|
-
//#endregion
|
|
5
|
-
//#region src/dom.d.ts
|
|
6
3
|
type RichLink = string | {
|
|
7
4
|
href: string;
|
|
8
5
|
target?: string;
|
|
@@ -26,8 +23,6 @@ export declare const RICH_TAGS: string[];
|
|
|
26
23
|
export declare const CATALOG_SCRIPT = "data-verbaly-catalog";
|
|
27
24
|
export declare function inlineMessages(root?: ParentNode): Record<string, string> | undefined;
|
|
28
25
|
export declare function bindDom<D extends DictionaryInput>(instance: Verbaly<D>, options?: BindDomOptions): () => void;
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/locale.d.ts
|
|
31
26
|
interface ResolveLocaleOptions {
|
|
32
27
|
supported: string[];
|
|
33
28
|
fallback?: string;
|
|
@@ -105,24 +100,13 @@ interface SwitchLocaleOptions {
|
|
|
105
100
|
}
|
|
106
101
|
export declare function switchLocale(instance: Pick<Verbaly, 'loadLocale' | 'setLocale'> & Partial<Pick<Verbaly, 'locales'>>, locale: string, options?: SwitchLocaleOptions): Promise<void>;
|
|
107
102
|
export declare function persistLocale(locale: string, storageKey?: string | false): void;
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/icu.d.ts
|
|
110
103
|
export declare function parseIcu(message: string): MessageNode[];
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/relative.d.ts
|
|
113
104
|
export declare const relativeFormatter: Formatter;
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region src/flatten.d.ts
|
|
116
105
|
export declare function flatten(tree: MessageTree, prefix?: string, out?: Record<string, string>): Record<string, string>;
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/tags.d.ts
|
|
119
106
|
type TagNode = string | {
|
|
120
107
|
name: string;
|
|
121
108
|
children: TagNode[];
|
|
122
109
|
};
|
|
123
110
|
export declare function parseTags(text: string): TagNode[];
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/warn.d.ts
|
|
126
111
|
export declare function warnOnce(message: string): void;
|
|
127
|
-
//#endregion
|
|
128
112
|
export { type AddMessagesOptions, type AlternateLink, type AlternateLinksOptions, type BindDomOptions, type DictionaryInput, type FlatKeys, type FormatInfo, type Formatter, type IcuParser, type KeysOf, type Locale, type LocaleFromPathOptions, type LocaleLoader, type LocalePathOptions, type MessageAt, type MessageNode, type MessageTree, type MessageValue, type ParamNames, type ParamNode, type Params, type Register, type RequestLocaleOptions, type ResolveInfo, type ResolveLocaleOptions, type ResolveStatus, type RichLink, type Routing, type StripLocalePathOptions, type SwitchLocaleOptions, type TArgs, type TFunction, type TagNode, type TrailingSlash, type Translate, type Verbaly, type VerbalyOptions, parse };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
// src/warn.ts
|
|
2
2
|
const warned = /* @__PURE__ */ new Set();
|
|
3
3
|
function warnOnce(message) {
|
|
4
4
|
if (warned.has(message)) return;
|
|
5
5
|
warned.add(message);
|
|
6
6
|
console.warn(`[verbaly] ${message}`);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
//#region src/flatten.ts
|
|
8
|
+
// src/flatten.ts
|
|
10
9
|
function flatten(tree, prefix = "", out = Object.create(null)) {
|
|
11
10
|
if (!isGroup(tree)) return out;
|
|
12
11
|
for (const [key, value] of Object.entries(tree)) {
|
|
@@ -20,8 +19,7 @@ function flatten(tree, prefix = "", out = Object.create(null)) {
|
|
|
20
19
|
function isGroup(value) {
|
|
21
20
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
//#region src/intl.ts
|
|
22
|
+
// src/intl.ts
|
|
25
23
|
const CACHE_CAP = 200;
|
|
26
24
|
const nfCache = /* @__PURE__ */ new Map();
|
|
27
25
|
const dtfCache = /* @__PURE__ */ new Map();
|
|
@@ -68,8 +66,7 @@ function listFormat(locale, type) {
|
|
|
68
66
|
function displayNames(locale) {
|
|
69
67
|
return cached(dnCache, locale, locale, (tag) => new Intl.DisplayNames(tag, { type: "language" }));
|
|
70
68
|
}
|
|
71
|
-
|
|
72
|
-
//#region src/format.ts
|
|
69
|
+
// src/format.ts
|
|
73
70
|
function formatNodes(nodes, ctx) {
|
|
74
71
|
let out = "";
|
|
75
72
|
for (const node of nodes) if (node.kind === "text") out += node.value;
|
|
@@ -205,8 +202,7 @@ function autoFormat(value, locale, ctx) {
|
|
|
205
202
|
function toDate(value) {
|
|
206
203
|
return value instanceof Date ? value : new Date(value);
|
|
207
204
|
}
|
|
208
|
-
|
|
209
|
-
//#region src/locale.ts
|
|
205
|
+
// src/locale.ts
|
|
210
206
|
const LOCALE_STORAGE_KEY = "verbaly-locale";
|
|
211
207
|
function narrowLocales(lang) {
|
|
212
208
|
const out = [];
|
|
@@ -456,8 +452,7 @@ function getStorage() {
|
|
|
456
452
|
return null;
|
|
457
453
|
}
|
|
458
454
|
}
|
|
459
|
-
|
|
460
|
-
//#region src/icu.ts
|
|
455
|
+
// src/icu.ts
|
|
461
456
|
const ICU_ARG = /(^|[^{])\{\s*[a-zA-Z0-9_]+\s*,\s*(?:plural|selectordinal|select|number|date|time)\b/;
|
|
462
457
|
function isIcu(message) {
|
|
463
458
|
return ICU_ARG.test(message);
|
|
@@ -607,8 +602,7 @@ function parseIcu(message) {
|
|
|
607
602
|
}
|
|
608
603
|
return parseBody(false);
|
|
609
604
|
}
|
|
610
|
-
|
|
611
|
-
//#region src/parse.ts
|
|
605
|
+
// src/parse.ts
|
|
612
606
|
const astCache = /* @__PURE__ */ new Map();
|
|
613
607
|
const AST_CACHE_MAX = 5e3;
|
|
614
608
|
const oldest = astCache.keys();
|
|
@@ -775,8 +769,7 @@ function splitTop(input) {
|
|
|
775
769
|
parts.push(buf);
|
|
776
770
|
return parts;
|
|
777
771
|
}
|
|
778
|
-
|
|
779
|
-
//#region src/instance.ts
|
|
772
|
+
// src/instance.ts
|
|
780
773
|
function createVerbaly(options = {}) {
|
|
781
774
|
const dict = Object.setPrototypeOf({}, null);
|
|
782
775
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -938,8 +931,7 @@ function isTemplateStrings(value) {
|
|
|
938
931
|
function detectLocale() {
|
|
939
932
|
return typeof document !== "undefined" && typeof navigator !== "undefined" && navigator.language ? navigator.language : "en";
|
|
940
933
|
}
|
|
941
|
-
|
|
942
|
-
//#region src/tags.ts
|
|
934
|
+
// src/tags.ts
|
|
943
935
|
const TAG = /<(\/?)([a-zA-Z][\w-]*)\s*(\/?)>/g;
|
|
944
936
|
const BREAK = /^(?:br|wbr)$/;
|
|
945
937
|
const ENTITY = /&(?:(lt|gt|amp)|#(\d+)|#[xX]([0-9a-fA-F]+));/g;
|
|
@@ -989,8 +981,7 @@ function parseTags(text) {
|
|
|
989
981
|
}
|
|
990
982
|
return root;
|
|
991
983
|
}
|
|
992
|
-
|
|
993
|
-
//#region src/dom.ts
|
|
984
|
+
// src/dom.ts
|
|
994
985
|
const UNSAFE_HREF = /^[\u0000-\u0020]*(javascript|data|vbscript):/i;
|
|
995
986
|
const URL_ATTR = /^(href|src|xlink:href|action|formaction)$/;
|
|
996
987
|
const BLOCKED_ATTR = /^(style|srcdoc)$/;
|
|
@@ -1066,7 +1057,7 @@ function inlineMessages(root) {
|
|
|
1066
1057
|
function bindDom(instance, options = {}) {
|
|
1067
1058
|
if (typeof document === "undefined") throw new Error("[verbaly] bindDom requires a DOM");
|
|
1068
1059
|
const t = instance.t;
|
|
1069
|
-
const root = options.root ?? document
|
|
1060
|
+
const root = options.root ?? document;
|
|
1070
1061
|
const attr = options.attribute ?? "data-verbaly";
|
|
1071
1062
|
const argsAttr = `${attr}-args`;
|
|
1072
1063
|
const attrsAttr = `${attr}-attr`;
|
|
@@ -1204,8 +1195,7 @@ function parseArgs(raw) {
|
|
|
1204
1195
|
return;
|
|
1205
1196
|
}
|
|
1206
1197
|
}
|
|
1207
|
-
|
|
1208
|
-
//#region src/relative.ts
|
|
1198
|
+
// src/relative.ts
|
|
1209
1199
|
const REL_UNITS = [
|
|
1210
1200
|
["year", 31536e3],
|
|
1211
1201
|
["month", 2592e3],
|
|
@@ -1242,5 +1232,4 @@ const relativeFormatter = (value, locale, arg, info) => {
|
|
|
1242
1232
|
return degrade(`cannot format ${describe(value)} as "${arg}"`);
|
|
1243
1233
|
}
|
|
1244
1234
|
};
|
|
1245
|
-
//#endregion
|
|
1246
1235
|
export { CATALOG_SCRIPT, LOCALE_STORAGE_KEY, RICH_TAGS, VOID_TAGS, alternateLinks, bindDom, createVerbaly, flatten, inlineMessages, localeDirection, localeFromPath, localeName, localePath, negotiateLocale, normalizeLink, parse, parseIcu, parseTags, persistLocale, relativeFormatter, resolveLocale, resolveRequestLocale, safeAttribute, safeHref, stripLocalePath, switchLocale, warnOnce };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/parse.d.ts
|
|
2
1
|
type MessageNode = {
|
|
3
2
|
kind: 'text';
|
|
4
3
|
value: string;
|
|
@@ -15,8 +14,6 @@ interface ParamNode {
|
|
|
15
14
|
}
|
|
16
15
|
type IcuParser = (message: string) => MessageNode[];
|
|
17
16
|
declare function parse(message: string, icu?: IcuParser): MessageNode[];
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/types.d.ts
|
|
20
17
|
type MessageValue = string | MessageTree;
|
|
21
18
|
interface MessageTree {
|
|
22
19
|
[key: string]: MessageValue;
|
|
@@ -94,5 +91,4 @@ interface Verbaly<D extends DictionaryInput = DictionaryInput> {
|
|
|
94
91
|
source: string;
|
|
95
92
|
} | undefined;
|
|
96
93
|
}
|
|
97
|
-
//#endregion
|
|
98
94
|
export { MessageNode as C, IcuParser as S, parse as T, TArgs as _, Formatter as a, Verbaly as b, LocaleLoader as c, MessageValue as d, ParamNames as f, ResolveStatus as g, ResolveInfo as h, FormatInfo as i, MessageAt as l, Register as m, DictionaryInput as n, KeysOf as o, Params as p, FlatKeys as r, Locale as s, AddMessagesOptions as t, MessageTree as u, TFunction as v, ParamNode as w, VerbalyOptions as x, Translate as y };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/parse.d.ts
|
|
2
1
|
type MessageNode = {
|
|
3
2
|
kind: 'text';
|
|
4
3
|
value: string;
|
|
@@ -15,8 +14,6 @@ interface ParamNode {
|
|
|
15
14
|
}
|
|
16
15
|
type IcuParser = (message: string) => MessageNode[];
|
|
17
16
|
declare function parse(message: string, icu?: IcuParser): MessageNode[];
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/types.d.ts
|
|
20
17
|
type MessageValue = string | MessageTree;
|
|
21
18
|
interface MessageTree {
|
|
22
19
|
[key: string]: MessageValue;
|
|
@@ -94,5 +91,4 @@ interface Verbaly<D extends DictionaryInput = DictionaryInput> {
|
|
|
94
91
|
source: string;
|
|
95
92
|
} | undefined;
|
|
96
93
|
}
|
|
97
|
-
//#endregion
|
|
98
94
|
export { MessageNode as C, IcuParser as S, parse as T, TArgs as _, Formatter as a, Verbaly as b, LocaleLoader as c, MessageValue as d, ParamNames as f, ResolveStatus as g, ResolveInfo as h, FormatInfo as i, MessageAt as l, Register as m, DictionaryInput as n, KeysOf as o, Params as p, FlatKeys as r, Locale as s, AddMessagesOptions as t, MessageTree as u, TFunction as v, ParamNode as w, VerbalyOptions as x, Translate as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "verbaly",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"description": "Effortless i18n: write natural text, ship type-safe, tree-shakeable translations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"bugs": {
|
|
30
30
|
"url": "https://github.com/AronSoto/verbaly/issues"
|
|
31
31
|
},
|
|
32
|
+
"funding": {
|
|
33
|
+
"type": "github",
|
|
34
|
+
"url": "https://github.com/sponsors/AronSoto"
|
|
35
|
+
},
|
|
32
36
|
"type": "module",
|
|
33
37
|
"main": "./dist/index.cjs",
|
|
34
38
|
"module": "./dist/index.js",
|
|
@@ -70,7 +74,7 @@
|
|
|
70
74
|
"esbuild": "^0.28.2",
|
|
71
75
|
"fast-check": "^4.10.2",
|
|
72
76
|
"happy-dom": "^21.0.4",
|
|
73
|
-
"i18next": "^26.5.
|
|
77
|
+
"i18next": "^26.5.12",
|
|
74
78
|
"tinybench": "^6.2.2"
|
|
75
79
|
},
|
|
76
80
|
"scripts": {
|