@nerimity/solid-i18lite 1.5.0 → 1.5.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/i18lite.mjs +66 -0
- package/dist/index.mjs +81 -0
- package/package.json +28 -7
- package/dist/browser.mjs +0 -142
- package/dist/ssr.js +0 -1
- package/dist/ssr.mjs +0 -142
package/dist/i18lite.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
let h = {}, S = "translation", d = "";
|
|
2
|
+
const A = { resources: {}, interpolation: { prefix: "{{", suffix: "}}" } };
|
|
3
|
+
let c = A;
|
|
4
|
+
const R = (e) => e.replace(/[-|\\{}()[\]^$+*?.]/g, (t) => t === "-" ? "\\x2d" : `\\${t}`), v = /* @__PURE__ */ new Map(), $ = (e, t) => {
|
|
5
|
+
if (!e) return "";
|
|
6
|
+
const o = c?.interpolation, s = o?.prefix ?? "{{", a = o?.suffix ?? "}}", i = s + "|" + a;
|
|
7
|
+
let r = v.get(i);
|
|
8
|
+
if (!r) {
|
|
9
|
+
const f = R(s), u = R(a);
|
|
10
|
+
r = new RegExp(`${f}\\s*(\\w+)\\s*${u}`, "g"), v.set(i, r);
|
|
11
|
+
}
|
|
12
|
+
return e.replace(r, (f, u) => Object.prototype.hasOwnProperty.call(t, u) ? t[u] : f);
|
|
13
|
+
}, g = (e, t, o) => {
|
|
14
|
+
let s = j(n.language, S, e) ?? (typeof t == "string" ? t : e);
|
|
15
|
+
return o || typeof t == "object" && t !== null ? $(s, o || t) : s;
|
|
16
|
+
}, P = (e, t) => {
|
|
17
|
+
h[e] = t;
|
|
18
|
+
}, L = (e, t) => {
|
|
19
|
+
c = A, e && (c = { ...e, interpolation: e?.interpolation || {} }, c.interpolation.prefix = e.interpolation?.prefix || "{{", c.interpolation.suffix = e.interpolation?.suffix || "}}"), d = e?.lng || "", n.store = { data: c.resources || {} }, c.resources = {}, t?.(null, g);
|
|
20
|
+
}, M = (e) => (d = e, Promise.resolve(g)), b = (e, t, o = !0) => {
|
|
21
|
+
const s = e;
|
|
22
|
+
for (const a in t) {
|
|
23
|
+
const i = s[a], r = t[a];
|
|
24
|
+
r && typeof r == "object" && !Array.isArray(r) ? ((typeof i != "object" || Array.isArray(i)) && (s[a] = {}), b(s[a], r, o)) : (o || i === void 0) && (s[a] = r);
|
|
25
|
+
}
|
|
26
|
+
return e;
|
|
27
|
+
}, V = (e, t, o, s = !0, a = !0) => {
|
|
28
|
+
n.store = n.store || { data: {} }, n.store.data = n.store.data || {}, n.store.data[e] = n.store.data[e] || {}, n.store.data[e][t] = n.store.data[e][t] || {};
|
|
29
|
+
const i = n.store.data[e][t], r = o;
|
|
30
|
+
return s ? b(i, r, a) : n.store.data[e][t] = a ? r : { ...r, ...i }, (h.loaded || (() => {
|
|
31
|
+
}))(e, t), n;
|
|
32
|
+
}, j = (e, t, o, s) => {
|
|
33
|
+
const a = n.store;
|
|
34
|
+
if (!a) return;
|
|
35
|
+
const i = a.data?.[e];
|
|
36
|
+
if (!i) return;
|
|
37
|
+
const r = i[t];
|
|
38
|
+
if (!r || typeof r == "string") return;
|
|
39
|
+
const f = s?.keySeparator ?? n.options?.keySeparator ?? ".";
|
|
40
|
+
if (f === !1) return r[o];
|
|
41
|
+
const u = String(f);
|
|
42
|
+
if (o.indexOf(u) === -1) return r[o];
|
|
43
|
+
let p = r, x = 0;
|
|
44
|
+
for (let l = 0; l <= o.length; l++)
|
|
45
|
+
if (l === o.length || o[l] === u) {
|
|
46
|
+
const y = o.slice(x, l);
|
|
47
|
+
if (p == null || !(y in p)) return;
|
|
48
|
+
p = p[y], x = l + 1;
|
|
49
|
+
}
|
|
50
|
+
return p;
|
|
51
|
+
}, B = () => n, n = {
|
|
52
|
+
get language() {
|
|
53
|
+
return d;
|
|
54
|
+
},
|
|
55
|
+
createInstance: B,
|
|
56
|
+
t: g,
|
|
57
|
+
on: P,
|
|
58
|
+
init: L,
|
|
59
|
+
changeLanguage: M,
|
|
60
|
+
addResourceBundle: V,
|
|
61
|
+
options: c,
|
|
62
|
+
getResource: j
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
n as default
|
|
66
|
+
};
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createComponent as f, memo as d } from "solid-js/web";
|
|
2
|
+
import { useContext as m, createContext as y, createSignal as x, children as C } from "solid-js";
|
|
3
|
+
import T from "./i18lite.mjs";
|
|
4
|
+
const g = y();
|
|
5
|
+
function w(t, r) {
|
|
6
|
+
const [n, e] = x(r.resources ? t.t : () => null);
|
|
7
|
+
t.on("loaded", () => e(() => t.t)), t.init(r, (a, i) => e(() => i));
|
|
8
|
+
async function c(a) {
|
|
9
|
+
const i = await t.changeLanguage(a);
|
|
10
|
+
e(() => i);
|
|
11
|
+
}
|
|
12
|
+
function o(a, i, h, u = {}) {
|
|
13
|
+
return t.addResourceBundle(a, i, h, u.deep, u.overwrite);
|
|
14
|
+
}
|
|
15
|
+
return [((...a) => n().apply(null, a)), {
|
|
16
|
+
addResources: o,
|
|
17
|
+
getI18next: () => t,
|
|
18
|
+
changeLanguage: c
|
|
19
|
+
}];
|
|
20
|
+
}
|
|
21
|
+
const I = () => m(g), N = (t) => f(g.Provider, {
|
|
22
|
+
get value() {
|
|
23
|
+
return w(t.instance || T, {
|
|
24
|
+
lng: t.lng,
|
|
25
|
+
...t.options
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
get children() {
|
|
29
|
+
return t.children;
|
|
30
|
+
}
|
|
31
|
+
}), s = (t, { prefix: r, suffix: n }) => t.includes(r) && t.includes(n), S = (t, { interpolation: r }) => (n, e) => typeof n == "string" ? s(n, r) ? t.children[e].children?.[0].content : t.children[e].content : (n.textContent = t.children[e].children?.[0].content, n), k = !globalThis.window, v = (t, r, n) => (e) => {
|
|
32
|
+
const c = typeof e;
|
|
33
|
+
if (c === "string" && s(e, r.interpolation)) return t(e, n.options);
|
|
34
|
+
if (c === "object") {
|
|
35
|
+
const o = e.textContent ?? e.t;
|
|
36
|
+
o && s(o, r.interpolation) && (e[k ? "t" : "textContent"] = t(o, n.options));
|
|
37
|
+
}
|
|
38
|
+
return e;
|
|
39
|
+
};
|
|
40
|
+
let l;
|
|
41
|
+
(async () => {
|
|
42
|
+
try {
|
|
43
|
+
l = (await import("html-parse-string")).parse;
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
})();
|
|
47
|
+
const L = () => {
|
|
48
|
+
console.error(
|
|
49
|
+
"In order to use JSX nesting, install %chtml-parse-string",
|
|
50
|
+
"font-weight: 700",
|
|
51
|
+
"https://github.com/ryansolid/html-parse-string."
|
|
52
|
+
);
|
|
53
|
+
}, P = ({ i18n: { options: t }, t: r, props: n }, e) => {
|
|
54
|
+
const c = r(n.key, n.options);
|
|
55
|
+
if (!n.children) return c;
|
|
56
|
+
if (c === n.key) return e.map(v(r, t, n));
|
|
57
|
+
if (!l) {
|
|
58
|
+
L();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const [o] = l(`<0>${c}</0>`);
|
|
63
|
+
return e.map(S(o, t));
|
|
64
|
+
} catch (o) {
|
|
65
|
+
console.error(o);
|
|
66
|
+
}
|
|
67
|
+
}, R = (t) => {
|
|
68
|
+
const [r, {
|
|
69
|
+
getI18next: n
|
|
70
|
+
}] = I();
|
|
71
|
+
return d(() => d(() => typeof t.children == "string")() ? r(t.key, t.children, t.options) : P({
|
|
72
|
+
i18n: n(),
|
|
73
|
+
t: r,
|
|
74
|
+
props: t
|
|
75
|
+
}, C(() => t.children)()));
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
R as Trans,
|
|
79
|
+
N as TransProvider,
|
|
80
|
+
I as useTransContext
|
|
81
|
+
};
|
package/package.json
CHANGED
|
@@ -20,11 +20,33 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
22
|
"types": "./dist/types/index.d.ts",
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
"default": "./dist/index.mjs",
|
|
24
|
+
"import": "./dist/index.mjs",
|
|
25
|
+
"require": "./dist/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./index": {
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"default": "./dist/index.mjs",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"require": "./dist/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./i18lite": {
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"default": "./dist/i18lite.mjs",
|
|
36
|
+
"import": "./dist/i18lite.mjs",
|
|
37
|
+
"require": "./dist/i18lite.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./i18lite.mjs": {
|
|
40
|
+
"types": "./dist/types/index.d.ts",
|
|
41
|
+
"default": "./dist/i18lite.mjs",
|
|
42
|
+
"import": "./dist/i18lite.mjs",
|
|
43
|
+
"require": "./dist/i18lite.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./index.mjs": {
|
|
46
|
+
"types": "./dist/types/index.d.ts",
|
|
47
|
+
"default": "./dist/index.mjs",
|
|
48
|
+
"import": "./dist/index.mjs",
|
|
49
|
+
"require": "./dist/index.mjs"
|
|
28
50
|
}
|
|
29
51
|
},
|
|
30
52
|
"files": [
|
|
@@ -61,7 +83,6 @@
|
|
|
61
83
|
"scripts": {
|
|
62
84
|
"build:browser": "vite build --config vite.browser.config.js",
|
|
63
85
|
"build:docs": "vite build --config vite.docs.config.js",
|
|
64
|
-
"build:ssr": "vite build --config vite.ssr.config.js",
|
|
65
86
|
"build:types": "tsc --project tsconfig.types.json",
|
|
66
87
|
"docs": "vite --config vite.docs.config.js",
|
|
67
88
|
"test": "jest --coverage",
|
|
@@ -70,5 +91,5 @@
|
|
|
70
91
|
"sideEffects": false,
|
|
71
92
|
"type": "module",
|
|
72
93
|
"types": "./dist/types/index.d.ts",
|
|
73
|
-
"version": "1.5.
|
|
94
|
+
"version": "1.5.2"
|
|
74
95
|
}
|
package/dist/browser.mjs
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { createComponent as I, memo as v } from "solid-js/web";
|
|
2
|
-
import { useContext as P, createContext as w, createSignal as L, children as $ } from "solid-js";
|
|
3
|
-
let S = {}, E = "translation", x = "";
|
|
4
|
-
const T = { resources: {}, interpolation: { prefix: "{{", suffix: "}}" } };
|
|
5
|
-
let f = T;
|
|
6
|
-
const R = (t) => t.replace(/[-|\\{}()[\]^$+*?.]/g, (e) => e === "-" ? "\\x2d" : `\\${e}`), m = /* @__PURE__ */ new Map(), M = (t, e) => {
|
|
7
|
-
if (!t) return "";
|
|
8
|
-
const n = f?.interpolation, r = n?.prefix ?? "{{", s = n?.suffix ?? "}}", a = r + "|" + s;
|
|
9
|
-
let o = m.get(a);
|
|
10
|
-
if (!o) {
|
|
11
|
-
const i = R(r), u = R(s);
|
|
12
|
-
o = new RegExp(`${i}\\s*(\\w+)\\s*${u}`, "g"), m.set(a, o);
|
|
13
|
-
}
|
|
14
|
-
return t.replace(o, (i, u) => Object.prototype.hasOwnProperty.call(e, u) ? e[u] : i);
|
|
15
|
-
}, h = (t, e, n) => {
|
|
16
|
-
let r = j(c.language, E, t) ?? (typeof e == "string" ? e : t);
|
|
17
|
-
return n || typeof e == "object" && e !== null ? M(r, n || e) : r;
|
|
18
|
-
}, B = (t, e) => {
|
|
19
|
-
S[t] = e;
|
|
20
|
-
}, F = (t, e) => {
|
|
21
|
-
f = T, t && (f = { ...t, interpolation: t?.interpolation || {} }, f.interpolation.prefix = t.interpolation?.prefix || "{{", f.interpolation.suffix = t.interpolation?.suffix || "}}"), x = t?.lng || "", c.store = { data: f.resources || {} }, f.resources = {}, e?.(null, h);
|
|
22
|
-
}, J = (t) => (x = t, Promise.resolve(h)), b = (t, e, n = !0) => {
|
|
23
|
-
const r = t;
|
|
24
|
-
for (const s in e) {
|
|
25
|
-
const a = r[s], o = e[s];
|
|
26
|
-
o && typeof o == "object" && !Array.isArray(o) ? ((typeof a != "object" || Array.isArray(a)) && (r[s] = {}), b(r[s], o, n)) : (n || a === void 0) && (r[s] = o);
|
|
27
|
-
}
|
|
28
|
-
return t;
|
|
29
|
-
}, V = (t, e, n, r = !0, s = !0) => {
|
|
30
|
-
c.store = c.store || { data: {} }, c.store.data = c.store.data || {}, c.store.data[t] = c.store.data[t] || {}, c.store.data[t][e] = c.store.data[t][e] || {};
|
|
31
|
-
const a = c.store.data[t][e], o = n;
|
|
32
|
-
return r ? b(a, o, s) : c.store.data[t][e] = s ? o : { ...o, ...a }, (S.loaded || (() => {
|
|
33
|
-
}))(t, e), c;
|
|
34
|
-
}, j = (t, e, n, r) => {
|
|
35
|
-
const s = c.store;
|
|
36
|
-
if (!s) return;
|
|
37
|
-
const a = s.data?.[t];
|
|
38
|
-
if (!a) return;
|
|
39
|
-
const o = a[e];
|
|
40
|
-
if (!o || typeof o == "string") return;
|
|
41
|
-
const i = r?.keySeparator ?? c.options?.keySeparator ?? ".";
|
|
42
|
-
if (i === !1) return o[n];
|
|
43
|
-
const u = String(i);
|
|
44
|
-
if (n.indexOf(u) === -1) return o[n];
|
|
45
|
-
let l = o, y = 0;
|
|
46
|
-
for (let d = 0; d <= n.length; d++)
|
|
47
|
-
if (d === n.length || n[d] === u) {
|
|
48
|
-
const C = n.slice(y, d);
|
|
49
|
-
if (l == null || !(C in l)) return;
|
|
50
|
-
l = l[C], y = d + 1;
|
|
51
|
-
}
|
|
52
|
-
return l;
|
|
53
|
-
}, X = () => c, c = {
|
|
54
|
-
get language() {
|
|
55
|
-
return x;
|
|
56
|
-
},
|
|
57
|
-
createInstance: X,
|
|
58
|
-
t: h,
|
|
59
|
-
on: B,
|
|
60
|
-
init: F,
|
|
61
|
-
changeLanguage: J,
|
|
62
|
-
addResourceBundle: V,
|
|
63
|
-
options: f,
|
|
64
|
-
getResource: j
|
|
65
|
-
}, A = w();
|
|
66
|
-
function H(t, e) {
|
|
67
|
-
const [n, r] = L(e.resources ? t.t : () => null);
|
|
68
|
-
t.on("loaded", () => r(() => t.t)), t.init(e, (o, i) => r(() => i));
|
|
69
|
-
async function s(o) {
|
|
70
|
-
const i = await t.changeLanguage(o);
|
|
71
|
-
r(() => i);
|
|
72
|
-
}
|
|
73
|
-
function a(o, i, u, l = {}) {
|
|
74
|
-
return t.addResourceBundle(o, i, u, l.deep, l.overwrite);
|
|
75
|
-
}
|
|
76
|
-
return [((...o) => n().apply(null, o)), {
|
|
77
|
-
addResources: a,
|
|
78
|
-
getI18next: () => t,
|
|
79
|
-
changeLanguage: s
|
|
80
|
-
}];
|
|
81
|
-
}
|
|
82
|
-
const K = () => P(A), Y = (t) => I(A.Provider, {
|
|
83
|
-
get value() {
|
|
84
|
-
return H(t.instance || c, {
|
|
85
|
-
lng: t.lng,
|
|
86
|
-
...t.options
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
get children() {
|
|
90
|
-
return t.children;
|
|
91
|
-
}
|
|
92
|
-
}), g = (t, { prefix: e, suffix: n }) => t.includes(e) && t.includes(n), W = (t, { interpolation: e }) => (n, r) => typeof n == "string" ? g(n, e) ? t.children[r].children?.[0].content : t.children[r].content : (n.textContent = t.children[r].children?.[0].content, n), _ = !globalThis.window, q = (t, e, n) => (r) => {
|
|
93
|
-
const s = typeof r;
|
|
94
|
-
if (s === "string" && g(r, e.interpolation)) return t(r, n.options);
|
|
95
|
-
if (s === "object") {
|
|
96
|
-
const a = r.textContent ?? r.t;
|
|
97
|
-
a && g(a, e.interpolation) && (r[_ ? "t" : "textContent"] = t(a, n.options));
|
|
98
|
-
}
|
|
99
|
-
return r;
|
|
100
|
-
};
|
|
101
|
-
let p;
|
|
102
|
-
(async () => {
|
|
103
|
-
try {
|
|
104
|
-
p = (await import("html-parse-string")).parse;
|
|
105
|
-
} catch {
|
|
106
|
-
}
|
|
107
|
-
})();
|
|
108
|
-
const z = () => {
|
|
109
|
-
console.error(
|
|
110
|
-
"In order to use JSX nesting, install %chtml-parse-string",
|
|
111
|
-
"font-weight: 700",
|
|
112
|
-
"https://github.com/ryansolid/html-parse-string."
|
|
113
|
-
);
|
|
114
|
-
}, G = ({ i18n: { options: t }, t: e, props: n }, r) => {
|
|
115
|
-
const s = e(n.key, n.options);
|
|
116
|
-
if (!n.children) return s;
|
|
117
|
-
if (s === n.key) return r.map(q(e, t, n));
|
|
118
|
-
if (!p) {
|
|
119
|
-
z();
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
const [a] = p(`<0>${s}</0>`);
|
|
124
|
-
return r.map(W(a, t));
|
|
125
|
-
} catch (a) {
|
|
126
|
-
console.error(a);
|
|
127
|
-
}
|
|
128
|
-
}, Z = (t) => {
|
|
129
|
-
const [e, {
|
|
130
|
-
getI18next: n
|
|
131
|
-
}] = K();
|
|
132
|
-
return v(() => v(() => typeof t.children == "string")() ? e(t.key, t.children, t.options) : G({
|
|
133
|
-
i18n: n(),
|
|
134
|
-
t: e,
|
|
135
|
-
props: t
|
|
136
|
-
}, $(() => t.children)()));
|
|
137
|
-
};
|
|
138
|
-
export {
|
|
139
|
-
Z as Trans,
|
|
140
|
-
Y as TransProvider,
|
|
141
|
-
K as useTransContext
|
|
142
|
-
};
|
package/dist/ssr.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var L=Object.create;var T=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var J=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!E.call(t,o)&&o!==n&&T(t,o,{get:()=>e[o],enumerable:!(r=$(e,o))||r.enumerable});return t};var q=(t,e,n)=>(n=t!=null?L(M(t)):{},J(e||!t||!t.__esModule?T(n,"default",{value:t,enumerable:!0}):n,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("solid-js"),B=require("solid-js/web");let R={},F="translation",h="";const P={resources:{},interpolation:{prefix:"{{",suffix:"}}"}};let f=P;const S=t=>t.replace(/[-|\\{}()[\]^$+*?.]/g,e=>e==="-"?"\\x2d":`\\${e}`),b=new Map,V=(t,e)=>{if(!t)return"";const n=f?.interpolation,r=n?.prefix??"{{",o=n?.suffix??"}}",a=r+"|"+o;let s=b.get(a);if(!s){const i=S(r),u=S(o);s=new RegExp(`${i}\\s*(\\w+)\\s*${u}`,"g"),b.set(a,s)}return t.replace(s,(i,u)=>Object.prototype.hasOwnProperty.call(e,u)?e[u]:i)},y=(t,e,n)=>{let r=w(c.language,F,t)??(typeof e=="string"?e:t);return n||typeof e=="object"&&e!==null?V(r,n||e):r},X=(t,e)=>{R[t]=e},H=(t,e)=>{f=P,t&&(f={...t,interpolation:t?.interpolation||{}},f.interpolation.prefix=t.interpolation?.prefix||"{{",f.interpolation.suffix=t.interpolation?.suffix||"}}"),h=t?.lng||"",c.store={data:f.resources||{}},f.resources={},e?.(null,y)},K=t=>(h=t,Promise.resolve(y)),j=(t,e,n=!0)=>{const r=t;for(const o in e){const a=r[o],s=e[o];s&&typeof s=="object"&&!Array.isArray(s)?((typeof a!="object"||Array.isArray(a))&&(r[o]={}),j(r[o],s,n)):(n||a===void 0)&&(r[o]=s)}return t},W=(t,e,n,r=!0,o=!0)=>{c.store=c.store||{data:{}},c.store.data=c.store.data||{},c.store.data[t]=c.store.data[t]||{},c.store.data[t][e]=c.store.data[t][e]||{};const a=c.store.data[t][e],s=n;return r?j(a,s,o):c.store.data[t][e]=o?s:{...s,...a},(R.loaded||(()=>{}))(t,e),c},w=(t,e,n,r)=>{const o=c.store;if(!o)return;const a=o.data?.[t];if(!a)return;const s=a[e];if(!s||typeof s=="string")return;const i=r?.keySeparator??c.options?.keySeparator??".";if(i===!1)return s[n];const u=String(i);if(n.indexOf(u)===-1)return s[n];let l=s,v=0;for(let d=0;d<=n.length;d++)if(d===n.length||n[d]===u){const C=n.slice(v,d);if(l==null||!(C in l))return;l=l[C],v=d+1}return l},_=()=>c,c={get language(){return h},createInstance:_,t:y,on:X,init:H,changeLanguage:K,addResourceBundle:W,options:f,getResource:w},A=g.createContext();function z(t,e){const[n,r]=g.createSignal(e.resources?t.t:()=>null);t.on("loaded",()=>r(()=>t.t)),t.init(e,(s,i)=>r(()=>i));async function o(s){const i=await t.changeLanguage(s);r(()=>i)}function a(s,i,u,l={}){return t.addResourceBundle(s,i,u,l.deep,l.overwrite)}return[((...s)=>n().apply(null,s)),{addResources:a,getI18next:()=>t,changeLanguage:o}]}const I=()=>g.useContext(A),G=t=>B.createComponent(A.Provider,{get value(){return z(t.instance||c,{lng:t.lng,...t.options})},get children(){return t.children}}),x=(t,{prefix:e,suffix:n})=>t.includes(e)&&t.includes(n),Q=(t,{interpolation:e})=>(n,r)=>typeof n=="string"?x(n,e)?t.children[r].children?.[0].content:t.children[r].content:(n.textContent=t.children[r].children?.[0].content,n),U=!globalThis.window,Y=(t,e,n)=>r=>{const o=typeof r;if(o==="string"&&x(r,e.interpolation))return t(r,n.options);if(o==="object"){const a=r.textContent??r.t;a&&x(a,e.interpolation)&&(r[U?"t":"textContent"]=t(a,n.options))}return r};let p;(async()=>{try{p=(await import("html-parse-string")).parse}catch{}})();const Z=()=>{console.error("In order to use JSX nesting, install %chtml-parse-string","font-weight: 700","https://github.com/ryansolid/html-parse-string.")},k=({i18n:{options:t},t:e,props:n},r)=>{const o=e(n.key,n.options);if(!n.children)return o;if(o===n.key)return r.map(Y(e,t,n));if(!p){Z();return}try{const[a]=p(`<0>${o}</0>`);return r.map(Q(a,t))}catch(a){console.error(a)}},N=t=>{const[e,{getI18next:n}]=I();return typeof t.children=="string"?e(t.key,t.children,t.options):k({i18n:n(),t:e,props:t},g.children(()=>t.children)())};exports.Trans=N;exports.TransProvider=G;exports.useTransContext=I;
|
package/dist/ssr.mjs
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { useContext as A, createContext as I, createSignal as P, children as w } from "solid-js";
|
|
2
|
-
import { createComponent as L } from "solid-js/web";
|
|
3
|
-
let S = {}, $ = "translation", x = "";
|
|
4
|
-
const T = { resources: {}, interpolation: { prefix: "{{", suffix: "}}" } };
|
|
5
|
-
let f = T;
|
|
6
|
-
const v = (t) => t.replace(/[-|\\{}()[\]^$+*?.]/g, (e) => e === "-" ? "\\x2d" : `\\${e}`), R = /* @__PURE__ */ new Map(), E = (t, e) => {
|
|
7
|
-
if (!t) return "";
|
|
8
|
-
const n = f?.interpolation, r = n?.prefix ?? "{{", s = n?.suffix ?? "}}", a = r + "|" + s;
|
|
9
|
-
let o = R.get(a);
|
|
10
|
-
if (!o) {
|
|
11
|
-
const i = v(r), u = v(s);
|
|
12
|
-
o = new RegExp(`${i}\\s*(\\w+)\\s*${u}`, "g"), R.set(a, o);
|
|
13
|
-
}
|
|
14
|
-
return t.replace(o, (i, u) => Object.prototype.hasOwnProperty.call(e, u) ? e[u] : i);
|
|
15
|
-
}, h = (t, e, n) => {
|
|
16
|
-
let r = m(c.language, $, t) ?? (typeof e == "string" ? e : t);
|
|
17
|
-
return n || typeof e == "object" && e !== null ? E(r, n || e) : r;
|
|
18
|
-
}, M = (t, e) => {
|
|
19
|
-
S[t] = e;
|
|
20
|
-
}, B = (t, e) => {
|
|
21
|
-
f = T, t && (f = { ...t, interpolation: t?.interpolation || {} }, f.interpolation.prefix = t.interpolation?.prefix || "{{", f.interpolation.suffix = t.interpolation?.suffix || "}}"), x = t?.lng || "", c.store = { data: f.resources || {} }, f.resources = {}, e?.(null, h);
|
|
22
|
-
}, F = (t) => (x = t, Promise.resolve(h)), b = (t, e, n = !0) => {
|
|
23
|
-
const r = t;
|
|
24
|
-
for (const s in e) {
|
|
25
|
-
const a = r[s], o = e[s];
|
|
26
|
-
o && typeof o == "object" && !Array.isArray(o) ? ((typeof a != "object" || Array.isArray(a)) && (r[s] = {}), b(r[s], o, n)) : (n || a === void 0) && (r[s] = o);
|
|
27
|
-
}
|
|
28
|
-
return t;
|
|
29
|
-
}, J = (t, e, n, r = !0, s = !0) => {
|
|
30
|
-
c.store = c.store || { data: {} }, c.store.data = c.store.data || {}, c.store.data[t] = c.store.data[t] || {}, c.store.data[t][e] = c.store.data[t][e] || {};
|
|
31
|
-
const a = c.store.data[t][e], o = n;
|
|
32
|
-
return r ? b(a, o, s) : c.store.data[t][e] = s ? o : { ...o, ...a }, (S.loaded || (() => {
|
|
33
|
-
}))(t, e), c;
|
|
34
|
-
}, m = (t, e, n, r) => {
|
|
35
|
-
const s = c.store;
|
|
36
|
-
if (!s) return;
|
|
37
|
-
const a = s.data?.[t];
|
|
38
|
-
if (!a) return;
|
|
39
|
-
const o = a[e];
|
|
40
|
-
if (!o || typeof o == "string") return;
|
|
41
|
-
const i = r?.keySeparator ?? c.options?.keySeparator ?? ".";
|
|
42
|
-
if (i === !1) return o[n];
|
|
43
|
-
const u = String(i);
|
|
44
|
-
if (n.indexOf(u) === -1) return o[n];
|
|
45
|
-
let l = o, y = 0;
|
|
46
|
-
for (let d = 0; d <= n.length; d++)
|
|
47
|
-
if (d === n.length || n[d] === u) {
|
|
48
|
-
const C = n.slice(y, d);
|
|
49
|
-
if (l == null || !(C in l)) return;
|
|
50
|
-
l = l[C], y = d + 1;
|
|
51
|
-
}
|
|
52
|
-
return l;
|
|
53
|
-
}, V = () => c, c = {
|
|
54
|
-
get language() {
|
|
55
|
-
return x;
|
|
56
|
-
},
|
|
57
|
-
createInstance: V,
|
|
58
|
-
t: h,
|
|
59
|
-
on: M,
|
|
60
|
-
init: B,
|
|
61
|
-
changeLanguage: F,
|
|
62
|
-
addResourceBundle: J,
|
|
63
|
-
options: f,
|
|
64
|
-
getResource: m
|
|
65
|
-
}, j = I();
|
|
66
|
-
function X(t, e) {
|
|
67
|
-
const [n, r] = P(e.resources ? t.t : () => null);
|
|
68
|
-
t.on("loaded", () => r(() => t.t)), t.init(e, (o, i) => r(() => i));
|
|
69
|
-
async function s(o) {
|
|
70
|
-
const i = await t.changeLanguage(o);
|
|
71
|
-
r(() => i);
|
|
72
|
-
}
|
|
73
|
-
function a(o, i, u, l = {}) {
|
|
74
|
-
return t.addResourceBundle(o, i, u, l.deep, l.overwrite);
|
|
75
|
-
}
|
|
76
|
-
return [((...o) => n().apply(null, o)), {
|
|
77
|
-
addResources: a,
|
|
78
|
-
getI18next: () => t,
|
|
79
|
-
changeLanguage: s
|
|
80
|
-
}];
|
|
81
|
-
}
|
|
82
|
-
const H = () => A(j), U = (t) => L(j.Provider, {
|
|
83
|
-
get value() {
|
|
84
|
-
return X(t.instance || c, {
|
|
85
|
-
lng: t.lng,
|
|
86
|
-
...t.options
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
get children() {
|
|
90
|
-
return t.children;
|
|
91
|
-
}
|
|
92
|
-
}), g = (t, { prefix: e, suffix: n }) => t.includes(e) && t.includes(n), K = (t, { interpolation: e }) => (n, r) => typeof n == "string" ? g(n, e) ? t.children[r].children?.[0].content : t.children[r].content : (n.textContent = t.children[r].children?.[0].content, n), W = !globalThis.window, _ = (t, e, n) => (r) => {
|
|
93
|
-
const s = typeof r;
|
|
94
|
-
if (s === "string" && g(r, e.interpolation)) return t(r, n.options);
|
|
95
|
-
if (s === "object") {
|
|
96
|
-
const a = r.textContent ?? r.t;
|
|
97
|
-
a && g(a, e.interpolation) && (r[W ? "t" : "textContent"] = t(a, n.options));
|
|
98
|
-
}
|
|
99
|
-
return r;
|
|
100
|
-
};
|
|
101
|
-
let p;
|
|
102
|
-
(async () => {
|
|
103
|
-
try {
|
|
104
|
-
p = (await import("html-parse-string")).parse;
|
|
105
|
-
} catch {
|
|
106
|
-
}
|
|
107
|
-
})();
|
|
108
|
-
const q = () => {
|
|
109
|
-
console.error(
|
|
110
|
-
"In order to use JSX nesting, install %chtml-parse-string",
|
|
111
|
-
"font-weight: 700",
|
|
112
|
-
"https://github.com/ryansolid/html-parse-string."
|
|
113
|
-
);
|
|
114
|
-
}, z = ({ i18n: { options: t }, t: e, props: n }, r) => {
|
|
115
|
-
const s = e(n.key, n.options);
|
|
116
|
-
if (!n.children) return s;
|
|
117
|
-
if (s === n.key) return r.map(_(e, t, n));
|
|
118
|
-
if (!p) {
|
|
119
|
-
q();
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
const [a] = p(`<0>${s}</0>`);
|
|
124
|
-
return r.map(K(a, t));
|
|
125
|
-
} catch (a) {
|
|
126
|
-
console.error(a);
|
|
127
|
-
}
|
|
128
|
-
}, Y = (t) => {
|
|
129
|
-
const [e, {
|
|
130
|
-
getI18next: n
|
|
131
|
-
}] = H();
|
|
132
|
-
return typeof t.children == "string" ? e(t.key, t.children, t.options) : z({
|
|
133
|
-
i18n: n(),
|
|
134
|
-
t: e,
|
|
135
|
-
props: t
|
|
136
|
-
}, w(() => t.children)());
|
|
137
|
-
};
|
|
138
|
-
export {
|
|
139
|
-
Y as Trans,
|
|
140
|
-
U as TransProvider,
|
|
141
|
-
H as useTransContext
|
|
142
|
-
};
|