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