@verbaly/astro 0.79.0 → 0.81.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 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +15 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -45,6 +45,11 @@ export default { sourceLocale: 'en', locales: ['en', 'es', 'pt'] };
|
|
|
45
45
|
|
|
46
46
|
```astro
|
|
47
47
|
---
|
|
48
|
+
import { createRequestInstance, sourceLocale } from 'verbaly/app';
|
|
49
|
+
|
|
50
|
+
const { t } = await createRequestInstance(Astro.currentLocale ?? sourceLocale);
|
|
51
|
+
const name = 'Ada';
|
|
52
|
+
const count = 3;
|
|
48
53
|
const title = t`Search and find`;
|
|
49
54
|
---
|
|
50
55
|
|
|
@@ -70,6 +75,24 @@ const { t } = await createRequestInstance(Astro.currentLocale ?? sourceLocale);
|
|
|
70
75
|
translated instead of flashing. `Astro.currentLocale` is `undefined` outside a localized route, so
|
|
71
76
|
the fallback is not decoration.
|
|
72
77
|
|
|
78
|
+
The integration reads Astro's `i18n` too, so `switchLocale` and `localePath` from `verbaly/app`
|
|
79
|
+
go to the page Astro serves in the other language: `prefix-except-source` by default, or
|
|
80
|
+
`prefix-all` with `prefixDefaultLocale: true`. That needs Astro's `defaultLocale` to be your
|
|
81
|
+
`sourceLocale`, and each language's path to be its code; the dev server and the build say so
|
|
82
|
+
when it is not. A prefix mode your `verbaly.config` names stays as it is, and `npx verbaly doctor`
|
|
83
|
+
shows the mode in use.
|
|
84
|
+
|
|
85
|
+
```astro
|
|
86
|
+
<button data-lang="es">Español</button>
|
|
87
|
+
<script>
|
|
88
|
+
import { switchLocale } from 'verbaly/app';
|
|
89
|
+
|
|
90
|
+
for (const button of document.querySelectorAll<HTMLButtonElement>('[data-lang]')) {
|
|
91
|
+
button.addEventListener('click', () => switchLocale(button.dataset.lang!)); // goes to /es/…
|
|
92
|
+
}
|
|
93
|
+
</script>
|
|
94
|
+
```
|
|
95
|
+
|
|
73
96
|
**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.
|
|
74
97
|
|
|
75
98
|
```js
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,20 @@ import { ViteVerbalyOptions, ViteVerbalyOptions as ViteVerbalyOptions$1 } from "
|
|
|
3
3
|
export interface VerbalyAstroOptions extends Omit<ViteVerbalyOptions$1, 'render'> {
|
|
4
4
|
render?: boolean | RenderConfig$1;
|
|
5
5
|
}
|
|
6
|
+
interface AstroI18nLike {
|
|
7
|
+
defaultLocale: string;
|
|
8
|
+
locales: (string | {
|
|
9
|
+
path: string;
|
|
10
|
+
codes: string[];
|
|
11
|
+
})[];
|
|
12
|
+
routing?: 'manual' | {
|
|
13
|
+
prefixDefaultLocale?: boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
6
16
|
interface AstroConfigLike {
|
|
7
17
|
root: URL;
|
|
8
18
|
trailingSlash?: 'always' | 'never' | 'ignore';
|
|
19
|
+
i18n?: AstroI18nLike;
|
|
9
20
|
}
|
|
10
21
|
interface ConfigSetupLike {
|
|
11
22
|
config: AstroConfigLike;
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,17 @@ import verbalyVite from "@verbaly/vite";
|
|
|
3
3
|
import { relative } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
// src/index.ts
|
|
6
|
+
function routingFromAstro(i18n, source) {
|
|
7
|
+
if (!i18n || i18n.routing === "manual") return void 0;
|
|
8
|
+
const custom = i18n.locales.find((entry) => typeof entry !== "string" && !entry.codes.includes(entry.path));
|
|
9
|
+
if (typeof custom === "object") {
|
|
10
|
+
console.warn(`[verbaly] Astro's i18n serves ${custom.codes.join(", ")} under /${custom.path}, a path no Verbaly url can follow, so switchLocale and localePath keep one address: use the language code as its path`);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (i18n.routing?.prefixDefaultLocale) return "prefix-all";
|
|
14
|
+
if (i18n.defaultLocale === source) return "prefix-except-source";
|
|
15
|
+
console.warn(`[verbaly] Astro's i18n serves its defaultLocale "${i18n.defaultLocale}" at the root, but Verbaly's sourceLocale "${source}" is the language without a prefix, so switchLocale and localePath keep one address: make them the same language, or set prefixDefaultLocale: true`);
|
|
16
|
+
}
|
|
6
17
|
function verbaly(options = {}) {
|
|
7
18
|
const { render, ...rest } = options;
|
|
8
19
|
const vite = typeof render === "object" ? {
|
|
@@ -17,6 +28,10 @@ function verbaly(options = {}) {
|
|
|
17
28
|
async "astro:config:setup"({ config, updateConfig }) {
|
|
18
29
|
root = vite.root ??= fileURLToPath(config.root);
|
|
19
30
|
vite.trailingSlash ??= config.trailingSlash;
|
|
31
|
+
if (vite.routing === void 0 && config.i18n) {
|
|
32
|
+
const cfg = await loadConfig(root, vite, { plugin: true });
|
|
33
|
+
if (cfg.routing === "no-prefix") vite.routing = routingFromAstro(config.i18n, cfg.sourceLocale);
|
|
34
|
+
}
|
|
20
35
|
updateConfig({ vite: { plugins: [verbalyVite(vite)] } });
|
|
21
36
|
},
|
|
22
37
|
async "astro:config:done"(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbaly/astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.81.0",
|
|
4
4
|
"description": "Astro integration for Verbaly: write-in-source extraction for .astro files plus automatic per-locale static rendering.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -45,15 +45,15 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@verbaly/compiler": "^0.
|
|
49
|
-
"@verbaly/vite": "^0.
|
|
48
|
+
"@verbaly/compiler": "^0.81.0",
|
|
49
|
+
"@verbaly/vite": "^0.81.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"verbaly": "^0.
|
|
52
|
+
"verbaly": "^0.81.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"astro": "^7.4.
|
|
56
|
-
"verbaly": "^0.
|
|
55
|
+
"astro": "^7.4.7",
|
|
56
|
+
"verbaly": "^0.81.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsdown",
|