@i18n-micro/preact 1.2.0 → 1.2.3
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +274 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.mjs +260 -251
- package/dist/index.mjs.map +1 -1
- package/package.json +50 -24
package/dist/index.mjs
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { BaseI18n as
|
|
2
|
-
import { FormatService as
|
|
3
|
-
import { createContext as
|
|
4
|
-
import { useContext as H, useState as W, useEffect as z, useRef as
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
if (!
|
|
1
|
+
import { BaseI18n as ut, createReactiveI18nStore as dt } from "@i18n-micro/core";
|
|
2
|
+
import { FormatService as Tt, defaultPlural as Nt, interpolate as Et } from "@i18n-micro/core";
|
|
3
|
+
import { createContext as A, h as p, Fragment as ft } from "preact";
|
|
4
|
+
import { useContext as H, useState as W, useEffect as z, useRef as pt } from "preact/hooks";
|
|
5
|
+
const F = A(null), O = A(null), V = A(null), q = A(null), K = () => {
|
|
6
|
+
const s = H(F);
|
|
7
|
+
if (!s)
|
|
8
8
|
throw new Error("[i18n-micro] I18nContext not found. Make sure I18nProvider is used.");
|
|
9
|
-
return
|
|
10
|
-
}, U = () => H(
|
|
11
|
-
function
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
{ value:
|
|
15
|
-
t ?
|
|
16
|
-
|
|
9
|
+
return s;
|
|
10
|
+
}, U = () => H(O), ht = () => H(V), M = () => H(q);
|
|
11
|
+
function wt({ i18n: s, locales: t, defaultLocale: o, routingStrategy: e, children: r }) {
|
|
12
|
+
return p(
|
|
13
|
+
F.Provider,
|
|
14
|
+
{ value: s },
|
|
15
|
+
t ? p(
|
|
16
|
+
O.Provider,
|
|
17
17
|
{ value: t },
|
|
18
|
-
|
|
18
|
+
o ? p(
|
|
19
19
|
V.Provider,
|
|
20
|
-
{ value:
|
|
21
|
-
e ?
|
|
22
|
-
) :
|
|
23
|
-
) :
|
|
20
|
+
{ value: o },
|
|
21
|
+
e ? p(q.Provider, { value: e }, r) : r
|
|
22
|
+
) : r
|
|
23
|
+
) : r
|
|
24
24
|
);
|
|
25
25
|
}
|
|
26
|
-
const
|
|
27
|
-
const t = K(),
|
|
26
|
+
const $ = (s) => {
|
|
27
|
+
const t = K(), o = M(), e = U(), r = ht(), [, L] = W(0);
|
|
28
28
|
z(() => t.subscribe(() => {
|
|
29
|
-
|
|
29
|
+
L((d) => d + 1);
|
|
30
30
|
}), [t]);
|
|
31
|
-
const
|
|
32
|
-
if (t.locale =
|
|
33
|
-
const d =
|
|
34
|
-
|
|
31
|
+
const m = s?.locales || e || [], h = s?.defaultLocale || r || t.locale, u = (a, d) => o?.resolvePath ? o.resolvePath(a, d || t.locale) : a, c = (a) => {
|
|
32
|
+
if (t.locale = a, o) {
|
|
33
|
+
const d = o.getCurrentPath(), f = u(d, a);
|
|
34
|
+
o.push(typeof f == "string" ? { path: f } : { path: f.path || "/" });
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
return {
|
|
@@ -53,20 +53,20 @@ const j = (a) => {
|
|
|
53
53
|
get currentRoute() {
|
|
54
54
|
return t.currentRoute;
|
|
55
55
|
},
|
|
56
|
-
setLocale: (
|
|
57
|
-
t.locale =
|
|
56
|
+
setLocale: (a) => {
|
|
57
|
+
t.locale = a;
|
|
58
58
|
},
|
|
59
59
|
// Route management
|
|
60
60
|
setRoute: t.setRoute.bind(t),
|
|
61
61
|
getRoute: t.getRoute.bind(t),
|
|
62
|
-
getLocales: () =>
|
|
63
|
-
defaultLocale: () =>
|
|
64
|
-
getLocaleName: () =>
|
|
62
|
+
getLocales: () => m,
|
|
63
|
+
defaultLocale: () => h,
|
|
64
|
+
getLocaleName: () => m.find((d) => d.code === t.locale)?.displayName || null,
|
|
65
65
|
// Router methods (always available, but navigation handled by components)
|
|
66
|
-
switchLocale:
|
|
66
|
+
switchLocale: c,
|
|
67
67
|
localeRoute: u,
|
|
68
|
-
localePath: (
|
|
69
|
-
const f = u(
|
|
68
|
+
localePath: (a, d) => {
|
|
69
|
+
const f = u(a, d);
|
|
70
70
|
return typeof f == "string" ? f : f.path || "/";
|
|
71
71
|
},
|
|
72
72
|
// Translation management
|
|
@@ -74,117 +74,122 @@ const j = (a) => {
|
|
|
74
74
|
addRouteTranslations: t.addRouteTranslations.bind(t),
|
|
75
75
|
clearCache: t.clearCache.bind(t)
|
|
76
76
|
};
|
|
77
|
-
},
|
|
78
|
-
const { prefix: t, groupClass:
|
|
79
|
-
const f =
|
|
77
|
+
}, Pt = (s) => {
|
|
78
|
+
const { prefix: t, groupClass: o, children: e, ...r } = s, { t: L, getRoute: m } = $(), h = (a, d) => {
|
|
79
|
+
const f = L(`${t}.${a}`, d, void 0, m());
|
|
80
80
|
return typeof f == "string" ? f : String(f);
|
|
81
|
-
}, u = ["i18n-group",
|
|
82
|
-
return
|
|
83
|
-
},
|
|
84
|
-
const t =
|
|
85
|
-
if (
|
|
81
|
+
}, u = ["i18n-group", o].filter(Boolean).join(" "), c = typeof e == "function" ? e({ prefix: t, t: h }) : e;
|
|
82
|
+
return p("div", { ...r, className: u }, c);
|
|
83
|
+
}, St = (s) => {
|
|
84
|
+
const t = $(), o = M(), { to: e, activeStyle: r, localeRoute: L, children: m, ...h } = s, u = L || t.localeRoute, c = () => typeof e == "string" ? /^(?:https?:\/\/|\/\/|[a-zA-Z0-9-]+\.[a-zA-Z]{2,})|tel:|mailto:/.test(e) : !1, a = () => {
|
|
85
|
+
if (c() && typeof e == "string")
|
|
86
86
|
return /^https?:\/\//.test(e) ? e : `https://${e}`;
|
|
87
87
|
}, d = () => {
|
|
88
|
-
if (
|
|
88
|
+
if (c())
|
|
89
89
|
return typeof e == "string" ? e : e?.path || "/";
|
|
90
90
|
if (u) {
|
|
91
|
-
const
|
|
92
|
-
return typeof
|
|
91
|
+
const v = u(e);
|
|
92
|
+
return typeof v == "string" ? v : v.path || "/";
|
|
93
93
|
}
|
|
94
|
-
if (!
|
|
94
|
+
if (!o?.resolvePath)
|
|
95
95
|
return typeof e == "string" ? e : e.path || "/";
|
|
96
|
-
const
|
|
97
|
-
return typeof
|
|
98
|
-
},
|
|
99
|
-
if (
|
|
96
|
+
const l = o.resolvePath(e, t.locale);
|
|
97
|
+
return typeof l == "string" ? l : l.path || "/";
|
|
98
|
+
}, k = (() => {
|
|
99
|
+
if (c() || !o)
|
|
100
100
|
return !1;
|
|
101
|
-
const
|
|
102
|
-
return !!(
|
|
103
|
-
})() ?
|
|
104
|
-
|
|
101
|
+
const l = o.getCurrentPath(), v = d(), w = l.replace(/\/$/, ""), g = v.replace(/\/$/, "");
|
|
102
|
+
return !!(w === g || w.startsWith(`${g}/`));
|
|
103
|
+
})() ? r || {} : {}, x = d(), T = (l) => {
|
|
104
|
+
s.onClick && s.onClick(l), !l.defaultPrevented && !l.button && !l.metaKey && !l.ctrlKey && o && !c() && (l.preventDefault(), o.push({ path: x }));
|
|
105
105
|
};
|
|
106
|
-
if (
|
|
107
|
-
return
|
|
106
|
+
if (c())
|
|
107
|
+
return p(
|
|
108
108
|
"a",
|
|
109
109
|
{
|
|
110
|
-
...
|
|
111
|
-
href:
|
|
112
|
-
style:
|
|
110
|
+
...h,
|
|
111
|
+
href: a(),
|
|
112
|
+
style: k,
|
|
113
113
|
target: "_blank",
|
|
114
114
|
rel: "noopener noreferrer"
|
|
115
115
|
},
|
|
116
|
-
|
|
116
|
+
m
|
|
117
117
|
);
|
|
118
|
-
if (
|
|
119
|
-
const
|
|
120
|
-
if (typeof
|
|
121
|
-
return
|
|
122
|
-
|
|
118
|
+
if (o?.linkComponent) {
|
|
119
|
+
const l = o.linkComponent;
|
|
120
|
+
if (typeof l == "string")
|
|
121
|
+
return p(
|
|
122
|
+
l,
|
|
123
123
|
{
|
|
124
|
-
...
|
|
124
|
+
...h,
|
|
125
125
|
href: x,
|
|
126
|
-
style:
|
|
126
|
+
style: k
|
|
127
127
|
},
|
|
128
|
-
|
|
128
|
+
m
|
|
129
129
|
);
|
|
130
|
-
const
|
|
131
|
-
...
|
|
130
|
+
const v = l, w = {
|
|
131
|
+
...h,
|
|
132
132
|
href: x,
|
|
133
|
-
style:
|
|
133
|
+
style: k
|
|
134
134
|
};
|
|
135
|
-
return
|
|
135
|
+
return p(v, w, m);
|
|
136
136
|
}
|
|
137
|
-
return
|
|
137
|
+
return p(
|
|
138
138
|
"a",
|
|
139
139
|
{
|
|
140
|
-
...
|
|
140
|
+
...h,
|
|
141
141
|
href: x,
|
|
142
|
-
style:
|
|
143
|
-
onClick:
|
|
142
|
+
style: k,
|
|
143
|
+
onClick: T
|
|
144
144
|
},
|
|
145
|
-
|
|
145
|
+
m
|
|
146
146
|
);
|
|
147
|
-
}
|
|
147
|
+
};
|
|
148
|
+
function gt(s, t) {
|
|
149
|
+
return typeof s == "function" ? s() : typeof s == "string" ? s : t;
|
|
150
|
+
}
|
|
151
|
+
const kt = (s) => {
|
|
148
152
|
const {
|
|
149
153
|
locales: t,
|
|
150
|
-
currentLocale:
|
|
154
|
+
currentLocale: o,
|
|
151
155
|
getLocaleName: e,
|
|
152
|
-
switchLocale:
|
|
153
|
-
localeRoute:
|
|
154
|
-
customLabels:
|
|
155
|
-
customWrapperStyle:
|
|
156
|
+
switchLocale: r,
|
|
157
|
+
localeRoute: L,
|
|
158
|
+
customLabels: m = {},
|
|
159
|
+
customWrapperStyle: h,
|
|
156
160
|
customButtonStyle: u,
|
|
157
|
-
customDropdownStyle:
|
|
158
|
-
customItemStyle:
|
|
161
|
+
customDropdownStyle: c,
|
|
162
|
+
customItemStyle: a,
|
|
159
163
|
customLinkStyle: d,
|
|
160
164
|
customActiveLinkStyle: f,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
customDisabledLinkStyle: k = {},
|
|
166
|
+
customIconStyle: x,
|
|
167
|
+
...T
|
|
168
|
+
} = s, l = $(), v = K(), w = M(), g = U(), [P, y] = W(!1), I = pt(null), N = t || g || l.getLocales() || [], S = N.filter((n) => !n.disabled), i = gt(o, l.locale), b = N.some((n) => n.code === i && n.disabled), E = e ? e() : l.getLocaleName(), B = (n) => {
|
|
169
|
+
n && (n.stopPropagation(), n.preventDefault()), y(!P);
|
|
170
|
+
}, j = (n) => m[n.code] || n.displayName || n.code, _ = () => {
|
|
171
|
+
const n = S.find((R) => R.code === i);
|
|
172
|
+
return n ? j(n) : E || i;
|
|
173
|
+
}, Z = (n) => {
|
|
174
|
+
if (y(!1), r) {
|
|
175
|
+
r(n);
|
|
171
176
|
return;
|
|
172
177
|
}
|
|
173
|
-
if (
|
|
178
|
+
if (v.locale = n, !w)
|
|
174
179
|
return;
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
return typeof
|
|
178
|
-
})() :
|
|
179
|
-
const
|
|
180
|
-
return typeof
|
|
181
|
-
})() :
|
|
182
|
-
|
|
183
|
-
},
|
|
180
|
+
const R = w.getCurrentPath(), D = s.localeRoute ? (() => {
|
|
181
|
+
const C = s.localeRoute(R, n);
|
|
182
|
+
return typeof C == "string" ? C : C.path || "/";
|
|
183
|
+
})() : w?.resolvePath ? (() => {
|
|
184
|
+
const C = w.resolvePath(R, n);
|
|
185
|
+
return typeof C == "string" ? C : C.path || "/";
|
|
186
|
+
})() : R;
|
|
187
|
+
w.push({ path: D });
|
|
188
|
+
}, G = {
|
|
184
189
|
position: "relative",
|
|
185
190
|
display: "inline-block",
|
|
186
191
|
verticalAlign: "middle"
|
|
187
|
-
},
|
|
192
|
+
}, J = {
|
|
188
193
|
padding: "4px 12px",
|
|
189
194
|
fontSize: "16px",
|
|
190
195
|
cursor: "pointer",
|
|
@@ -194,7 +199,7 @@ const j = (a) => {
|
|
|
194
199
|
display: "flex",
|
|
195
200
|
alignItems: "center",
|
|
196
201
|
justifyContent: "space-between"
|
|
197
|
-
},
|
|
202
|
+
}, Q = {
|
|
198
203
|
position: "absolute",
|
|
199
204
|
top: "100%",
|
|
200
205
|
left: "0",
|
|
@@ -206,237 +211,241 @@ const j = (a) => {
|
|
|
206
211
|
margin: "4px 0 0 0",
|
|
207
212
|
minWidth: "150px",
|
|
208
213
|
boxShadow: "0 2px 8px rgba(0,0,0,0.15)"
|
|
209
|
-
},
|
|
214
|
+
}, X = {
|
|
210
215
|
margin: "0",
|
|
211
216
|
padding: "0"
|
|
212
|
-
},
|
|
217
|
+
}, Y = {
|
|
213
218
|
display: "block",
|
|
214
219
|
padding: "8px 12px",
|
|
215
220
|
color: "#333",
|
|
216
221
|
textDecoration: "none",
|
|
217
222
|
transition: "background-color 0.3s ease",
|
|
218
223
|
cursor: "pointer"
|
|
219
|
-
},
|
|
224
|
+
}, tt = {
|
|
220
225
|
fontWeight: "bold",
|
|
221
|
-
color: "#007bff"
|
|
222
|
-
|
|
226
|
+
color: "#007bff",
|
|
227
|
+
cursor: "not-allowed"
|
|
228
|
+
}, et = {
|
|
223
229
|
marginLeft: "8px",
|
|
224
230
|
display: "inline-block",
|
|
225
231
|
transition: "transform 0.3s ease"
|
|
226
|
-
},
|
|
232
|
+
}, nt = {
|
|
227
233
|
transform: "rotate(180deg)"
|
|
228
234
|
};
|
|
229
235
|
z(() => {
|
|
230
|
-
if (!
|
|
231
|
-
const
|
|
232
|
-
if (!
|
|
233
|
-
const D =
|
|
234
|
-
if (!D || !
|
|
235
|
-
const
|
|
236
|
-
!
|
|
236
|
+
if (!P) return;
|
|
237
|
+
const n = (R) => {
|
|
238
|
+
if (!P) return;
|
|
239
|
+
const D = R.target;
|
|
240
|
+
if (!D || !I.current) return;
|
|
241
|
+
const C = I.current.contains(D), it = D.closest(".i18n-switcher-button") !== null;
|
|
242
|
+
!C && !it && y(!1);
|
|
237
243
|
};
|
|
238
|
-
return document.addEventListener("click",
|
|
239
|
-
document.removeEventListener("click",
|
|
244
|
+
return document.addEventListener("click", n), () => {
|
|
245
|
+
document.removeEventListener("click", n);
|
|
240
246
|
};
|
|
241
|
-
}, [
|
|
242
|
-
const
|
|
243
|
-
...
|
|
244
|
-
...
|
|
245
|
-
...
|
|
246
|
-
}, at =
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
247
|
+
}, [P]);
|
|
248
|
+
const ot = { ...G, ...h }, rt = {
|
|
249
|
+
...J,
|
|
250
|
+
...u,
|
|
251
|
+
...b ? k : {}
|
|
252
|
+
}, st = { ...Q, ...c }, at = { ...X, ...a }, lt = {
|
|
253
|
+
...et,
|
|
254
|
+
...P ? nt : {},
|
|
255
|
+
...x
|
|
256
|
+
}, ct = S.map((n) => {
|
|
257
|
+
const R = n.code === i, D = {
|
|
258
|
+
...Y,
|
|
259
|
+
...R ? tt : {},
|
|
250
260
|
...d,
|
|
251
|
-
...
|
|
261
|
+
...R ? f : {},
|
|
252
262
|
width: "100%",
|
|
253
263
|
textAlign: "left",
|
|
254
264
|
border: "none",
|
|
255
265
|
background: "transparent"
|
|
256
266
|
};
|
|
257
|
-
return
|
|
267
|
+
return p(
|
|
258
268
|
"li",
|
|
259
269
|
{
|
|
260
|
-
key:
|
|
261
|
-
style:
|
|
270
|
+
key: n.code,
|
|
271
|
+
style: at
|
|
262
272
|
},
|
|
263
|
-
|
|
273
|
+
p(
|
|
264
274
|
"button",
|
|
265
275
|
{
|
|
266
276
|
type: "button",
|
|
267
|
-
className: `switcher-locale-${
|
|
277
|
+
className: `switcher-locale-${n.code}`,
|
|
268
278
|
style: D,
|
|
269
|
-
onClick: (
|
|
270
|
-
|
|
279
|
+
onClick: (C) => {
|
|
280
|
+
C.preventDefault(), C.stopPropagation(), Z(n.code);
|
|
271
281
|
}
|
|
272
282
|
},
|
|
273
|
-
|
|
283
|
+
j(n)
|
|
274
284
|
)
|
|
275
285
|
);
|
|
276
286
|
});
|
|
277
|
-
return
|
|
287
|
+
return p(
|
|
278
288
|
"div",
|
|
279
289
|
{
|
|
280
|
-
ref:
|
|
290
|
+
ref: I,
|
|
281
291
|
className: "i18n-switcher-wrapper",
|
|
282
|
-
style:
|
|
283
|
-
...
|
|
292
|
+
style: ot,
|
|
293
|
+
...T
|
|
284
294
|
},
|
|
285
|
-
|
|
295
|
+
p(
|
|
286
296
|
"button",
|
|
287
297
|
{
|
|
288
298
|
type: "button",
|
|
289
299
|
className: "i18n-switcher-button",
|
|
290
|
-
style:
|
|
291
|
-
onClick: (
|
|
292
|
-
|
|
300
|
+
style: rt,
|
|
301
|
+
onClick: (n) => {
|
|
302
|
+
n.preventDefault(), n.stopPropagation(), B(n);
|
|
293
303
|
},
|
|
294
|
-
|
|
295
|
-
|
|
304
|
+
"aria-haspopup": "true",
|
|
305
|
+
"aria-expanded": P
|
|
296
306
|
},
|
|
297
|
-
|
|
298
|
-
|
|
307
|
+
p("span", null, _()),
|
|
308
|
+
p("span", { style: lt }, "▼")
|
|
299
309
|
),
|
|
300
|
-
|
|
310
|
+
P ? p(
|
|
301
311
|
"ul",
|
|
302
312
|
{
|
|
303
313
|
className: "i18n-switcher-dropdown",
|
|
304
|
-
style:
|
|
314
|
+
style: st
|
|
305
315
|
},
|
|
306
|
-
...
|
|
316
|
+
...ct
|
|
307
317
|
) : null
|
|
308
318
|
);
|
|
309
|
-
},
|
|
310
|
-
const { t, tc:
|
|
319
|
+
}, Ct = (s) => {
|
|
320
|
+
const { t, tc: o, tn: e, td: r, tdr: L, locale: m, getRoute: h } = $(), {
|
|
311
321
|
keypath: u,
|
|
312
|
-
params:
|
|
313
|
-
tag:
|
|
322
|
+
params: c,
|
|
323
|
+
tag: a = "span",
|
|
314
324
|
plural: d,
|
|
315
325
|
defaultValue: f,
|
|
316
|
-
html:
|
|
326
|
+
html: k = !1,
|
|
317
327
|
hideIfEmpty: x = !1,
|
|
318
|
-
customPluralRule:
|
|
319
|
-
number:
|
|
320
|
-
date:
|
|
321
|
-
relativeDate:
|
|
322
|
-
...
|
|
323
|
-
} =
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
328
|
+
customPluralRule: T,
|
|
329
|
+
number: l,
|
|
330
|
+
date: v,
|
|
331
|
+
relativeDate: w,
|
|
332
|
+
...g
|
|
333
|
+
} = s, P = h(), y = (S, i, b) => p(
|
|
334
|
+
S,
|
|
335
|
+
i,
|
|
336
|
+
b
|
|
327
337
|
);
|
|
328
|
-
if (
|
|
329
|
-
const
|
|
330
|
-
return
|
|
338
|
+
if (l !== void 0) {
|
|
339
|
+
const S = Number(l), i = e(S), b = t(u, { number: i, ...c || {} }, void 0, P), E = typeof b == "string" ? b : String(b);
|
|
340
|
+
return k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: E } }, void 0) : y(a, g, E);
|
|
331
341
|
}
|
|
332
|
-
if (
|
|
333
|
-
const
|
|
334
|
-
return
|
|
342
|
+
if (v !== void 0) {
|
|
343
|
+
const S = r(v), i = t(u, { date: S, ...c || {} }, void 0, P), b = typeof i == "string" ? i : String(i);
|
|
344
|
+
return k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: b } }, void 0) : y(a, g, b);
|
|
335
345
|
}
|
|
336
|
-
if (
|
|
337
|
-
const
|
|
338
|
-
return
|
|
346
|
+
if (w !== void 0) {
|
|
347
|
+
const S = L(w), i = t(u, { relativeDate: S, ...c || {} }, void 0, P), b = typeof i == "string" ? i : String(i);
|
|
348
|
+
return k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: b } }, void 0) : y(a, g, b);
|
|
339
349
|
}
|
|
340
350
|
if (d !== void 0) {
|
|
341
|
-
const
|
|
342
|
-
let
|
|
343
|
-
return
|
|
351
|
+
const S = Number.parseInt(d.toString(), 10);
|
|
352
|
+
let i;
|
|
353
|
+
return T ? i = T(
|
|
344
354
|
u,
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
(
|
|
349
|
-
const
|
|
350
|
-
return typeof
|
|
355
|
+
S,
|
|
356
|
+
c || {},
|
|
357
|
+
m,
|
|
358
|
+
(E, B, j) => {
|
|
359
|
+
const _ = t(E, B, j, P);
|
|
360
|
+
return typeof _ == "string" ? _ : String(_);
|
|
351
361
|
}
|
|
352
|
-
) || "" :
|
|
362
|
+
) || "" : i = o(u, { count: S, ...c || {} }, f), k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: i } }, void 0) : y(a, g, i);
|
|
353
363
|
}
|
|
354
|
-
const
|
|
355
|
-
return x && !N.trim() ? f ?
|
|
364
|
+
const I = t(u, c, f, P), N = typeof I == "string" ? I : String(I);
|
|
365
|
+
return x && !N.trim() ? f ? p(ft, null, f) : null : k ? y(a, { ...g, dangerouslySetInnerHTML: { __html: N } }, void 0) : y(a, g, N);
|
|
356
366
|
};
|
|
357
|
-
class
|
|
358
|
-
|
|
359
|
-
_fallbackLocale;
|
|
360
|
-
_currentRoute = "index";
|
|
361
|
-
listeners = /* @__PURE__ */ new Set();
|
|
362
|
-
revision = 0;
|
|
367
|
+
class mt extends ut {
|
|
368
|
+
store;
|
|
363
369
|
storage;
|
|
364
370
|
constructor(t) {
|
|
365
|
-
const
|
|
371
|
+
const o = {
|
|
366
372
|
translations: /* @__PURE__ */ new Map()
|
|
367
373
|
};
|
|
368
374
|
if (super({
|
|
369
|
-
storage:
|
|
375
|
+
storage: o,
|
|
370
376
|
plural: t.plural,
|
|
371
377
|
missingWarn: t.missingWarn,
|
|
372
378
|
missingHandler: t.missingHandler
|
|
373
|
-
}), this.storage =
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
notify() {
|
|
380
|
-
this.revision++, this.listeners.forEach((t) => t());
|
|
379
|
+
}), this.storage = o, this.store = dt({
|
|
380
|
+
locale: t.locale,
|
|
381
|
+
fallbackLocale: t.fallbackLocale || t.locale
|
|
382
|
+
}), t.messages)
|
|
383
|
+
for (const [e, r] of Object.entries(t.messages))
|
|
384
|
+
this.helper.loadTranslations(e, r);
|
|
381
385
|
}
|
|
386
|
+
subscribe = (t) => this.store.subscribe(t);
|
|
387
|
+
getSnapshot = () => this.store.getSnapshot();
|
|
382
388
|
get locale() {
|
|
383
|
-
return this.
|
|
389
|
+
return this.store.getLocale();
|
|
384
390
|
}
|
|
385
391
|
set locale(t) {
|
|
386
|
-
this.
|
|
392
|
+
this.store.setLocale(t);
|
|
387
393
|
}
|
|
388
394
|
get fallbackLocale() {
|
|
389
|
-
return this.
|
|
395
|
+
return this.store.getFallbackLocale();
|
|
390
396
|
}
|
|
391
397
|
set fallbackLocale(t) {
|
|
392
|
-
this.
|
|
398
|
+
this.store.setFallbackLocale(t);
|
|
393
399
|
}
|
|
394
400
|
get currentRoute() {
|
|
395
|
-
return this.
|
|
401
|
+
return this.store.getRoute();
|
|
396
402
|
}
|
|
397
403
|
setRoute(t) {
|
|
398
|
-
this.
|
|
404
|
+
this.store.setRoute(t);
|
|
399
405
|
}
|
|
400
406
|
getLocale() {
|
|
401
|
-
return this.
|
|
407
|
+
return this.store.getLocale();
|
|
402
408
|
}
|
|
403
409
|
getFallbackLocale() {
|
|
404
|
-
return this.
|
|
410
|
+
return this.store.getFallbackLocale();
|
|
405
411
|
}
|
|
406
412
|
getRoute() {
|
|
407
|
-
return this.
|
|
413
|
+
return this.store.getRoute();
|
|
408
414
|
}
|
|
409
|
-
addTranslations(t,
|
|
410
|
-
super.loadTranslationsCore(t,
|
|
415
|
+
addTranslations(t, o, e = !0) {
|
|
416
|
+
super.loadTranslationsCore(t, o, e), this.store.notify();
|
|
411
417
|
}
|
|
412
|
-
addRouteTranslations(t,
|
|
413
|
-
super.loadRouteTranslationsCore(t,
|
|
418
|
+
addRouteTranslations(t, o, e, r = !0) {
|
|
419
|
+
super.loadRouteTranslationsCore(t, o, e, r), this.store.notify();
|
|
414
420
|
}
|
|
415
421
|
clearCache() {
|
|
416
|
-
super.clearCache(), this.notify();
|
|
422
|
+
super.clearCache(), this.store.notify();
|
|
423
|
+
}
|
|
424
|
+
onTranslationsChanged() {
|
|
425
|
+
this.store.notify();
|
|
417
426
|
}
|
|
418
427
|
}
|
|
419
|
-
function
|
|
420
|
-
return new
|
|
428
|
+
function Rt(s) {
|
|
429
|
+
return new mt(s);
|
|
421
430
|
}
|
|
422
|
-
function
|
|
423
|
-
const
|
|
424
|
-
const
|
|
425
|
-
u !== void 0 &&
|
|
426
|
-
const
|
|
427
|
-
return
|
|
431
|
+
function yt(s, t) {
|
|
432
|
+
const o = s.map((r) => r.code), e = (r, L) => {
|
|
433
|
+
const h = (typeof r == "string" ? r : r.path || "/").split("/").filter(Boolean), u = h[0];
|
|
434
|
+
u !== void 0 && o.includes(u) && h.shift();
|
|
435
|
+
const c = `/${h.join("/")}`;
|
|
436
|
+
return L === t ? c : `/${L}${c === "/" ? "" : c}`;
|
|
428
437
|
};
|
|
429
438
|
return {
|
|
430
439
|
// Просто рендерим <a>, навигацию перехватит onClick в I18nLink
|
|
431
440
|
linkComponent: void 0,
|
|
432
441
|
getCurrentPath: () => typeof window < "u" ? window.location.pathname : "/",
|
|
433
|
-
push: (
|
|
434
|
-
typeof window < "u" && (window.history.pushState({}, "",
|
|
442
|
+
push: (r) => {
|
|
443
|
+
typeof window < "u" && (window.history.pushState({}, "", r.path), window.dispatchEvent(new Event("popstate")));
|
|
435
444
|
},
|
|
436
|
-
replace: (
|
|
437
|
-
typeof window < "u" && (window.history.replaceState({}, "",
|
|
445
|
+
replace: (r) => {
|
|
446
|
+
typeof window < "u" && (window.history.replaceState({}, "", r.path), window.dispatchEvent(new Event("popstate")));
|
|
438
447
|
},
|
|
439
|
-
resolvePath: (
|
|
448
|
+
resolvePath: (r, L) => e(r, L),
|
|
440
449
|
getRoute: () => typeof window < "u" ? {
|
|
441
450
|
fullPath: window.location.pathname + window.location.search,
|
|
442
451
|
query: Object.fromEntries(new URLSearchParams(window.location.search))
|
|
@@ -446,27 +455,27 @@ function pt(a, t) {
|
|
|
446
455
|
}
|
|
447
456
|
};
|
|
448
457
|
}
|
|
449
|
-
const
|
|
458
|
+
const xt = yt;
|
|
450
459
|
export {
|
|
451
|
-
|
|
452
|
-
|
|
460
|
+
Tt as FormatService,
|
|
461
|
+
F as I18nContext,
|
|
453
462
|
V as I18nDefaultLocaleContext,
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
463
|
+
Pt as I18nGroup,
|
|
464
|
+
St as I18nLink,
|
|
465
|
+
O as I18nLocalesContext,
|
|
466
|
+
wt as I18nProvider,
|
|
458
467
|
q as I18nRouterContext,
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
+
kt as I18nSwitcher,
|
|
469
|
+
Ct as I18nT,
|
|
470
|
+
mt as PreactI18n,
|
|
471
|
+
yt as createBrowserHistoryAdapter,
|
|
472
|
+
Rt as createI18n,
|
|
473
|
+
xt as createPreactRouterAdapter,
|
|
474
|
+
Nt as defaultPlural,
|
|
475
|
+
Et as interpolate,
|
|
476
|
+
$ as useI18n,
|
|
468
477
|
K as useI18nContext,
|
|
469
|
-
|
|
478
|
+
ht as useI18nDefaultLocale,
|
|
470
479
|
U as useI18nLocales,
|
|
471
480
|
M as useI18nRouter
|
|
472
481
|
};
|