@i18n-micro/solid 1.2.16 → 2.0.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 +16 -53
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -169
- package/dist/index.d.ts +101 -169
- package/dist/index.mjs +309 -436
- package/dist/index.mjs.map +1 -1
- package/dist/router.cjs +2 -0
- package/dist/router.cjs.map +1 -0
- package/dist/router.d.cts +84 -0
- package/dist/router.d.ts +84 -0
- package/dist/router.mjs +26 -0
- package/dist/router.mjs.map +1 -0
- package/package.json +33 -15
- package/src/components/I18nGroup.tsx +27 -0
- package/src/components/I18nLink.tsx +71 -0
- package/src/components/I18nSwitcher.tsx +175 -0
- package/src/components/I18nT.tsx +126 -0
- package/src/components/merge-styles.ts +16 -0
- package/src/context.tsx +41 -0
- package/src/i18n.ts +68 -0
- package/src/index.ts +26 -0
- package/src/injection.ts +31 -0
- package/src/router/adapter.tsx +54 -0
- package/src/router/index.ts +3 -0
- package/src/router/types.ts +53 -0
- package/src/use-i18n.ts +72 -0
package/dist/index.mjs
CHANGED
|
@@ -1,99 +1,128 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Dynamic as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { FormatService as e, defaultPlural as t, externalLinkHref as n, interpolate as r, interpolate as i, isActiveLink as a, isPlainClick as o, localeIsoMap as s, ownValue as c, resolveText as l } from "@i18n-micro/core";
|
|
2
|
+
import { Dynamic as u, className as d, createComponent as f, delegateEvents as p, effect as m, insert as h, memo as g, mergeProps as _, setAttribute as v, spread as y, style as b, template as x, use as ee } from "solid-js/web";
|
|
3
|
+
import { For as S, Show as te, batch as C, createComputed as w, createContext as T, createMemo as E, createRoot as D, createSignal as O, getOwner as k, mergeProps as A, onCleanup as j, onMount as M, splitProps as N, useContext as P } from "solid-js";
|
|
4
|
+
import { SWITCHER_STYLES as F, foldTemplate as I } from "@i18n-micro/core/render";
|
|
5
|
+
import { I18n as L } from "@i18n-micro/runtime";
|
|
6
|
+
// src/injection.ts
|
|
7
|
+
var R = T(), z = () => {
|
|
8
|
+
let e = P(R);
|
|
8
9
|
if (!e) throw Error("[i18n-micro] I18nContext not found. Make sure I18nProvider is used.");
|
|
9
10
|
return e;
|
|
10
|
-
},
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return typeof i == "string" ? i : String(i);
|
|
22
|
-
};
|
|
11
|
+
}, B = () => z().i18n, ne = () => P(R)?.locales, V = () => P(R)?.defaultLocale, H = () => P(R)?.router, U = /*#__PURE__*/ x("<div>"), W = (e) => {
|
|
12
|
+
let t = B(), [n, r] = N(e, [
|
|
13
|
+
"prefix",
|
|
14
|
+
"groupClass",
|
|
15
|
+
"class",
|
|
16
|
+
"children"
|
|
17
|
+
]), i = (e, r) => t.ts(`${n.prefix}.${e}`, r), a = E(() => [
|
|
18
|
+
"i18n-group",
|
|
19
|
+
n.groupClass,
|
|
20
|
+
n.class
|
|
21
|
+
].filter(Boolean).join(" "));
|
|
23
22
|
return (() => {
|
|
24
|
-
var
|
|
25
|
-
return
|
|
26
|
-
return
|
|
27
|
-
} }, r), !1, !0),
|
|
28
|
-
var
|
|
29
|
-
return () =>
|
|
23
|
+
var e = U();
|
|
24
|
+
return y(e, _({ get class() {
|
|
25
|
+
return a();
|
|
26
|
+
} }, r), !1, !0), h(e, (() => {
|
|
27
|
+
var e = g(() => typeof n.children == "function");
|
|
28
|
+
return () => e() ? n.children({
|
|
30
29
|
prefix: n.prefix,
|
|
31
30
|
t: i
|
|
32
|
-
}) :
|
|
33
|
-
})()),
|
|
31
|
+
}) : n.children;
|
|
32
|
+
})()), e;
|
|
34
33
|
})();
|
|
35
|
-
},
|
|
36
|
-
|
|
34
|
+
}, G = (e) => typeof e == "string" ? e : e.path || "/";
|
|
35
|
+
function K(e, t) {
|
|
36
|
+
let n = e.i18n, r = () => t?.locales ?? e.locales ?? [], i = (t, r) => {
|
|
37
|
+
let i = e.router?.resolvePath;
|
|
38
|
+
return i ? i(t, r || n.locale) : t;
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
instance: n,
|
|
42
|
+
locale: n.localeAccessor,
|
|
43
|
+
getLocales: r,
|
|
44
|
+
defaultLocale: () => t?.defaultLocale ?? e.defaultLocale ?? n.fallbackLocale,
|
|
45
|
+
getLocaleName: () => r().find((e) => e.code === n.locale)?.displayName || null,
|
|
46
|
+
localeRoute: i,
|
|
47
|
+
localePath: (e, t) => G(i(e, t)),
|
|
48
|
+
switchLocale: (t) => {
|
|
49
|
+
n.locale = t;
|
|
50
|
+
let r = e.router;
|
|
51
|
+
r && r.push({ path: G(i(r.getCurrentPath(), t)) });
|
|
52
|
+
},
|
|
53
|
+
t: n.t.bind(n),
|
|
54
|
+
ts: n.ts.bind(n),
|
|
55
|
+
tc: n.tc.bind(n),
|
|
56
|
+
tn: n.tn.bind(n),
|
|
57
|
+
td: n.td.bind(n),
|
|
58
|
+
tdr: n.tdr.bind(n),
|
|
59
|
+
has: n.has.bind(n),
|
|
60
|
+
setRoute: n.setRoute.bind(n),
|
|
61
|
+
getRoute: () => n.currentRoute,
|
|
62
|
+
getLocale: () => n.locale,
|
|
63
|
+
addTranslations: n.addTranslations.bind(n),
|
|
64
|
+
addRouteTranslations: n.addRouteTranslations.bind(n),
|
|
65
|
+
resolveTranslations: n.resolveTranslations.bind(n),
|
|
66
|
+
setTranslation: n.setTranslation.bind(n),
|
|
67
|
+
clearCache: n.clearCache.bind(n)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function q(e) {
|
|
71
|
+
let t = z();
|
|
72
|
+
return e?.locales || e?.defaultLocale ? K(t, e) : t.api ??= K(t);
|
|
73
|
+
}
|
|
74
|
+
// src/components/merge-styles.ts
|
|
75
|
+
var J = (e) => typeof e == "string" ? e : Object.entries(e ?? {}).map(([e, t]) => `${e}:${t}`).join(";");
|
|
76
|
+
function Y(...e) {
|
|
77
|
+
return e.some((e) => typeof e == "string") ? e.map(J).filter(Boolean).join(";") : Object.assign({}, ...e);
|
|
78
|
+
}
|
|
79
|
+
// src/components/I18nLink.tsx
|
|
80
|
+
function X(e, t) {
|
|
81
|
+
typeof e == "function" ? e(t) : e && e[0](e[1], t);
|
|
82
|
+
}
|
|
83
|
+
var Z = (e) => {
|
|
84
|
+
let t = z(), r = t.i18n, i = q(), [s, c] = N(e, [
|
|
37
85
|
"to",
|
|
38
86
|
"localeRoute",
|
|
39
87
|
"activeStyle",
|
|
40
88
|
"style",
|
|
41
|
-
"
|
|
42
|
-
]),
|
|
43
|
-
let e =
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
i
|
|
50
|
-
|
|
51
|
-
return
|
|
52
|
-
}),
|
|
53
|
-
|
|
54
|
-
let
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
let e = r.style || {}, t = l() && r.activeStyle || {};
|
|
58
|
-
return {
|
|
59
|
-
...typeof e == "object" ? e : {},
|
|
60
|
-
...typeof t == "object" ? t : {}
|
|
61
|
-
};
|
|
62
|
-
}), h = t?.linkComponent;
|
|
63
|
-
return c() ? (() => {
|
|
64
|
-
var e = L();
|
|
65
|
-
return m(e, f({
|
|
66
|
-
get href() {
|
|
67
|
-
return d(() => typeof r.to == "string")() ? r.to : "";
|
|
68
|
-
},
|
|
69
|
-
get style() {
|
|
70
|
-
return p();
|
|
71
|
-
}
|
|
72
|
-
}, i), !1, !0), u(e, () => r.children), e;
|
|
73
|
-
})() : h ? s(h, f({
|
|
89
|
+
"onClick"
|
|
90
|
+
]), l = E(() => n(s.to)), d = E(() => G((s.localeRoute ?? i.localeRoute)(s.to, r.locale))), p = E(() => {
|
|
91
|
+
let e = t.router;
|
|
92
|
+
if (!e || !s.activeStyle || l() !== void 0) return !1;
|
|
93
|
+
let n = [
|
|
94
|
+
r.locale,
|
|
95
|
+
i.defaultLocale(),
|
|
96
|
+
r.fallbackLocale,
|
|
97
|
+
...i.getLocales().map((e) => e.code)
|
|
98
|
+
];
|
|
99
|
+
return a(e.getCurrentPath(), d(), n);
|
|
100
|
+
}), m = (e) => {
|
|
101
|
+
X(s.onClick, e);
|
|
102
|
+
let n = t.router;
|
|
103
|
+
n && l() === void 0 && o(e) && (e.preventDefault(), n.push({ path: d() }));
|
|
104
|
+
}, h = () => l() === void 0 && t.router?.linkComponent !== void 0, v = A(c, {
|
|
74
105
|
get href() {
|
|
75
|
-
return
|
|
106
|
+
return l() ?? d();
|
|
76
107
|
},
|
|
77
108
|
get style() {
|
|
78
|
-
return p();
|
|
109
|
+
return p() ? Y(s.style, s.activeStyle) : s.style;
|
|
110
|
+
},
|
|
111
|
+
get onClick() {
|
|
112
|
+
return h() ? s.onClick : m;
|
|
113
|
+
},
|
|
114
|
+
get target() {
|
|
115
|
+
return l() === void 0 ? void 0 : c.target ?? "_blank";
|
|
116
|
+
},
|
|
117
|
+
get rel() {
|
|
118
|
+
return l() === void 0 ? void 0 : c.rel ?? "noopener noreferrer";
|
|
79
119
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return o();
|
|
87
|
-
},
|
|
88
|
-
get style() {
|
|
89
|
-
return p();
|
|
90
|
-
}
|
|
91
|
-
}, i, { onClick: (e) => {
|
|
92
|
-
t && !c() && (e.preventDefault(), t.push({ path: o() }));
|
|
93
|
-
} }), !1, !0), u(e, () => r.children), e;
|
|
94
|
-
})();
|
|
95
|
-
}, B = /*#__PURE__*/ g("<div class=i18n-switcher-wrapper><button type=button class=i18n-switcher-button aria-haspopup=true><span></span><span>▼"), V = /*#__PURE__*/ g("<ul class=i18n-switcher-dropdown>"), H = /*#__PURE__*/ g("<li><a>"), U = (e) => {
|
|
96
|
-
let t = j(), n = P(), r = M(), [i, a] = w(e, [
|
|
120
|
+
});
|
|
121
|
+
return f(u, _({ get component() {
|
|
122
|
+
return g(() => !!h())() ? t.router.linkComponent : "a";
|
|
123
|
+
} }, v));
|
|
124
|
+
}, re = /*#__PURE__*/ x("<ul class=i18n-switcher-dropdown>"), ie = /*#__PURE__*/ x("<div><button type=button class=\"i18n-switcher-button language-switcher\"><span></span> <span>▾"), ae = /*#__PURE__*/ x("<li><a>"), Q = (e) => Object.fromEntries(Object.entries(e).map(([e, t]) => [e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`), t])), oe = /*#__PURE__*/ Q(F.wrapper), se = /*#__PURE__*/ Q(F.button), ce = /*#__PURE__*/ Q(F.dropdown), le = /*#__PURE__*/ Q(F.item), ue = /*#__PURE__*/ Q(F.link), de = /*#__PURE__*/ Q(F.activeLink), fe = /*#__PURE__*/ Q(F.icon), pe = /*#__PURE__*/ Q(F.openIcon), me = (e) => {
|
|
125
|
+
let t = q(), n = z(), [r, i] = N(e, [
|
|
97
126
|
"locales",
|
|
98
127
|
"currentLocale",
|
|
99
128
|
"getLocaleName",
|
|
@@ -107,135 +136,92 @@ var D = v(), O = v(), k = v(), A = v(), j = () => {
|
|
|
107
136
|
"customLinkStyle",
|
|
108
137
|
"customActiveLinkStyle",
|
|
109
138
|
"customDisabledLinkStyle",
|
|
110
|
-
"customIconStyle"
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
let e =
|
|
115
|
-
return e ?
|
|
116
|
-
}),
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
139
|
+
"customIconStyle",
|
|
140
|
+
"class",
|
|
141
|
+
"style"
|
|
142
|
+
]), [a, s] = O(!1), l, u = E(() => r.locales ?? n.locales ?? []), p = E(() => {
|
|
143
|
+
let e = r.currentLocale;
|
|
144
|
+
return typeof e == "function" ? e() : e ?? t.locale();
|
|
145
|
+
}), g = E(() => u().find((e) => e.code === p())), x = (e) => r.customLabels && c(r.customLabels, e.code) || e.displayName || e.code, C = (e) => {
|
|
146
|
+
let t = n.router, i = t?.getCurrentPath() ?? (typeof window > "u" ? "/" : window.location.pathname + window.location.search + window.location.hash);
|
|
147
|
+
return r.localeRoute ? G(r.localeRoute(i, e)) : t ? G(t.resolvePath ? t.resolvePath(i, e) : i) : "#";
|
|
148
|
+
}, w = (e, i) => {
|
|
149
|
+
if (o(e)) {
|
|
150
|
+
if ((r.switchLocale || n.router || !r.localeRoute) && e.preventDefault(), s(!1), r.switchLocale) return r.switchLocale(i);
|
|
151
|
+
if (!r.localeRoute) return t.switchLocale(i);
|
|
152
|
+
t.instance.locale = i, n.router?.push({ path: C(i) });
|
|
120
153
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
})() : n?.resolvePath ? (() => {
|
|
126
|
-
let t = n.resolvePath(a, e);
|
|
127
|
-
return typeof t == "string" ? t : t.path || "/";
|
|
128
|
-
})() : a;
|
|
129
|
-
n.push({ path: o });
|
|
130
|
-
}, F = {
|
|
131
|
-
position: "relative",
|
|
132
|
-
display: "inline-block",
|
|
133
|
-
"vertical-align": "middle"
|
|
134
|
-
}, I = {
|
|
135
|
-
padding: "4px 12px",
|
|
136
|
-
"font-size": "16px",
|
|
137
|
-
cursor: "pointer",
|
|
138
|
-
"background-color": "#fff",
|
|
139
|
-
border: "1px solid #333",
|
|
140
|
-
transition: "background-color 0.3s ease",
|
|
141
|
-
display: "flex",
|
|
142
|
-
"align-items": "center",
|
|
143
|
-
"justify-content": "space-between"
|
|
144
|
-
}, L = {
|
|
145
|
-
position: "absolute",
|
|
146
|
-
top: "100%",
|
|
147
|
-
left: "0",
|
|
148
|
-
"z-index": 1e3,
|
|
149
|
-
"background-color": "#fff",
|
|
150
|
-
border: "1px solid #333",
|
|
151
|
-
"list-style": "none",
|
|
152
|
-
padding: "0",
|
|
153
|
-
margin: "4px 0 0 0",
|
|
154
|
-
"min-width": "150px",
|
|
155
|
-
"box-shadow": "0 2px 8px rgba(0,0,0,0.15)"
|
|
156
|
-
}, R = {
|
|
157
|
-
margin: "0",
|
|
158
|
-
padding: "0"
|
|
159
|
-
}, z = {
|
|
160
|
-
display: "block",
|
|
161
|
-
padding: "8px 12px",
|
|
162
|
-
color: "#333",
|
|
163
|
-
"text-decoration": "none",
|
|
164
|
-
transition: "background-color 0.3s ease",
|
|
165
|
-
cursor: "pointer"
|
|
166
|
-
}, U = {
|
|
167
|
-
"font-weight": "bold",
|
|
168
|
-
color: "#007bff",
|
|
169
|
-
cursor: "not-allowed"
|
|
170
|
-
}, W = {
|
|
171
|
-
"margin-left": "8px",
|
|
172
|
-
display: "inline-block",
|
|
173
|
-
transition: "transform 0.3s ease"
|
|
174
|
-
}, G = { transform: "rotate(180deg)" }, K = (e) => {
|
|
175
|
-
if (!s()) return;
|
|
176
|
-
let t = e.target;
|
|
177
|
-
if (!t || !g) return;
|
|
178
|
-
let n = g.contains(t), r = t.closest(".i18n-switcher-button") !== null;
|
|
179
|
-
!n && !r && c(!1);
|
|
154
|
+
}, T = (e) => {
|
|
155
|
+
a() && !l?.contains(e.target) && s(!1);
|
|
156
|
+
}, D = (e) => {
|
|
157
|
+
e.key === "Escape" && s(!1);
|
|
180
158
|
};
|
|
181
|
-
return
|
|
182
|
-
document.addEventListener("click",
|
|
183
|
-
|
|
184
|
-
|
|
159
|
+
return M(() => {
|
|
160
|
+
document.addEventListener("click", T), document.addEventListener("keydown", D), j(() => {
|
|
161
|
+
document.removeEventListener("click", T), document.removeEventListener("keydown", D);
|
|
162
|
+
});
|
|
185
163
|
}), (() => {
|
|
186
|
-
var e =
|
|
187
|
-
return
|
|
188
|
-
|
|
189
|
-
}, e),
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
164
|
+
var e = ie(), t = e.firstChild, n = t.firstChild, o = n.nextSibling.nextSibling;
|
|
165
|
+
return ee((e) => {
|
|
166
|
+
l = e;
|
|
167
|
+
}, e), y(e, _(i, {
|
|
168
|
+
get class() {
|
|
169
|
+
return ["i18n-switcher-wrapper", r.class].filter(Boolean).join(" ");
|
|
170
|
+
},
|
|
171
|
+
get style() {
|
|
172
|
+
return Y(oe, r.customWrapperStyle, r.style);
|
|
173
|
+
}
|
|
174
|
+
}), !1, !0), t.$$click = () => s(!a()), h(n, () => r.getLocaleName?.() || x(g() ?? { code: p() })), h(e, f(te, {
|
|
175
|
+
get when() {
|
|
176
|
+
return a();
|
|
177
|
+
},
|
|
178
|
+
get children() {
|
|
179
|
+
var e = re();
|
|
180
|
+
return h(e, f(S, {
|
|
181
|
+
get each() {
|
|
182
|
+
return u().filter((e) => !e.disabled);
|
|
183
|
+
},
|
|
184
|
+
children: (e) => {
|
|
185
|
+
let t = () => e.code === p(), n = e.iso || e.code;
|
|
186
|
+
return (() => {
|
|
187
|
+
var i = ae(), a = i.firstChild;
|
|
188
|
+
return a.$$click = (t) => w(t, e.code), v(a, "hreflang", n), v(a, "lang", n), h(a, () => x(e)), m((n) => {
|
|
189
|
+
var o = {
|
|
190
|
+
...le,
|
|
191
|
+
...r.customItemStyle
|
|
192
|
+
}, s = `switcher-locale-${e.code}`, c = C(e.code), l = e.dir, u = t() ? "page" : void 0, f = {
|
|
193
|
+
...ue,
|
|
194
|
+
...t() ? de : void 0,
|
|
195
|
+
...r.customLinkStyle,
|
|
196
|
+
...t() ? r.customActiveLinkStyle : void 0
|
|
197
|
+
};
|
|
198
|
+
return n.e = b(i, o, n.e), s !== n.t && d(a, n.t = s), c !== n.a && v(a, "href", n.a = c), l !== n.o && v(a, "dir", n.o = l), u !== n.i && v(a, "aria-current", n.i = u), n.n = b(a, f, n.n), n;
|
|
199
|
+
}, {
|
|
200
|
+
e: void 0,
|
|
201
|
+
t: void 0,
|
|
202
|
+
a: void 0,
|
|
203
|
+
o: void 0,
|
|
204
|
+
i: void 0,
|
|
205
|
+
n: void 0
|
|
206
|
+
}), i;
|
|
207
|
+
})();
|
|
208
|
+
}
|
|
209
|
+
})), m((t) => b(e, {
|
|
210
|
+
...ce,
|
|
211
|
+
...r.customDropdownStyle
|
|
226
212
|
}, t)), e;
|
|
227
|
-
}
|
|
228
|
-
})
|
|
213
|
+
}
|
|
214
|
+
}), null), m((e) => {
|
|
229
215
|
var n = {
|
|
230
|
-
...
|
|
231
|
-
...
|
|
232
|
-
...
|
|
233
|
-
},
|
|
234
|
-
...
|
|
235
|
-
...
|
|
236
|
-
...
|
|
216
|
+
...se,
|
|
217
|
+
...r.customButtonStyle,
|
|
218
|
+
...g()?.disabled ? r.customDisabledLinkStyle : void 0
|
|
219
|
+
}, i = a(), s = {
|
|
220
|
+
...fe,
|
|
221
|
+
...a() ? pe : void 0,
|
|
222
|
+
...r.customIconStyle
|
|
237
223
|
};
|
|
238
|
-
return e.e =
|
|
224
|
+
return e.e = b(t, n, e.e), i !== e.t && v(t, "aria-expanded", e.t = i), e.a = b(o, s, e.a), e;
|
|
239
225
|
}, {
|
|
240
226
|
e: void 0,
|
|
241
227
|
t: void 0,
|
|
@@ -243,253 +229,140 @@ var D = v(), O = v(), k = v(), A = v(), j = () => {
|
|
|
243
229
|
}), e;
|
|
244
230
|
})();
|
|
245
231
|
};
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
return
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
232
|
+
p(["click"]);
|
|
233
|
+
// src/components/I18nT.tsx
|
|
234
|
+
var he = /*#__PURE__*/ x("<span>"), ge = [
|
|
235
|
+
"keypath",
|
|
236
|
+
"params",
|
|
237
|
+
"tag",
|
|
238
|
+
"plural",
|
|
239
|
+
"defaultValue",
|
|
240
|
+
"html",
|
|
241
|
+
"hideIfEmpty",
|
|
242
|
+
"customPluralRule",
|
|
243
|
+
"number",
|
|
244
|
+
"date",
|
|
245
|
+
"relativeDate",
|
|
246
|
+
"components",
|
|
247
|
+
"children"
|
|
248
|
+
], _e = [
|
|
249
|
+
"innerHTML",
|
|
250
|
+
"textContent",
|
|
251
|
+
"dangerouslySetInnerHTML",
|
|
252
|
+
"prop:innerHTML",
|
|
253
|
+
"prop:textContent"
|
|
254
|
+
], ve = (e) => e == null || typeof e == "boolean";
|
|
255
|
+
function ye(e) {
|
|
256
|
+
let t = Object.create(null);
|
|
257
|
+
for (let n of Object.keys(e ?? {})) {
|
|
258
|
+
let r = e[n];
|
|
259
|
+
r !== void 0 && (t[n] = typeof r == "function" ? r : () => r);
|
|
260
|
+
}
|
|
261
|
+
return t;
|
|
262
|
+
}
|
|
263
|
+
var be = (e) => {
|
|
264
|
+
let t = B(), [n, , r] = N(e, ge, _e), a = E(() => (t.localeAccessor(), l(t, n))), o = () => {
|
|
265
|
+
let { template: e, params: t } = a();
|
|
266
|
+
return i(e, t);
|
|
267
|
+
}, s = E(() => {
|
|
268
|
+
let e = /* @__PURE__ */ new Map();
|
|
269
|
+
return j(() => {
|
|
270
|
+
for (let t of e.values()) t.dispose();
|
|
271
|
+
}), {
|
|
272
|
+
slots: ye(n.components),
|
|
273
|
+
nodes: e,
|
|
274
|
+
owner: k()
|
|
275
|
+
};
|
|
276
|
+
}), c = (e, t) => {
|
|
277
|
+
let { nodes: n, owner: r } = s();
|
|
278
|
+
return n.has(t) || n.set(t, D((t) => ({
|
|
279
|
+
node: e({}),
|
|
280
|
+
dispose: t
|
|
281
|
+
}), r)), n.get(t).node;
|
|
282
|
+
}, d = () => {
|
|
283
|
+
let { template: e, params: t } = a(), { slots: n, nodes: r } = s(), i = /* @__PURE__ */ new Set(), o = I((e, t) => (i.add(t), c(e, t)), e, t, n);
|
|
284
|
+
for (let [e, t] of r) i.has(e) || (t.dispose(), r.delete(e));
|
|
285
|
+
return o;
|
|
286
|
+
}, p = () => {
|
|
287
|
+
let e = n.children;
|
|
288
|
+
return typeof e == "function" ? e({ translation: o() }) : ve(e) ? d() : e;
|
|
289
|
+
}, m = (e) => {
|
|
290
|
+
let t = A(r, e);
|
|
291
|
+
return n.tag ? f(u, _({ get component() {
|
|
292
|
+
return n.tag;
|
|
293
|
+
} }, t)) : (() => {
|
|
294
|
+
var e = he();
|
|
295
|
+
return y(e, t, !1, !1), e;
|
|
296
|
+
})();
|
|
297
|
+
}, h = { get innerHTML() {
|
|
298
|
+
return o();
|
|
299
|
+
} }, v = { get children() {
|
|
300
|
+
return p();
|
|
301
|
+
} };
|
|
302
|
+
return g(() => g(() => a() === null)() ? n.defaultValue : g(() => !!n.html)() ? m(h) : m(v));
|
|
303
|
+
}, xe = (e) => {
|
|
304
|
+
let t = P(R), n = {
|
|
305
|
+
get i18n() {
|
|
306
|
+
let n = e.i18n ?? t?.i18n;
|
|
307
|
+
if (!n) throw Error("[i18n-micro] I18nProvider needs an `i18n` instance or an outer provider.");
|
|
308
|
+
return n;
|
|
309
|
+
},
|
|
310
|
+
get locales() {
|
|
311
|
+
return e.locales ?? t?.locales;
|
|
313
312
|
},
|
|
313
|
+
get defaultLocale() {
|
|
314
|
+
return e.defaultLocale ?? t?.defaultLocale;
|
|
315
|
+
},
|
|
316
|
+
get router() {
|
|
317
|
+
return e.routingStrategy ?? t?.router;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
return w(() => {
|
|
321
|
+
e.locales && n.i18n.addLocaleIso(s(e.locales));
|
|
322
|
+
}), f(R.Provider, {
|
|
323
|
+
value: n,
|
|
314
324
|
get children() {
|
|
315
|
-
return
|
|
316
|
-
get value() {
|
|
317
|
-
return e.locales;
|
|
318
|
-
},
|
|
319
|
-
get children() {
|
|
320
|
-
return [d(() => d(() => !!e.defaultLocale)() && s(k.Provider, {
|
|
321
|
-
get value() {
|
|
322
|
-
return e.defaultLocale;
|
|
323
|
-
},
|
|
324
|
-
get children() {
|
|
325
|
-
return [d(() => d(() => !!e.routingStrategy)() && s(A.Provider, {
|
|
326
|
-
get value() {
|
|
327
|
-
return e.routingStrategy;
|
|
328
|
-
},
|
|
329
|
-
children: t
|
|
330
|
-
})), d(() => !e.routingStrategy && t)];
|
|
331
|
-
}
|
|
332
|
-
})), d(() => !e.defaultLocale && t)];
|
|
333
|
-
}
|
|
334
|
-
})), d(() => !e.locales && t)];
|
|
325
|
+
return e.children;
|
|
335
326
|
}
|
|
336
327
|
});
|
|
337
|
-
},
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
storage;
|
|
328
|
+
}, $ = class extends L {
|
|
329
|
+
revision;
|
|
330
|
+
localeSignal;
|
|
331
|
+
fallbackSignal;
|
|
332
|
+
routeSignal;
|
|
333
|
+
localeAccessor = () => this.locale;
|
|
334
|
+
routeAccessor = () => this.currentRoute;
|
|
345
335
|
constructor(e) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}), this.storage = t, this.store = n({
|
|
353
|
-
locale: e.locale,
|
|
354
|
-
fallbackLocale: e.fallbackLocale || e.locale
|
|
336
|
+
super(e);
|
|
337
|
+
let [t, n] = O(0), [r, i] = O(this.getLocale()), [a, o] = O(this.getFallbackLocale()), [s, c] = O(this.getRoute());
|
|
338
|
+
this.revision = t, this.localeSignal = r, this.fallbackSignal = a, this.routeSignal = s, this.subscribe(() => {
|
|
339
|
+
C(() => {
|
|
340
|
+
i(this.getLocale()), o(this.getFallbackLocale()), c(this.getRoute()), n((e) => e + 1);
|
|
341
|
+
});
|
|
355
342
|
});
|
|
356
|
-
let [r, i] = x(e.locale), [a] = x(e.fallbackLocale || e.locale), [o, s] = x("index");
|
|
357
|
-
if (this._localeSignal = r, this._setLocaleSignal = i, this._fallbackSignal = a, this._routeSignal = o, this._setRouteSignal = s, this.store.subscribe(() => {
|
|
358
|
-
i(this.store.getLocale()), s(this.store.getRoute());
|
|
359
|
-
}), e.messages) for (let [t, n] of Object.entries(e.messages)) this.addTranslations(t, n);
|
|
360
|
-
}
|
|
361
|
-
getLocale() {
|
|
362
|
-
return this.store.getLocale();
|
|
363
|
-
}
|
|
364
|
-
getFallbackLocale() {
|
|
365
|
-
return this.store.getFallbackLocale();
|
|
366
343
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
set locale(e) {
|
|
371
|
-
this.store.setLocale(e), this._setLocaleSignal(e), this.notifyListeners();
|
|
344
|
+
touch() {
|
|
345
|
+
this.revision();
|
|
372
346
|
}
|
|
373
347
|
get locale() {
|
|
374
|
-
return this.
|
|
348
|
+
return this.localeSignal();
|
|
375
349
|
}
|
|
376
|
-
|
|
377
|
-
|
|
350
|
+
set locale(e) {
|
|
351
|
+
super.locale = e;
|
|
378
352
|
}
|
|
379
353
|
get fallbackLocale() {
|
|
380
|
-
return this.
|
|
381
|
-
}
|
|
382
|
-
get currentRoute() {
|
|
383
|
-
return this._routeSignal();
|
|
384
|
-
}
|
|
385
|
-
get routeAccessor() {
|
|
386
|
-
return this._routeSignal;
|
|
387
|
-
}
|
|
388
|
-
setRoute(e) {
|
|
389
|
-
this.store.setRoute(e), this._setRouteSignal(e), this.notifyListeners();
|
|
390
|
-
}
|
|
391
|
-
addTranslations(e, t, n = !0) {
|
|
392
|
-
super.loadTranslationsCore(e, t, n), this.store.notify(), this.notifyListeners();
|
|
393
|
-
}
|
|
394
|
-
addRouteTranslations(e, t, n, r = !0) {
|
|
395
|
-
super.loadRouteTranslationsCore(e, t, n, r), this.store.notify(), this.notifyListeners();
|
|
354
|
+
return this.fallbackSignal();
|
|
396
355
|
}
|
|
397
|
-
|
|
398
|
-
super.
|
|
356
|
+
set fallbackLocale(e) {
|
|
357
|
+
super.fallbackLocale = e;
|
|
399
358
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
listeners = /* @__PURE__ */ new Set();
|
|
404
|
-
subscribe(e) {
|
|
405
|
-
return this.listeners.add(e), () => this.listeners.delete(e);
|
|
406
|
-
}
|
|
407
|
-
getSnapshot() {
|
|
408
|
-
return this.store.getSnapshot();
|
|
409
|
-
}
|
|
410
|
-
notifyListeners() {
|
|
411
|
-
this.listeners.forEach((e) => e());
|
|
359
|
+
get currentRoute() {
|
|
360
|
+
return this.routeSignal();
|
|
412
361
|
}
|
|
413
362
|
};
|
|
414
|
-
function
|
|
415
|
-
return new
|
|
416
|
-
}
|
|
417
|
-
//#endregion
|
|
418
|
-
//#region src/router/adapter.tsx
|
|
419
|
-
function J(e, t, n, r) {
|
|
420
|
-
let i = e.map((e) => e.code), [a, o] = x(r.pathname);
|
|
421
|
-
y(() => {
|
|
422
|
-
o(r.pathname);
|
|
423
|
-
});
|
|
424
|
-
let c = (e, n) => {
|
|
425
|
-
let r = (typeof e == "string" ? e : e.path || "/").split("/").filter(Boolean);
|
|
426
|
-
r.length > 0 && i.includes(r[0]) && r.shift();
|
|
427
|
-
let a = `/${r.join("/")}`;
|
|
428
|
-
return n === t ? a : `/${n}${a === "/" ? "" : a}`;
|
|
429
|
-
};
|
|
430
|
-
return {
|
|
431
|
-
getCurrentPath: () => a(),
|
|
432
|
-
getCurrentPathAccessor: a,
|
|
433
|
-
push: (e) => {
|
|
434
|
-
n(e.path);
|
|
435
|
-
},
|
|
436
|
-
replace: (e) => {
|
|
437
|
-
n(e.path, { replace: !0 });
|
|
438
|
-
},
|
|
439
|
-
resolvePath: (e, t) => c(e, t),
|
|
440
|
-
getRoute: () => ({
|
|
441
|
-
fullPath: a(),
|
|
442
|
-
query: {}
|
|
443
|
-
}),
|
|
444
|
-
linkComponent: ((e) => {
|
|
445
|
-
let { href: t, children: n, class: r, style: i, ...a } = e;
|
|
446
|
-
return s(E, f({
|
|
447
|
-
href: t,
|
|
448
|
-
class: r,
|
|
449
|
-
style: i
|
|
450
|
-
}, a, { children: n }));
|
|
451
|
-
})
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
//#endregion
|
|
455
|
-
//#region src/use-i18n.ts
|
|
456
|
-
function Y(e) {
|
|
457
|
-
let t = j(), n = P(), r = M(), i = N(), a = e?.locales || r, o = e?.defaultLocale || i, s = (e, r) => n?.resolvePath ? n.resolvePath(e, r || t.getLocale()) : e;
|
|
458
|
-
return {
|
|
459
|
-
instance: t,
|
|
460
|
-
locale: b(() => t.localeAccessor()),
|
|
461
|
-
getLocales: () => a,
|
|
462
|
-
defaultLocale: () => o,
|
|
463
|
-
getLocaleName: () => a.find((e) => e.code === t.localeAccessor())?.displayName || null,
|
|
464
|
-
localeRoute: s,
|
|
465
|
-
localePath: (e, t) => {
|
|
466
|
-
let n = s(e, t);
|
|
467
|
-
return typeof n == "string" ? n : n.path || "/";
|
|
468
|
-
},
|
|
469
|
-
switchLocale: (e) => {
|
|
470
|
-
if (t.locale = e, n) {
|
|
471
|
-
let t = n.getCurrentPath(), r = s(t, e);
|
|
472
|
-
n.push(typeof r == "string" ? { path: r } : { path: r.path || "/" });
|
|
473
|
-
}
|
|
474
|
-
},
|
|
475
|
-
t: t.t.bind(t),
|
|
476
|
-
ts: t.ts.bind(t),
|
|
477
|
-
tc: t.tc.bind(t),
|
|
478
|
-
tn: t.tn.bind(t),
|
|
479
|
-
td: t.td.bind(t),
|
|
480
|
-
tdr: t.tdr.bind(t),
|
|
481
|
-
has: t.has.bind(t),
|
|
482
|
-
setRoute: t.setRoute.bind(t),
|
|
483
|
-
getRoute: t.getRoute.bind(t),
|
|
484
|
-
getLocale: () => t.getLocale(),
|
|
485
|
-
addTranslations: t.addTranslations.bind(t),
|
|
486
|
-
addRouteTranslations: t.addRouteTranslations.bind(t),
|
|
487
|
-
resolveTranslations: t.resolveTranslations.bind(t),
|
|
488
|
-
setTranslation: t.setTranslation.bind(t),
|
|
489
|
-
clearCache: t.clearCache.bind(t)
|
|
490
|
-
};
|
|
363
|
+
function Se(e) {
|
|
364
|
+
return new $(e);
|
|
491
365
|
}
|
|
492
|
-
|
|
493
|
-
export { t as FormatService, D as I18nContext, k as I18nDefaultLocaleContext, I as I18nGroup, z as I18nLink, O as I18nLocalesContext, G as I18nProvider, A as I18nRouterContext, U as I18nSwitcher, W as I18nT, K as SolidI18n, q as createI18n, J as createSolidRouterAdapter, r as defaultPlural, i as interpolate, Y as useI18n, j as useI18nContext, N as useI18nDefaultLocale, M as useI18nLocales, P as useI18nRouter };
|
|
366
|
+
export { e as FormatService, R as I18nContext, W as I18nGroup, Z as I18nLink, xe as I18nProvider, me as I18nSwitcher, be as I18nT, $ as SolidI18n, Se as createI18n, t as defaultPlural, r as interpolate, q as useI18n, B as useI18nContext, V as useI18nDefaultLocale, ne as useI18nLocales, H as useI18nRouter };
|
|
494
367
|
|
|
495
368
|
//# sourceMappingURL=index.mjs.map
|