@i18n-micro/core 1.0.27 → 1.0.28

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