@i18n-micro/astro 1.3.1 → 1.3.2
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/dist/client/core.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/preact.js +1 -1
- package/dist/client/react.js +1 -1
- package/dist/client/svelte.js +1 -1
- package/dist/client/vue.js +1 -1
- package/dist/core-B-Ia_nzr.cjs +1 -0
- package/dist/core-Bk6qZuDf.js +37 -0
- package/package.json +3 -3
- package/src/client/core.ts +2 -22
- package/src/load-translations.ts +0 -1
- package/dist/core-Bx9n-eFD.cjs +0 -1
- package/dist/core-D32Y48CN.js +0 -42
package/dist/client/core.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface I18nState {
|
|
|
12
12
|
* Pure function to get a translation from state
|
|
13
13
|
*
|
|
14
14
|
* Note: This is a simplified version optimized for client-side islands.
|
|
15
|
-
* It supports basic translation lookup
|
|
15
|
+
* It supports basic translation lookup and interpolation.
|
|
16
16
|
* Returns CleanTranslation which can be string, number, boolean, object, or null.
|
|
17
17
|
* For advanced features like Linked Messages (@:path.to.key), use the server-side i18n instance.
|
|
18
18
|
*/
|
package/dist/client/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as s, t as o } from "../core-
|
|
1
|
+
import { h as s, t as o } from "../core-Bk6qZuDf.js";
|
|
2
2
|
import { I18nProvider as a, useAstroI18n as n } from "./preact.js";
|
|
3
3
|
import { I18nProvider as u, useAstroI18n as A } from "./react.js";
|
|
4
4
|
import { createI18nStore as f, useAstroI18n as i } from "./svelte.js";
|
package/dist/client/preact.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FormatService as g, defaultPlural as w } from "@i18n-micro/core";
|
|
2
2
|
import { createContext as x, createElement as L } from "preact";
|
|
3
3
|
import { useState as P, useContext as S, useMemo as a } from "preact/hooks";
|
|
4
|
-
import { t as C, h as A } from "../core-
|
|
4
|
+
import { t as C, h as A } from "../core-Bk6qZuDf.js";
|
|
5
5
|
const s = new g(), i = x(null), F = ({ children: t, value: o }) => {
|
|
6
6
|
const [l] = P(() => ({
|
|
7
7
|
locale: o.locale,
|
package/dist/client/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormatService as g, defaultPlural as w } from "@i18n-micro/core";
|
|
2
2
|
import x, { createContext as L, useState as P, useContext as S, useMemo as a } from "react";
|
|
3
|
-
import { t as C, h as A } from "../core-
|
|
3
|
+
import { t as C, h as A } from "../core-Bk6qZuDf.js";
|
|
4
4
|
const s = new g(), i = L(null);
|
|
5
5
|
function D({ children: t, value: o }) {
|
|
6
6
|
const [l] = P(() => ({
|
package/dist/client/svelte.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormatService as R, defaultPlural as b } from "@i18n-micro/core";
|
|
2
2
|
import { writable as d, get as v } from "svelte/store";
|
|
3
|
-
import { h as L, t as S } from "../core-
|
|
3
|
+
import { h as L, t as S } from "../core-Bk6qZuDf.js";
|
|
4
4
|
const l = new R();
|
|
5
5
|
function F(o) {
|
|
6
6
|
return d({
|
package/dist/client/vue.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormatService as wt, defaultPlural as yt } from "@i18n-micro/core";
|
|
2
|
-
import { h as St, t as Ot } from "../core-
|
|
2
|
+
import { h as St, t as Ot } from "../core-Bk6qZuDf.js";
|
|
3
3
|
// @__NO_SIDE_EFFECTS__
|
|
4
4
|
function Rt(e) {
|
|
5
5
|
const t = /* @__PURE__ */ Object.create(null);
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/astro",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@i18n-micro/core": "1.2.0",
|
|
55
|
-
"@i18n-micro/
|
|
56
|
-
"@i18n-micro/
|
|
55
|
+
"@i18n-micro/types": "1.1.6",
|
|
56
|
+
"@i18n-micro/node": "1.2.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"astro": "^5.16.5",
|
package/src/client/core.ts
CHANGED
|
@@ -44,7 +44,7 @@ function findTranslation<T = unknown>(translations: Translations | null, key: st
|
|
|
44
44
|
* Pure function to get a translation from state
|
|
45
45
|
*
|
|
46
46
|
* Note: This is a simplified version optimized for client-side islands.
|
|
47
|
-
* It supports basic translation lookup
|
|
47
|
+
* It supports basic translation lookup and interpolation.
|
|
48
48
|
* Returns CleanTranslation which can be string, number, boolean, object, or null.
|
|
49
49
|
* For advanced features like Linked Messages (@:path.to.key), use the server-side i18n instance.
|
|
50
50
|
*/
|
|
@@ -62,28 +62,18 @@ export function translate(
|
|
|
62
62
|
const route = routeName || state.currentRoute
|
|
63
63
|
let value: string | number | boolean | Translations | null = null
|
|
64
64
|
|
|
65
|
-
// 1. Look in route-specific translations
|
|
66
65
|
if (state.translations[route]) {
|
|
67
66
|
value = findTranslation<string | number | boolean | Translations>(state.translations[route], key)
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
//
|
|
71
|
-
if (!value && state.translations.general) {
|
|
72
|
-
value = findTranslation<string | number | boolean | Translations>(state.translations.general, key)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 3. If not found, use defaultValue or key
|
|
69
|
+
// If not found, use defaultValue or key
|
|
76
70
|
if (!value) {
|
|
77
71
|
value = defaultValue === undefined ? key : defaultValue || key
|
|
78
72
|
}
|
|
79
73
|
|
|
80
|
-
// 4. Parameter interpolation (strings only)
|
|
81
74
|
if (typeof value === 'string' && params) {
|
|
82
75
|
return interpolate(value, params)
|
|
83
76
|
}
|
|
84
|
-
|
|
85
|
-
// 5. Return value as-is (can be string, number, boolean, object, or null)
|
|
86
|
-
// This matches the CleanTranslation type
|
|
87
77
|
return value
|
|
88
78
|
}
|
|
89
79
|
|
|
@@ -93,9 +83,7 @@ export function translate(
|
|
|
93
83
|
export function hasTranslation(state: I18nState, key: string, routeName?: string): boolean {
|
|
94
84
|
const route = routeName || state.currentRoute
|
|
95
85
|
const routeTranslations = state.translations[route]
|
|
96
|
-
const generalTranslations = state.translations.general
|
|
97
86
|
|
|
98
|
-
// Check in route-specific translations
|
|
99
87
|
if (routeTranslations) {
|
|
100
88
|
const value = findTranslation(routeTranslations, key)
|
|
101
89
|
if (value !== null && typeof value !== 'object') {
|
|
@@ -103,13 +91,5 @@ export function hasTranslation(state: I18nState, key: string, routeName?: string
|
|
|
103
91
|
}
|
|
104
92
|
}
|
|
105
93
|
|
|
106
|
-
// Check in general translations
|
|
107
|
-
if (generalTranslations) {
|
|
108
|
-
const value = findTranslation(generalTranslations, key)
|
|
109
|
-
if (value !== null && typeof value !== 'object') {
|
|
110
|
-
return true
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
94
|
return false
|
|
115
95
|
}
|
package/src/load-translations.ts
CHANGED
|
@@ -65,7 +65,6 @@ export function loadTranslationsFromDir(options: LoadTranslationsOptions): Loade
|
|
|
65
65
|
if (entry === 'pages' && !disablePageLocales) {
|
|
66
66
|
loadFiles(fullPath, '')
|
|
67
67
|
} else if (routePrefix || disablePageLocales) {
|
|
68
|
-
// Continue in general translations
|
|
69
68
|
loadFiles(fullPath, routePrefix)
|
|
70
69
|
} else {
|
|
71
70
|
// This is a route directory (e.g., pages/home/)
|
package/dist/core-Bx9n-eFD.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const s=require("@i18n-micro/core");function u(n,t){if(n===null||typeof t!="string")return null;let o=n;if(n[t])o=n[t];else{const l=t.toString().split(".");for(const e of l)if(o&&typeof o=="object"&&o!==null&&e in o)o=o[e];else return null}return o??null}function a(n,t,o,l,e){if(!t)return l||t||"";const i=e||n.currentRoute;let r=null;return n.translations[i]&&(r=u(n.translations[i],t)),!r&&n.translations.general&&(r=u(n.translations.general,t)),r||(r=l===void 0?t:l||t),typeof r=="string"&&o?s.interpolate(r,o):r}function f(n,t,o){const l=o||n.currentRoute,e=n.translations[l],i=n.translations.general;if(e){const r=u(e,t);if(r!==null&&typeof r!="object")return!0}if(i){const r=u(i,t);if(r!==null&&typeof r!="object")return!0}return!1}exports.hasTranslation=f;exports.translate=a;
|
package/dist/core-D32Y48CN.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { interpolate as s } from "@i18n-micro/core";
|
|
2
|
-
function u(n, t) {
|
|
3
|
-
if (n === null || typeof t != "string")
|
|
4
|
-
return null;
|
|
5
|
-
let o = n;
|
|
6
|
-
if (n[t])
|
|
7
|
-
o = n[t];
|
|
8
|
-
else {
|
|
9
|
-
const l = t.toString().split(".");
|
|
10
|
-
for (const i of l)
|
|
11
|
-
if (o && typeof o == "object" && o !== null && i in o)
|
|
12
|
-
o = o[i];
|
|
13
|
-
else
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
return o ?? null;
|
|
17
|
-
}
|
|
18
|
-
function a(n, t, o, l, i) {
|
|
19
|
-
if (!t)
|
|
20
|
-
return l || t || "";
|
|
21
|
-
const e = i || n.currentRoute;
|
|
22
|
-
let r = null;
|
|
23
|
-
return n.translations[e] && (r = u(n.translations[e], t)), !r && n.translations.general && (r = u(n.translations.general, t)), r || (r = l === void 0 ? t : l || t), typeof r == "string" && o ? s(r, o) : r;
|
|
24
|
-
}
|
|
25
|
-
function c(n, t, o) {
|
|
26
|
-
const l = o || n.currentRoute, i = n.translations[l], e = n.translations.general;
|
|
27
|
-
if (i) {
|
|
28
|
-
const r = u(i, t);
|
|
29
|
-
if (r !== null && typeof r != "object")
|
|
30
|
-
return !0;
|
|
31
|
-
}
|
|
32
|
-
if (e) {
|
|
33
|
-
const r = u(e, t);
|
|
34
|
-
if (r !== null && typeof r != "object")
|
|
35
|
-
return !0;
|
|
36
|
-
}
|
|
37
|
-
return !1;
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
c as h,
|
|
41
|
-
a as t
|
|
42
|
-
};
|