@i18n-micro/astro 1.3.12 → 1.3.18
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 +17 -0
- package/dist/astro-shim.d.ts +0 -0
- package/dist/client/index.js +6 -17
- package/dist/client/preact.js +35 -64
- package/dist/client/react.js +35 -64
- package/dist/client/svelte.js +60 -62
- package/dist/client/vue.js +2 -1552
- package/dist/core-DwkpOV-H.cjs +1 -0
- package/dist/core-VSnkGRWR.js +28 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +499 -552
- package/dist/utils.d.ts +9 -0
- package/dist/vue-BVFyDsja.cjs +5 -0
- package/dist/vue-CyIbewNw.js +1723 -0
- package/package.json +15 -12
- package/src/astro-shim.d.ts +1 -0
- package/src/index.ts +11 -1
- package/src/utils.ts +29 -0
- package/dist/core-B-Ia_nzr.cjs +0 -1
- package/dist/core-Bk6qZuDf.js +0 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/astro",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.18",
|
|
4
4
|
"description": "Astro integration for i18n-micro — translations, routing, and islands.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"./env": {
|
|
44
44
|
"types": "./dist/env.d.ts"
|
|
45
45
|
},
|
|
46
|
+
"./astro-shim": {
|
|
47
|
+
"types": "./dist/env.d.ts"
|
|
48
|
+
},
|
|
46
49
|
"./components/i18n-t.astro": "./src/components/i18n-t.astro",
|
|
47
50
|
"./components/i18n-link.astro": "./src/components/i18n-link.astro",
|
|
48
51
|
"./components/i18n-switcher.astro": "./src/components/i18n-switcher.astro",
|
|
@@ -77,28 +80,28 @@
|
|
|
77
80
|
"access": "public"
|
|
78
81
|
},
|
|
79
82
|
"dependencies": {
|
|
80
|
-
"@i18n-micro/
|
|
81
|
-
"@i18n-micro/
|
|
82
|
-
"@i18n-micro/
|
|
83
|
-
"@i18n-micro/utils": "^1.0.
|
|
83
|
+
"@i18n-micro/node": "^1.2.14",
|
|
84
|
+
"@i18n-micro/core": "^1.3.16",
|
|
85
|
+
"@i18n-micro/types": "^1.2.13",
|
|
86
|
+
"@i18n-micro/utils": "^1.0.21"
|
|
84
87
|
},
|
|
85
88
|
"devDependencies": {
|
|
86
89
|
"astro": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
87
90
|
"preact": "^10.0.0",
|
|
88
|
-
"publint": "^0.3.
|
|
91
|
+
"publint": "^0.3.24",
|
|
89
92
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
90
93
|
"svelte": "^4.0.0 || ^5.0.0",
|
|
91
|
-
"vite": "^
|
|
92
|
-
"vite-plugin-dts": "^
|
|
93
|
-
"vitest": "^4.1.
|
|
94
|
-
"vue": "^3.5.
|
|
94
|
+
"vite": "^8.2.2",
|
|
95
|
+
"vite-plugin-dts": "^5.1.0",
|
|
96
|
+
"vitest": "^4.1.11",
|
|
97
|
+
"vue": "^3.5.42"
|
|
95
98
|
},
|
|
96
99
|
"peerDependencies": {
|
|
97
100
|
"astro": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
98
101
|
"preact": "^10.0.0",
|
|
99
102
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
100
103
|
"svelte": "^4.0.0 || ^5.0.0",
|
|
101
|
-
"vue": "^3.5.
|
|
104
|
+
"vue": "^3.5.42"
|
|
102
105
|
},
|
|
103
106
|
"peerDependenciesMeta": {
|
|
104
107
|
"svelte": {
|
|
@@ -123,6 +126,6 @@
|
|
|
123
126
|
"dev": "cd playground && astro dev",
|
|
124
127
|
"test": "vitest run",
|
|
125
128
|
"test:dist": "vitest run --config vitest.dist.config.ts",
|
|
126
|
-
"typecheck": "tsc --noEmit"
|
|
129
|
+
"typecheck": "tsc --noEmit && pnpm --dir playground typecheck"
|
|
127
130
|
}
|
|
128
131
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './env'
|
package/src/index.ts
CHANGED
|
@@ -20,5 +20,15 @@ export { createAstroRouterAdapter } from './router/adapter'
|
|
|
20
20
|
export type { I18nRoutingStrategy } from './router/types'
|
|
21
21
|
export type { I18nClientProps, LocaleHeadOptions, LocaleHeadResult } from './utils'
|
|
22
22
|
// Utilities
|
|
23
|
-
export {
|
|
23
|
+
export {
|
|
24
|
+
getDefaultLocale,
|
|
25
|
+
getI18n,
|
|
26
|
+
getI18nProps,
|
|
27
|
+
getLocale,
|
|
28
|
+
getLocaleRewritePath,
|
|
29
|
+
getLocales,
|
|
30
|
+
prepareLocaleRewrite,
|
|
31
|
+
useI18n,
|
|
32
|
+
useLocaleHead,
|
|
33
|
+
} from './utils'
|
|
24
34
|
// It's loaded directly by Astro via entrypoint in integration config
|
package/src/utils.ts
CHANGED
|
@@ -181,6 +181,35 @@ export function useI18n(astro: AstroGlobal) {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Strip locale prefix from the current URL for `Astro.rewrite()` on `/[locale]/*` routes.
|
|
186
|
+
*/
|
|
187
|
+
export function getLocaleRewritePath(astro: AstroGlobal): string {
|
|
188
|
+
const url = astro.locals.currentUrl ?? astro.url
|
|
189
|
+
return useI18n(astro).getBasePath(url)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Validate `:locale`, sync i18n/locals, and return the base path for `Astro.rewrite()`.
|
|
194
|
+
* Returns a `Response` when the locale param is invalid.
|
|
195
|
+
*/
|
|
196
|
+
export function prepareLocaleRewrite(astro: AstroGlobal): Response | string {
|
|
197
|
+
const { locale } = astro.params
|
|
198
|
+
const localeCodes = getLocales(astro).map((entry) => entry.code)
|
|
199
|
+
|
|
200
|
+
if (!locale || !localeCodes.includes(locale)) {
|
|
201
|
+
return new Response(null, { status: 404 })
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const i18n = astro.locals.i18n
|
|
205
|
+
if (i18n) {
|
|
206
|
+
i18n.locale = locale
|
|
207
|
+
astro.locals.locale = locale
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return getLocaleRewritePath(astro)
|
|
211
|
+
}
|
|
212
|
+
|
|
184
213
|
/**
|
|
185
214
|
* Generate locale head meta tags for SEO
|
|
186
215
|
*/
|
package/dist/core-B-Ia_nzr.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const s=require("@i18n-micro/core");function l(r,t){if(r===null||typeof t!="string")return null;let n=r;if(r[t])n=r[t];else{const o=t.toString().split(".");for(const u of o)if(n&&typeof n=="object"&&n!==null&&u in n)n=n[u];else return null}return n??null}function f(r,t,n,o,u){if(!t)return o||t||"";const i=u||r.currentRoute;let e=null;return r.translations[i]&&(e=l(r.translations[i],t)),e||(e=o===void 0?t:o||t),typeof e=="string"&&n?s.interpolate(e,n):e}function c(r,t,n){const o=n||r.currentRoute,u=r.translations[o];if(u){const i=l(u,t);if(i!==null&&typeof i!="object")return!0}return!1}exports.hasTranslation=c;exports.translate=f;
|
package/dist/core-Bk6qZuDf.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { interpolate as f } from "@i18n-micro/core";
|
|
2
|
-
function e(r, t) {
|
|
3
|
-
if (r === null || typeof t != "string")
|
|
4
|
-
return null;
|
|
5
|
-
let n = r;
|
|
6
|
-
if (r[t])
|
|
7
|
-
n = r[t];
|
|
8
|
-
else {
|
|
9
|
-
const o = t.toString().split(".");
|
|
10
|
-
for (const u of o)
|
|
11
|
-
if (n && typeof n == "object" && n !== null && u in n)
|
|
12
|
-
n = n[u];
|
|
13
|
-
else
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
return n ?? null;
|
|
17
|
-
}
|
|
18
|
-
function c(r, t, n, o, u) {
|
|
19
|
-
if (!t)
|
|
20
|
-
return o || t || "";
|
|
21
|
-
const l = u || r.currentRoute;
|
|
22
|
-
let i = null;
|
|
23
|
-
return r.translations[l] && (i = e(r.translations[l], t)), i || (i = o === void 0 ? t : o || t), typeof i == "string" && n ? f(i, n) : i;
|
|
24
|
-
}
|
|
25
|
-
function a(r, t, n) {
|
|
26
|
-
const o = n || r.currentRoute, u = r.translations[o];
|
|
27
|
-
if (u) {
|
|
28
|
-
const l = e(u, t);
|
|
29
|
-
if (l !== null && typeof l != "object")
|
|
30
|
-
return !0;
|
|
31
|
-
}
|
|
32
|
-
return !1;
|
|
33
|
-
}
|
|
34
|
-
export {
|
|
35
|
-
a as h,
|
|
36
|
-
c as t
|
|
37
|
-
};
|