@verbaly/astro 0.26.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/LICENSE +21 -0
- package/README.md +83 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aron Soto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/AronSoto/verbaly/develop/assets/logo.png" alt="Verbaly" width="300" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center"><em>Astro integration for Verbaly: write-in-source extraction for .astro files plus automatic per-locale static rendering.</em></p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@verbaly/astro"><img src="https://img.shields.io/npm/v/@verbaly/astro?logo=npm&color=cb3837" alt="npm version" /></a>
|
|
9
|
+
<a href="https://github.com/AronSoto/verbaly/blob/develop/LICENSE"><img src="https://img.shields.io/npm/l/@verbaly/astro?color=blue" alt="MIT" /></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Write your text in place, in the frontmatter or right in the markup of your `.astro` files. The compiler extracts the messages, generates stable keys, typed params and one catalog per language, and the dev server keeps them in sync while you code.
|
|
15
|
+
|
|
16
|
+
One line in `astro.config` wires everything: the Vite plugin (live extraction, the `virtual:verbaly` module and the build gate) and, if you use the mirror flow, `verbaly render` runs by itself after every build. The generated types live inside Astro's own `.astro` folder (via `injectTypes`), so no extra file lands in your project.
|
|
17
|
+
|
|
18
|
+
## 🚀 Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add verbaly @verbaly/astro
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## ⚡ Wire it up
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// astro.config.mjs
|
|
28
|
+
import { defineConfig } from 'astro/config';
|
|
29
|
+
import verbaly from '@verbaly/astro';
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
integrations: [verbaly()],
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Locales live in your `verbaly.config` (created by `npx verbaly init`), or inline:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
integrations: [verbaly({ locales: ['en', 'es', 'pt'] })],
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## ✍️ Write the text in place
|
|
43
|
+
|
|
44
|
+
```astro
|
|
45
|
+
---
|
|
46
|
+
const title = t`Search and find`;
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
<h1>{title}</h1>
|
|
50
|
+
<p>{t`Hello ${name}, you have ${count} messages`}</p>
|
|
51
|
+
<img alt={t`Company logo`} src="/logo.png" />
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Every message becomes a stable key with typed params. Untranslated entries fail the build (opt out with `failOnMissing: false`).
|
|
55
|
+
|
|
56
|
+
## 🌍 Two ways to ship the languages
|
|
57
|
+
|
|
58
|
+
**Path-based pages** (Astro's i18n routing): create one instance per locale page and use `t` as usual. Astro owns the routes, Verbaly owns the catalogs and the type safety.
|
|
59
|
+
|
|
60
|
+
```astro
|
|
61
|
+
---
|
|
62
|
+
import { createInstance } from 'virtual:verbaly';
|
|
63
|
+
const { t } = await createInstance(Astro.currentLocale);
|
|
64
|
+
---
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Mirror mode** (one tree, pre-translated copies): keep your markup bound with `data-verbaly` attributes and add a `render` section to your `verbaly.config`. After `astro build`, the integration mirrors `dist/` into `dist/<locale>/` with every message pre-filled, plus hreflang and a per-locale sitemap if you configure `baseUrl`. No flash of untranslated content, no client work.
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
// verbaly.config.mjs
|
|
71
|
+
export default {
|
|
72
|
+
locales: ['en', 'es', 'pt'],
|
|
73
|
+
render: { baseUrl: 'https://example.com', sitemap: true },
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Force it on or off with the integration option: `verbaly({ render: true })`.
|
|
78
|
+
|
|
79
|
+
## 📚 Docs
|
|
80
|
+
|
|
81
|
+
Full guide: [verbaly-web.vercel.app/docs/frameworks/astro](https://verbaly-web.vercel.app/docs/frameworks/astro)
|
|
82
|
+
|
|
83
|
+
MIT © Aron Soto
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { RenderConfig, RenderConfig as RenderConfig$1, VerbalyConfig } from "@verbaly/compiler";
|
|
2
|
+
import { ViteVerbalyOptions, ViteVerbalyOptions as ViteVerbalyOptions$1 } from "@verbaly/vite";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
interface VerbalyAstroOptions extends Omit<ViteVerbalyOptions$1, 'render'> {
|
|
5
|
+
render?: boolean | RenderConfig$1;
|
|
6
|
+
}
|
|
7
|
+
interface AstroConfigLike {
|
|
8
|
+
root: URL;
|
|
9
|
+
}
|
|
10
|
+
interface ConfigSetupLike {
|
|
11
|
+
config: AstroConfigLike;
|
|
12
|
+
updateConfig(config: {
|
|
13
|
+
vite?: {
|
|
14
|
+
plugins?: unknown;
|
|
15
|
+
};
|
|
16
|
+
}): unknown;
|
|
17
|
+
}
|
|
18
|
+
interface ConfigDoneLike {
|
|
19
|
+
buildOutput?: 'static' | 'server';
|
|
20
|
+
injectTypes(injectedType: {
|
|
21
|
+
filename: string;
|
|
22
|
+
content: string;
|
|
23
|
+
}): URL;
|
|
24
|
+
}
|
|
25
|
+
interface BuildDoneLike {
|
|
26
|
+
dir: URL;
|
|
27
|
+
}
|
|
28
|
+
interface VerbalyAstroIntegration {
|
|
29
|
+
name: string;
|
|
30
|
+
hooks: {
|
|
31
|
+
'astro:config:setup'(options: ConfigSetupLike): void;
|
|
32
|
+
'astro:config:done'(options: ConfigDoneLike): Promise<void>;
|
|
33
|
+
'astro:build:done'(options: BuildDoneLike): Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
declare function verbaly(options?: VerbalyAstroOptions): VerbalyAstroIntegration;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { type RenderConfig, VerbalyAstroIntegration, VerbalyAstroOptions, type VerbalyConfig, type ViteVerbalyOptions, verbaly as default };
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { generateDts, loadCatalogs, loadConfig, renderSite } from "@verbaly/compiler";
|
|
2
|
+
import verbalyVite from "@verbaly/vite";
|
|
3
|
+
import { relative } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
function verbaly(options = {}) {
|
|
7
|
+
const { render, ...rest } = options;
|
|
8
|
+
const vite = typeof render === "object" ? {
|
|
9
|
+
...rest,
|
|
10
|
+
render
|
|
11
|
+
} : rest;
|
|
12
|
+
let root = "";
|
|
13
|
+
let buildOutput;
|
|
14
|
+
return {
|
|
15
|
+
name: "@verbaly/astro",
|
|
16
|
+
hooks: {
|
|
17
|
+
"astro:config:setup"({ config, updateConfig }) {
|
|
18
|
+
root = vite.root ??= fileURLToPath(config.root);
|
|
19
|
+
updateConfig({ vite: { plugins: [verbalyVite(vite)] } });
|
|
20
|
+
},
|
|
21
|
+
async "astro:config:done"(options) {
|
|
22
|
+
buildOutput = options.buildOutput;
|
|
23
|
+
const cfg = await loadConfig(root, vite);
|
|
24
|
+
const url = options.injectTypes({
|
|
25
|
+
filename: "verbaly.d.ts",
|
|
26
|
+
content: generateDts(loadCatalogs(cfg)[cfg.sourceLocale] ?? {})
|
|
27
|
+
});
|
|
28
|
+
vite.dts = fileURLToPath(url);
|
|
29
|
+
},
|
|
30
|
+
async "astro:build:done"({ dir }) {
|
|
31
|
+
const cfg = await loadConfig(root, vite);
|
|
32
|
+
if (!(render === void 0 ? Object.keys(cfg.render).length > 0 : Boolean(render))) return;
|
|
33
|
+
if (buildOutput === "server") {
|
|
34
|
+
console.warn("[verbaly] render skipped: only static output can be mirrored per locale (server-rendered pages already pick their locale per request)");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const result = await renderSite(cfg, { site: relative(cfg.root, fileURLToPath(dir)) || "." });
|
|
38
|
+
console.log(`[verbaly] render: ${result.files} pages × ${result.locales.length} locales (${result.locales.join(", ")})`);
|
|
39
|
+
for (const [locale, keys] of Object.entries(result.missing)) console.warn(` ${locale}: ${keys.length} keys not pre-filled: ${keys.join(", ")}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
export { verbaly as default };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n generateDts,\n loadCatalogs,\n loadConfig,\n renderSite,\n type RenderConfig,\n} from '@verbaly/compiler';\nimport verbalyVite, { type ViteVerbalyOptions } from '@verbaly/vite';\nimport { relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nexport type { RenderConfig, VerbalyConfig } from '@verbaly/compiler';\nexport type { ViteVerbalyOptions } from '@verbaly/vite';\n\n// render widens the config field: boolean toggles the post-build mirror, an object is both the opt-in and the config\nexport interface VerbalyAstroOptions extends Omit<ViteVerbalyOptions, 'render'> {\n render?: boolean | RenderConfig;\n}\n\n// structural subset of Astro's integration API: no runtime or type dependency on astro.\n// Method-style declarations on purpose: bivariance keeps them assignable to AstroIntegration.\ninterface AstroConfigLike {\n root: URL;\n}\n// plugins is `unknown`, not `unknown[]`: the type must stay a supertype of Astro's DeepPartial config\ninterface ConfigSetupLike {\n config: AstroConfigLike;\n updateConfig(config: { vite?: { plugins?: unknown } }): unknown;\n}\ninterface ConfigDoneLike {\n buildOutput?: 'static' | 'server';\n injectTypes(injectedType: { filename: string; content: string }): URL;\n}\ninterface BuildDoneLike {\n dir: URL;\n}\nexport interface VerbalyAstroIntegration {\n name: string;\n hooks: {\n 'astro:config:setup'(options: ConfigSetupLike): void;\n 'astro:config:done'(options: ConfigDoneLike): Promise<void>;\n 'astro:build:done'(options: BuildDoneLike): Promise<void>;\n };\n}\n\nexport default function verbaly(options: VerbalyAstroOptions = {}): VerbalyAstroIntegration {\n const { render, ...rest } = options;\n // one shared, mutable options object: config:done fills `dts` after the plugin\n // was created in config:setup, and the plugin reads it lazily at write time\n const vite: ViteVerbalyOptions = typeof render === 'object' ? { ...rest, render } : rest;\n let root = '';\n let buildOutput: 'static' | 'server' | undefined;\n\n return {\n name: '@verbaly/astro',\n hooks: {\n 'astro:config:setup'({ config, updateConfig }) {\n // root pinned to the project dir: Astro's Vite root can differ and config/catalog discovery would find nothing\n root = vite.root ??= fileURLToPath(config.root);\n updateConfig({ vite: { plugins: [verbalyVite(vite)] } });\n },\n async 'astro:config:done'(options) {\n buildOutput = options.buildOutput;\n // the generated types live in Astro's own slot (.astro/), no file in the project;\n // the vite plugin keeps that same file fresh as messages change in dev\n const cfg = await loadConfig(root, vite);\n const url = options.injectTypes({\n filename: 'verbaly.d.ts',\n content: generateDts(loadCatalogs(cfg)[cfg.sourceLocale] ?? {}),\n });\n vite.dts = fileURLToPath(url);\n },\n async 'astro:build:done'({ dir }) {\n const cfg = await loadConfig(root, vite);\n // mirror mode is opt-in: a `render` section in the config (or render: true) turns it on;\n // path-based i18n routing sites must never get their pages mirrored on top\n const wanted =\n render === undefined ? Object.keys(cfg.render).length > 0 : Boolean(render);\n if (!wanted) return;\n if (buildOutput === 'server') {\n console.warn(\n '[verbaly] render skipped: only static output can be mirrored per locale (server-rendered pages already pick their locale per request)',\n );\n return;\n }\n const site = relative(cfg.root, fileURLToPath(dir)) || '.';\n const result = await renderSite(cfg, { site });\n console.log(\n `[verbaly] render: ${result.files} pages × ${result.locales.length} locales (${result.locales.join(', ')})`,\n );\n for (const [locale, keys] of Object.entries(result.missing)) {\n console.warn(` ${locale}: ${keys.length} keys not pre-filled: ${keys.join(', ')}`);\n }\n },\n },\n };\n}\n"],"mappings":";;;;;AA6CA,SAAwB,QAAQ,UAA+B,CAAC,GAA4B;CAC1F,MAAM,EAAE,QAAQ,GAAG,SAAS;CAG5B,MAAM,OAA2B,OAAO,WAAW,WAAW;EAAE,GAAG;EAAM;CAAO,IAAI;CACpF,IAAI,OAAO;CACX,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,OAAO;GACL,qBAAqB,EAAE,QAAQ,gBAAgB;IAE7C,OAAO,KAAK,SAAS,cAAc,OAAO,IAAI;IAC9C,aAAa,EAAE,MAAM,EAAE,SAAS,CAAC,YAAY,IAAI,CAAC,EAAE,EAAE,CAAC;GACzD;GACA,MAAM,oBAAoB,SAAS;IACjC,cAAc,QAAQ;IAGtB,MAAM,MAAM,MAAM,WAAW,MAAM,IAAI;IACvC,MAAM,MAAM,QAAQ,YAAY;KAC9B,UAAU;KACV,SAAS,YAAY,aAAa,GAAG,CAAC,CAAC,IAAI,iBAAiB,CAAC,CAAC;IAChE,CAAC;IACD,KAAK,MAAM,cAAc,GAAG;GAC9B;GACA,MAAM,mBAAmB,EAAE,OAAO;IAChC,MAAM,MAAM,MAAM,WAAW,MAAM,IAAI;IAKvC,IAAI,EADF,WAAW,KAAA,IAAY,OAAO,KAAK,IAAI,MAAM,CAAC,CAAC,SAAS,IAAI,QAAQ,MAAM,IAC/D;IACb,IAAI,gBAAgB,UAAU;KAC5B,QAAQ,KACN,uIACF;KACA;IACF;IAEA,MAAM,SAAS,MAAM,WAAW,KAAK,EAAE,MAD1B,SAAS,IAAI,MAAM,cAAc,GAAG,CAAC,KAAK,IACX,CAAC;IAC7C,QAAQ,IACN,qBAAqB,OAAO,MAAM,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,QAAQ,KAAK,IAAI,EAAE,EAC3G;IACA,KAAK,MAAM,CAAC,QAAQ,SAAS,OAAO,QAAQ,OAAO,OAAO,GACxD,QAAQ,KAAK,KAAK,OAAO,IAAI,KAAK,OAAO,wBAAwB,KAAK,KAAK,IAAI,GAAG;GAEtF;EACF;CACF;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@verbaly/astro",
|
|
3
|
+
"version": "0.26.0",
|
|
4
|
+
"description": "Astro integration for Verbaly: write-in-source extraction for .astro files plus automatic per-locale static rendering.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"i18n",
|
|
7
|
+
"astro",
|
|
8
|
+
"astro-integration",
|
|
9
|
+
"withastro",
|
|
10
|
+
"ssg",
|
|
11
|
+
"verbaly"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Aron Soto",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/AronSoto/verbaly.git",
|
|
18
|
+
"directory": "packages/astro"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://verbaly-web.vercel.app/docs/frameworks/astro",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/AronSoto/verbaly/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=20"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@verbaly/compiler": "^0.26.0",
|
|
45
|
+
"@verbaly/vite": "^0.26.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"verbaly": "^0.26.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"astro": "^7.1.1",
|
|
52
|
+
"verbaly": "0.26.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsdown",
|
|
56
|
+
"dev": "tsdown --watch",
|
|
57
|
+
"test": "vitest run --passWithNoTests",
|
|
58
|
+
"typecheck": "tsc --noEmit"
|
|
59
|
+
}
|
|
60
|
+
}
|