@i18n-micro/core 1.0.28 → 1.1.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/dist/index.mjs CHANGED
@@ -1,155 +1,107 @@
1
- const $ = {}, b = {}, L = [], T = {};
2
- function N(o) {
3
- return Array.isArray(o) || typeof o == "object" && o !== null ? JSON.parse(JSON.stringify(o)) : o;
4
- }
5
- function v(o, e) {
6
- let t = o;
7
- if (o === null || typeof e != "string")
8
- return null;
9
- if (o[e])
10
- t = o[e];
11
- else {
12
- const r = e.toString().split(".");
13
- for (const n of r)
14
- if (t && typeof t == "object" && n in t)
15
- t = t[n];
16
- else
17
- return null;
18
- }
19
- return typeof t == "object" && t !== null ? N(t) : t ?? null;
20
- }
21
- function p(o) {
22
- return typeof o == "object" && o !== null && "value" in o ? o.value : o;
23
- }
24
- function d(o, e, t) {
25
- const r = p(o);
26
- r[e] = t;
27
- }
28
- function g(o, e) {
29
- return p(o)[e];
1
+ function d(o, e) {
2
+ if (!o || typeof e != "string") return null;
3
+ if (e in o) {
4
+ const s = o[e];
5
+ return s;
6
+ }
7
+ const t = e.split(".");
8
+ let r = o;
9
+ for (const s of t)
10
+ if (r && typeof r == "object" && s in r)
11
+ r = r[s];
12
+ else
13
+ return null;
14
+ return r ?? null;
30
15
  }
31
- function w(o) {
32
- const e = o?.generalLocaleCache ?? $, t = o?.routeLocaleCache ?? b, r = o?.dynamicTranslationsCaches ?? L, n = o?.serverTranslationCache ?? T;
16
+ function C(o) {
17
+ const e = o?.translations ?? /* @__PURE__ */ new Map();
33
18
  return {
34
- hasCache(s, i) {
35
- const a = `${s}:${i}`;
36
- return (g(n, a) ?? /* @__PURE__ */ new Map()).size > 0;
19
+ hasCache(t, r) {
20
+ const s = `${t}:${r}`;
21
+ return e.has(s) || e.has(t);
37
22
  },
38
- getCache(s, i) {
39
- const a = `${s}:${i}`;
40
- return g(n, a);
23
+ getCache(t, r) {
24
+ const s = `${t}:${r}`;
25
+ return e.get(s);
41
26
  },
42
- setCache(s, i, a) {
43
- const l = `${s}:${i}`;
44
- d(n, l, a);
27
+ setCache(t, r, s) {
45
28
  },
46
- mergeTranslation(s, i, a, l = !1) {
47
- const c = `${s}:${i}`, u = g(t, c);
48
- (u || l) && d(t, c, {
49
- ...u ?? {},
50
- ...a
51
- });
52
- const h = process.env.NODE_ENV !== "production";
53
- !u && h && console.warn(`[i18n] mergeTranslation called for '${c}' which was not pre-loaded. Skipping merge. Use force: true if this is intentional.`);
29
+ hasTranslation(t, r) {
30
+ for (const [s, n] of e)
31
+ if ((s === t || s.startsWith(`${t}:`)) && d(n, r) !== null)
32
+ return !0;
33
+ return !1;
54
34
  },
55
- mergeGlobalTranslation(s, i, a = !1) {
56
- const l = g(e, s);
57
- !a && !l && console.error(`marge: route ${s} not loaded`), d(e, s, {
58
- ...l ?? {},
59
- ...i
60
- });
35
+ hasGeneralTranslation(t) {
36
+ return e.has(t);
61
37
  },
62
- hasGeneralTranslation(s) {
63
- return !!g(e, s);
38
+ hasPageTranslation(t, r) {
39
+ return e.has(`${t}:${r}`);
64
40
  },
65
- hasPageTranslation(s, i) {
66
- const a = `${s}:${i}`;
67
- return !!g(t, a);
41
+ getTranslation(t, r, s) {
42
+ const n = `${t}:${r}`, i = e.get(n), a = d(i, s);
43
+ if (a !== null) return a;
44
+ const l = e.get(t);
45
+ return d(l, s);
68
46
  },
69
- hasTranslation: (s, i) => {
70
- const a = p(r);
71
- for (const c of a)
72
- if (v(c[s] || null, i) !== null)
73
- return !0;
74
- const l = g(e, s);
75
- return v(l || null, i) !== null;
47
+ loadTranslations(t, r) {
48
+ const s = e.get(t) ?? {};
49
+ e.set(t, { ...s, ...r });
76
50
  },
77
- getTranslation: (s, i, a) => {
78
- const l = `${s}:${i}`, c = g(n, l), u = c?.get(a);
79
- if (u)
80
- return u;
81
- let h = null;
82
- const C = p(r);
83
- for (const m of C)
84
- if (h = v(m[s] || null, a), h !== null) break;
85
- if (!h) {
86
- const m = g(t, l), R = g(e, s);
87
- h = v(m || null, a) ?? v(R || null, a);
88
- }
89
- if (h) {
90
- const m = c ?? /* @__PURE__ */ new Map();
91
- m.set(a, h), d(n, l, m);
92
- }
93
- return h;
51
+ setTranslations(t, r) {
52
+ e.set(t, r);
53
+ },
54
+ loadPageTranslations(t, r, s) {
55
+ const n = `${t}:${r}`, i = e.get(n);
56
+ !i || Object.keys(i).length === 0 ? e.set(n, s) : e.set(n, { ...i, ...s });
94
57
  },
95
- async loadPageTranslations(s, i, a) {
96
- const l = `${s}:${i}`;
97
- d(t, l, { ...a });
58
+ mergeTranslation(t, r, s, n = !1) {
59
+ const i = `${t}:${r}`, a = e.get(i) ?? {};
60
+ e.set(i, { ...a, ...s });
98
61
  },
99
- async loadTranslations(s, i) {
100
- d(e, s, { ...i });
62
+ mergeGlobalTranslation(t, r, s = !1) {
63
+ const n = e.get(t) ?? {};
64
+ e.set(t, { ...n, ...r });
101
65
  },
102
66
  clearCache() {
103
- const s = p(e);
104
- Object.keys(s).forEach((c) => {
105
- d(e, c, {});
106
- });
107
- const i = p(t);
108
- Object.keys(i).forEach((c) => {
109
- d(t, c, {});
110
- });
111
- const a = p(r);
112
- a.length = 0;
113
- const l = p(n);
114
- Object.keys(l).forEach((c) => {
115
- g(n, c)?.clear();
116
- });
67
+ e.clear();
117
68
  }
118
69
  };
119
70
  }
120
- function S(o, e) {
121
- let t = o;
122
- for (const r in e)
123
- t = t.split(`{${r}}`).join(String(e[r]));
124
- return t;
71
+ const y = /\{(\w+)\}/g;
72
+ function P(o, e) {
73
+ return e ? o.replace(y, (t, r) => {
74
+ const s = e[r];
75
+ return s !== void 0 ? String(s) : `{${r}}`;
76
+ }) : o;
125
77
  }
126
- function y(o) {
78
+ function f(o) {
127
79
  return o === "prefix" || o === "prefix_and_default";
128
80
  }
129
- function f(o) {
81
+ function c(o) {
130
82
  return o === "no_prefix";
131
83
  }
132
- function D(o) {
84
+ function b(o) {
133
85
  return o === "prefix";
134
86
  }
135
- function F(o) {
87
+ function R(o) {
136
88
  return o === "prefix_except_default";
137
89
  }
138
- function q(o) {
90
+ function $(o) {
139
91
  return o === "prefix_and_default";
140
92
  }
141
- const x = (o, e, t, r, n) => {
142
- const s = n(o, t);
143
- if (!s)
93
+ const L = (o, e, t, r, s) => {
94
+ const n = s(o, t);
95
+ if (!n)
144
96
  return null;
145
- const i = s.toString().split("|");
97
+ const i = n.toString().split("|");
146
98
  if (i.length === 0) return null;
147
99
  const a = e < i.length ? i[e] : i[i.length - 1];
148
100
  return a ? a.trim().replace("{count}", e.toString()) : null;
149
101
  };
150
- class z {
151
- constructor(e, t, r, n, s, i, a = null, l = null) {
152
- this.i18nConfig = e, this.router = t, this.hashLocaleDefault = r, this.noPrefixDefault = n, this.navigateTo = s, this.setCookie = i, this.cookieLocaleDefault = a, this.cookieLocaleName = l;
102
+ class w {
103
+ constructor(e, t, r, s, n, i) {
104
+ this.i18nConfig = e, this.router = t, this.hashLocaleDefault = r, this.noPrefixDefault = s, this.navigateTo = n, this.getDefaultLocale = i;
153
105
  }
154
106
  /**
155
107
  * Extracts locale from URL path by checking the first path segment
@@ -162,25 +114,41 @@ class z {
162
114
  const r = e.split("?")[0]?.split("#")[0];
163
115
  if (!r || r === "/")
164
116
  return null;
165
- const n = r.split("/").filter(Boolean);
166
- if (n.length === 0)
117
+ const s = r.split("/").filter(Boolean);
118
+ if (s.length === 0)
167
119
  return null;
168
- const s = n[0];
169
- return s && (this.i18nConfig.locales?.map((a) => a.code) || []).includes(s) ? s : null;
120
+ const n = s[0];
121
+ return n && (this.i18nConfig.locales?.map((a) => a.code) || []).includes(n) ? n : null;
170
122
  }
171
123
  getCurrentLocale(e) {
172
- if (e = e ?? this.router.currentRoute.value, this.i18nConfig.hashMode && this.hashLocaleDefault)
173
- return this.hashLocaleDefault;
174
- if (f(this.i18nConfig.strategy) && this.noPrefixDefault)
175
- return this.noPrefixDefault;
124
+ if (e = e ?? this.router.currentRoute.value, this.i18nConfig.hashMode) {
125
+ const n = this.getDefaultLocale?.();
126
+ if (n) return n;
127
+ if (this.hashLocaleDefault) return this.hashLocaleDefault;
128
+ }
129
+ if (c(this.i18nConfig.strategy)) {
130
+ const n = this.getDefaultLocale?.();
131
+ if (n) return n;
132
+ if (this.noPrefixDefault) return this.noPrefixDefault;
133
+ }
134
+ const t = e.path || e.fullPath || "";
135
+ if ($(this.i18nConfig.strategy) && (t === "/" || t === "")) {
136
+ const n = this.getDefaultLocale?.();
137
+ if (n) return n;
138
+ }
176
139
  if (e.params?.locale)
177
140
  return e.params.locale.toString();
178
- const t = e.path || e.fullPath || "", r = this.extractLocaleFromPath(t);
179
- return r || (this.cookieLocaleDefault ? this.cookieLocaleDefault : (this.i18nConfig.defaultLocale || "en").toString());
141
+ const r = this.extractLocaleFromPath(t);
142
+ if (r)
143
+ return r;
144
+ if (R(this.i18nConfig.strategy))
145
+ return (this.i18nConfig.defaultLocale || "en").toString();
146
+ const s = this.getDefaultLocale?.();
147
+ return s || (this.i18nConfig.defaultLocale || "en").toString();
180
148
  }
181
149
  getCurrentName(e) {
182
150
  const t = this.getCurrentLocale(e);
183
- return this.i18nConfig.locales?.find((n) => n.code === t)?.displayName ?? null;
151
+ return this.i18nConfig.locales?.find((s) => s.code === t)?.displayName ?? null;
184
152
  }
185
153
  getRouteName(e, t) {
186
154
  return (e.name ?? "").toString().toString().replace("localized-", "").replace(new RegExp(`-${t}$`), "");
@@ -189,36 +157,36 @@ class z {
189
157
  return this.i18nConfig.disablePageLocales ? "general" : this.getRouteName(e, t);
190
158
  }
191
159
  getFullPathWithBaseUrl(e, t) {
192
- let n = this.router.resolve(t).fullPath;
193
- e?.baseDefault && (n = n.replace(new RegExp(`^/${e.code}`), ""));
194
- let s = e.baseUrl;
195
- return s || (s = ""), s?.endsWith("/") && (s = s.slice(0, -1)), s + n;
160
+ let s = this.router.resolve(t).fullPath;
161
+ e?.baseDefault && (s = s.replace(new RegExp(`^/${e.code}`), ""));
162
+ let n = e.baseUrl;
163
+ return n || (n = ""), n?.endsWith("/") && (n = n.slice(0, -1)), n + s;
196
164
  }
197
- switchLocaleRoute(e, t, r, n) {
198
- const s = this.i18nConfig.locales?.find((h) => h.code === t), i = this.getRouteName(r, e);
165
+ switchLocaleRoute(e, t, r, s) {
166
+ const n = this.i18nConfig.locales?.find((g) => g.code === t), i = this.getRouteName(r, e);
199
167
  if (this.router.hasRoute(`localized-${i}-${t}`)) {
200
- const C = { ...n?.[t] ? { ...n[t] } : { ...r.params ?? {} } };
201
- delete C.locale, f(this.i18nConfig.strategy) || (C.locale = t);
202
- const m = {
168
+ const m = { ...s?.[t] ? { ...s[t] } : { ...r.params ?? {} } };
169
+ delete m.locale, c(this.i18nConfig.strategy) || (m.locale = t);
170
+ const p = {
203
171
  name: `localized-${i}-${t}`,
204
- params: C,
172
+ params: m,
205
173
  query: r.query,
206
174
  hash: r.hash
207
175
  };
208
- return s?.baseUrl ? this.getFullPathWithBaseUrl(s, m) : m;
176
+ return n?.baseUrl ? this.getFullPathWithBaseUrl(n, p) : p;
209
177
  }
210
178
  let a = i;
211
- const c = { ...n?.[t] ? { ...n[t] } : { ...r.params ?? {} } };
212
- delete c.locale, f(this.i18nConfig.strategy) || (i === "custom-fallback-route" ? a = i : a = t !== this.i18nConfig.defaultLocale || y(this.i18nConfig.strategy) ? `localized-${i}` : i, f(this.i18nConfig.strategy) || (t !== this.i18nConfig.defaultLocale || y(this.i18nConfig.strategy)) && (c.locale = t));
213
- const u = {
179
+ const u = { ...s?.[t] ? { ...s[t] } : { ...r.params ?? {} } };
180
+ delete u.locale, c(this.i18nConfig.strategy) || (i === "custom-fallback-route" ? a = i : a = t !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy) ? `localized-${i}` : i, c(this.i18nConfig.strategy) || (t !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy)) && (u.locale = t));
181
+ const h = {
214
182
  name: a,
215
- params: c,
183
+ params: u,
216
184
  query: r.query,
217
185
  hash: r.hash
218
186
  };
219
- return f(this.i18nConfig.strategy) && this.i18nConfig.locales?.forEach((h, C) => {
220
- u.name.endsWith(`-${h.code}`) && (u.name = u.name.slice(0, -h.code - 1));
221
- }), s?.baseUrl ? this.getFullPathWithBaseUrl(s, u) : u;
187
+ return c(this.i18nConfig.strategy) && this.i18nConfig.locales?.forEach((g, m) => {
188
+ h.name.endsWith(`-${g.code}`) && (h.name = h.name.slice(0, -g.code - 1));
189
+ }), n?.baseUrl ? this.getFullPathWithBaseUrl(n, h) : h;
222
190
  }
223
191
  resolveParams(e) {
224
192
  const t = typeof e == "object" && "params" in e && typeof e.params == "object" ? { ...e.params } : {};
@@ -229,110 +197,106 @@ class z {
229
197
  return t;
230
198
  }
231
199
  handlePrefixStrategy(e) {
232
- if (!y(this.i18nConfig.strategy))
200
+ if (!f(this.i18nConfig.strategy))
233
201
  return e;
234
202
  const t = this.i18nConfig.defaultLocale;
235
203
  let r = e;
236
204
  typeof e == "string" && (r = this.router.resolve("/" + t + e));
237
- const n = this.getRouteName(r, t), s = this.resolveParams(r);
238
- return f(this.i18nConfig.strategy) || (s.locale = t), this.router.hasRoute(`localized-${n}`) ? this.router.resolve({
239
- name: `localized-${n}`,
205
+ const s = this.getRouteName(r, t), n = this.resolveParams(r);
206
+ return c(this.i18nConfig.strategy) || (n.locale = t), this.router.hasRoute(`localized-${s}`) ? this.router.resolve({
207
+ name: `localized-${s}`,
240
208
  query: r.query,
241
209
  hash: r.hash,
242
- params: s
243
- }) : this.router.hasRoute(`localized-${n}-${t}`) ? this.router.resolve({
244
- name: `localized-${n}-${t}`,
210
+ params: n
211
+ }) : this.router.hasRoute(`localized-${s}-${t}`) ? this.router.resolve({
212
+ name: `localized-${s}-${t}`,
245
213
  query: r.query,
246
214
  hash: r.hash,
247
- params: s
215
+ params: n
248
216
  }) : e;
249
217
  }
250
218
  createLocalizedRoute(e, t, r) {
251
- const n = this.router.resolve(e), s = this.getRouteName(n, r).replace(new RegExp(`-${this.i18nConfig.defaultLocale}$`), "");
252
- if (!f(this.i18nConfig.strategy) && (!s || s === "")) {
253
- let c = this.router.resolve(e).path.replace(new RegExp(`^/${r}/`), "/");
254
- return (r !== this.i18nConfig.defaultLocale || y(this.i18nConfig.strategy)) && (c = "/" + r + c), this.router.resolve({
255
- path: c,
256
- query: n.query,
257
- hash: n.hash
219
+ const s = this.router.resolve(e), n = this.getRouteName(s, r).replace(new RegExp(`-${this.i18nConfig.defaultLocale}$`), "");
220
+ if (!c(this.i18nConfig.strategy) && (!n || n === "")) {
221
+ let u = this.router.resolve(e).path.replace(new RegExp(`^/${r}/`), "/");
222
+ return (r !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy)) && (u = "/" + r + u), this.router.resolve({
223
+ path: u,
224
+ query: s.query,
225
+ hash: s.hash
258
226
  });
259
227
  }
260
- if (this.router.hasRoute(`localized-${s}-${r}`)) {
261
- const l = this.resolveParams(n);
262
- return f(this.i18nConfig.strategy) || (l.locale = r), this.router.resolve({
263
- name: `localized-${s}-${r}`,
228
+ if (this.router.hasRoute(`localized-${n}-${r}`)) {
229
+ const l = this.resolveParams(s);
230
+ return c(this.i18nConfig.strategy) || (l.locale = r), this.router.resolve({
231
+ name: `localized-${n}-${r}`,
264
232
  params: l,
265
- query: n.query,
266
- hash: n.hash
233
+ query: s.query,
234
+ hash: s.hash
267
235
  });
268
236
  }
269
- const i = r !== this.i18nConfig.defaultLocale || y(this.i18nConfig.strategy) ? `localized-${s}` : s;
237
+ const i = r !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy) ? `localized-${n}` : n;
270
238
  if (!this.router.hasRoute(i)) {
271
239
  const l = this.resolveParams(e);
272
- return delete l.locale, this.router.hasRoute(s) ? this.router.resolve({
273
- name: s,
240
+ return delete l.locale, this.router.hasRoute(n) ? this.router.resolve({
241
+ name: n,
274
242
  params: l,
275
- query: n.query,
276
- hash: n.hash
243
+ query: s.query,
244
+ hash: s.hash
277
245
  }) : this.router.resolve("/");
278
246
  }
279
247
  const a = this.resolveParams(e);
280
- return delete a.locale, f(this.i18nConfig.strategy) || (r !== this.i18nConfig.defaultLocale || y(this.i18nConfig.strategy)) && (a.locale = r), this.router.resolve({
248
+ return delete a.locale, c(this.i18nConfig.strategy) || (r !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy)) && (a.locale = r), this.router.resolve({
281
249
  name: i,
282
250
  params: a,
283
- query: n.query,
284
- hash: n.hash
251
+ query: s.query,
252
+ hash: s.hash
285
253
  });
286
254
  }
287
255
  getLocalizedRoute(e, t, r) {
288
- const n = r || this.getCurrentLocale(t), s = this.handlePrefixStrategy(e);
289
- return this.createLocalizedRoute(s, t, n);
290
- }
291
- updateCookies(e) {
292
- const t = this.cookieLocaleName || this.i18nConfig.localeCookie || "user-locale";
293
- this.i18nConfig.hashMode && (this.setCookie("hash-locale", e), this.hashLocaleDefault = e), f(this.i18nConfig.strategy) && (this.setCookie(t, e), this.noPrefixDefault = e), !this.i18nConfig.hashMode && !f(this.i18nConfig.strategy) && t && (this.setCookie(t, e), this.cookieLocaleDefault = e);
256
+ const s = r || this.getCurrentLocale(t), n = this.handlePrefixStrategy(e);
257
+ return this.createLocalizedRoute(n, t, s);
294
258
  }
295
259
  getCurrentRoute() {
296
260
  return this.router.currentRoute.value;
297
261
  }
298
262
  resolveRouteWithStrategy(e, t, r) {
299
- return f(this.i18nConfig.strategy) ? this.router.resolve(e) : t !== this.i18nConfig.defaultLocale || y(this.i18nConfig.strategy) ? this.router.resolve(`/${r}${e}`) : this.router.resolve(e);
263
+ return c(this.i18nConfig.strategy) ? this.router.resolve(e) : t !== this.i18nConfig.defaultLocale || f(this.i18nConfig.strategy) ? this.router.resolve(`/${r}${e}`) : this.router.resolve(e);
300
264
  }
301
265
  switchLocaleLogic(e, t, r) {
302
- const n = this.getCurrentLocale();
303
- let s;
304
- typeof r == "string" ? s = this.resolveRouteWithStrategy(r, e, n) : s = r ?? this.getCurrentRoute(), this.updateCookies(e);
305
- const i = this.switchLocaleRoute(n, e, s, t);
306
- return typeof i == "string" && i.startsWith("http") ? this.navigateTo(i, { redirectCode: 200, external: !0 }) : (f(this.i18nConfig.strategy) && (i.force = !0), this.router.push(i));
266
+ const s = this.getCurrentLocale();
267
+ let n;
268
+ typeof r == "string" ? n = this.resolveRouteWithStrategy(r, e, s) : n = r ?? this.getCurrentRoute();
269
+ const i = this.switchLocaleRoute(s, e, n, t);
270
+ return typeof i == "string" && i.startsWith("http") ? this.navigateTo(i, { redirectCode: 200, external: !0 }) : (c(this.i18nConfig.strategy) && (i.force = !0), this.router.push(i));
307
271
  }
308
272
  resolveLocalizedRoute(e, t) {
309
- const r = this.getCurrentRoute(), n = this.getCurrentLocale(), s = t ?? n;
273
+ const r = this.getCurrentRoute(), s = this.getCurrentLocale(), n = t ?? s;
310
274
  let i;
311
275
  if (typeof e == "string")
312
276
  if (e.startsWith("/"))
313
- i = this.resolveRouteWithStrategy(e, s, n);
277
+ i = this.resolveRouteWithStrategy(e, n, s);
314
278
  else {
315
279
  const a = e;
316
- this.router.hasRoute(a) ? i = this.router.resolve({ name: a }) : (e = `/${e}`, i = this.resolveRouteWithStrategy(e, s, n));
280
+ this.router.hasRoute(a) ? i = this.router.resolve({ name: a }) : (e = `/${e}`, i = this.resolveRouteWithStrategy(e, n, s));
317
281
  }
318
282
  else
319
283
  i = e;
320
- return this.getLocalizedRoute(i, r, s);
284
+ return this.getLocalizedRoute(i, r, n);
321
285
  }
322
286
  }
323
- class P {
287
+ class v {
324
288
  formatNumber(e, t, r) {
325
289
  return new Intl.NumberFormat(t, r).format(e);
326
290
  }
327
291
  formatDate(e, t, r) {
328
- const n = new Date(e);
329
- return Number.isNaN(n.getTime()) ? "Invalid Date" : new Intl.DateTimeFormat(t, r).format(n);
292
+ const s = new Date(e);
293
+ return Number.isNaN(s.getTime()) ? "Invalid Date" : new Intl.DateTimeFormat(t, r).format(s);
330
294
  }
331
295
  formatRelativeTime(e, t, r) {
332
- const n = new Date(e);
333
- if (Number.isNaN(n.getTime()))
296
+ const s = new Date(e);
297
+ if (Number.isNaN(s.getTime()))
334
298
  return new Intl.RelativeTimeFormat(t, r).format(0, "second");
335
- const i = Math.floor(((/* @__PURE__ */ new Date()).getTime() - n.getTime()) / 1e3), a = [
299
+ const i = Math.floor(((/* @__PURE__ */ new Date()).getTime() - s.getTime()) / 1e3), a = [
336
300
  { unit: "year", seconds: 31536e3 },
337
301
  { unit: "month", seconds: 2592e3 },
338
302
  { unit: "day", seconds: 86400 },
@@ -340,62 +304,62 @@ class P {
340
304
  { unit: "minute", seconds: 60 },
341
305
  { unit: "second", seconds: 1 }
342
306
  ];
343
- for (const { unit: l, seconds: c } of a) {
344
- const u = Math.floor(i / c);
345
- if (u >= 1)
346
- return new Intl.RelativeTimeFormat(t, r).format(-u, l);
307
+ for (const { unit: l, seconds: u } of a) {
308
+ const h = Math.floor(i / u);
309
+ if (h >= 1)
310
+ return new Intl.RelativeTimeFormat(t, r).format(-h, l);
347
311
  }
348
312
  return new Intl.RelativeTimeFormat(t, r).format(0, "second");
349
313
  }
350
314
  }
351
- class E {
315
+ class T {
352
316
  constructor(e = {}) {
353
- this.formatter = new P(), this.helper = w(e.cache), this.formatter = new P(), this.pluralFunc = e.plural || x, this.missingWarn = e.missingWarn ?? !0, this.missingHandler = e.missingHandler, this.getPreviousPageInfo = e.getPreviousPageInfo, this.getCustomMissingHandler = e.getCustomMissingHandler, this.enablePreviousPageFallback = e.enablePreviousPageFallback ?? !1;
317
+ this.formatter = new v(), this.helper = C(e.storage), this.formatter = new v(), this.pluralFunc = e.plural || L, this.missingWarn = e.missingWarn ?? !0, this.missingHandler = e.missingHandler, this.getPreviousPageInfo = e.getPreviousPageInfo, this.getCustomMissingHandler = e.getCustomMissingHandler, this.enablePreviousPageFallback = e.enablePreviousPageFallback ?? !1;
354
318
  }
355
319
  // --- Public methods (implemented in base class) ---
356
320
  /**
357
321
  * Get translation for a key
358
322
  * Based on logic from src/runtime/plugins/01.plugin.ts
359
323
  */
360
- t(e, t, r, n) {
324
+ t(e, t, r, s) {
361
325
  if (!e) return "";
362
- const s = this.getLocale(), i = n || this.getRoute();
363
- let a = this.helper.getTranslation(s, i, e);
326
+ const n = this.getLocale(), i = s || this.getRoute();
327
+ let a = this.helper.getTranslation(n, i, e);
364
328
  if (!a && this.enablePreviousPageFallback && this.getPreviousPageInfo) {
365
329
  const l = this.getPreviousPageInfo();
366
330
  if (l) {
367
- const c = this.helper.getTranslation(l.locale, l.routeName, e);
368
- c && (a = c, process.env.NODE_ENV !== "production" && console.log(`Using fallback translation from previous route: ${l.routeName} -> ${e}`));
331
+ const u = this.helper.getTranslation(l.locale, l.routeName, e);
332
+ u && (a = u, process.env.NODE_ENV !== "production" && console.log(`Using fallback translation from previous route: ${l.routeName} -> ${e}`));
369
333
  }
370
334
  }
371
335
  if (!a) {
372
336
  const l = this.getFallbackLocale();
373
- s !== l && (a = this.helper.getTranslation(l, i, e));
337
+ n !== l && (a = this.helper.getTranslation(l, i, e));
374
338
  }
375
339
  if (!a) {
376
340
  const l = this.getCustomMissingHandler?.();
377
- l ? l(s, e, i) : this.missingHandler ? this.missingHandler(s, e, i) : this.missingWarn && process.env.NODE_ENV !== "production" && typeof window < "u" && console.warn(`Not found '${e}' key in '${s}' locale messages for route '${i}'.`), a = r === void 0 ? e : r || e;
341
+ l ? l(n, e, i) : this.missingHandler ? this.missingHandler(n, e, i) : this.missingWarn && process.env.NODE_ENV !== "production" && typeof window < "u" && console.warn(`Not found '${e}' key in '${n}' locale messages for route '${i}'.`), a = r === void 0 ? e : r || e;
378
342
  }
379
- return typeof a == "string" && t ? S(a, t) : a;
343
+ return typeof a == "string" && t ? P(a, t) : a;
380
344
  }
381
345
  /**
382
346
  * Get translation as string
383
347
  */
384
- ts(e, t, r, n) {
385
- return this.t(e, t, r, n)?.toString() ?? r ?? e;
348
+ ts(e, t, r, s) {
349
+ return this.t(e, t, r, s)?.toString() ?? r ?? e;
386
350
  }
387
351
  /**
388
352
  * Plural translation
389
353
  */
390
354
  tc(e, t, r) {
391
- const { count: n, ...s } = typeof t == "number" ? { count: t } : t;
392
- if (n === void 0)
355
+ const { count: s, ...n } = typeof t == "number" ? { count: t } : t;
356
+ if (s === void 0)
393
357
  return r ?? e;
394
- const i = (l, c, u) => this.t(l, c, u);
358
+ const i = (l, u, h) => this.t(l, u, h);
395
359
  return this.pluralFunc(
396
360
  e,
397
- Number.parseInt(n.toString()),
398
- s,
361
+ Number.parseInt(s.toString()),
362
+ n,
399
363
  this.getLocale(),
400
364
  i
401
365
  ) ?? r ?? e;
@@ -423,8 +387,8 @@ class E {
423
387
  * Based on logic from src/runtime/plugins/01.plugin.ts
424
388
  */
425
389
  has(e, t) {
426
- const r = t || this.getRoute(), n = this.getLocale();
427
- return !!this.helper.getTranslation(n, r, e);
390
+ const r = t || this.getRoute(), s = this.getLocale();
391
+ return !!this.helper.getTranslation(s, r, e);
428
392
  }
429
393
  /**
430
394
  * Clear cache
@@ -438,26 +402,26 @@ class E {
438
402
  * Subclasses can override addTranslations/addRouteTranslations to add reactivity
439
403
  */
440
404
  loadTranslationsCore(e, t, r) {
441
- r ? this.helper.mergeGlobalTranslation(e, t, !0) : this.helper.loadTranslations(e, t);
405
+ r ? this.helper.mergeGlobalTranslation(e, t, !0) : this.helper.setTranslations(e, t);
442
406
  }
443
407
  /**
444
408
  * Core route translation loading logic (without reactivity)
445
409
  * Subclasses can override addRouteTranslations to add reactivity
446
410
  */
447
- loadRouteTranslationsCore(e, t, r, n) {
448
- n ? this.helper.mergeTranslation(e, t, r, !0) : this.helper.loadPageTranslations(e, t, r);
411
+ loadRouteTranslationsCore(e, t, r, s) {
412
+ s ? this.helper.mergeTranslation(e, t, r, !0) : this.helper.loadPageTranslations(e, t, r);
449
413
  }
450
414
  }
451
415
  export {
452
- E as BaseI18n,
453
- P as FormatService,
454
- z as RouteService,
455
- x as defaultPlural,
456
- S as interpolate,
457
- f as isNoPrefixStrategy,
458
- q as isPrefixAndDefaultStrategy,
459
- F as isPrefixExceptDefaultStrategy,
460
- D as isPrefixStrategy,
461
- w as useTranslationHelper,
462
- y as withPrefixStrategy
416
+ T as BaseI18n,
417
+ v as FormatService,
418
+ w as RouteService,
419
+ L as defaultPlural,
420
+ P as interpolate,
421
+ c as isNoPrefixStrategy,
422
+ $ as isPrefixAndDefaultStrategy,
423
+ R as isPrefixExceptDefaultStrategy,
424
+ b as isPrefixStrategy,
425
+ C as useTranslationHelper,
426
+ f as withPrefixStrategy
463
427
  };