@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/astro",
3
- "version": "1.3.12",
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/core": "^1.3.14",
81
- "@i18n-micro/types": "^1.2.11",
82
- "@i18n-micro/node": "^1.2.8",
83
- "@i18n-micro/utils": "^1.0.14"
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.17",
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": "^7.3.6",
92
- "vite-plugin-dts": "^4.5.4",
93
- "vitest": "^4.1.10",
94
- "vue": "^3.5.25"
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.25"
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 { getDefaultLocale, getI18n, getI18nProps, getLocale, getLocales, useI18n, useLocaleHead } from './utils'
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
  */
@@ -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;
@@ -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
- };