@pie-element/shared-i18n 0.1.1-next.20261016234357 → 0.1.1

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.
Files changed (2) hide show
  1. package/dist/index.js +40 -27
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -88,11 +88,11 @@ var d = class n {
88
88
  }
89
89
  t(e, t) {
90
90
  let n = this.lookup(e);
91
- return n === void 0 ? (this.config.onMissingKey?.(e, this.locale), e) : p(n, t);
91
+ return n === void 0 ? (this.config.onMissingKey?.(e, this.locale), e) : h(n, t, this.locale);
92
92
  }
93
93
  plural(e, t) {
94
94
  let n = this.lookupNode(e);
95
- return n === void 0 || !l(n) ? this.t(e, t) : p(n[this.selectPluralCategory(t.count)] ?? n.other, t);
95
+ return n === void 0 || !l(n) ? this.t(e, t) : h(n[this.selectPluralCategory(t.count)] ?? n.other, t, this.locale);
96
96
  }
97
97
  getDirection() {
98
98
  return u(this.locale);
@@ -122,7 +122,7 @@ var d = class n {
122
122
  }
123
123
  addCustomMessages(e, n) {
124
124
  let r = t(e);
125
- this.customMessages[r] = m(this.customMessages[r] ?? {}, n), this.notify();
125
+ this.customMessages[r] = g(this.customMessages[r] ?? {}, n), this.notify();
126
126
  }
127
127
  withLocale(e) {
128
128
  let r = this.resolveLocaleTag(e) ?? t(e);
@@ -216,32 +216,45 @@ function f(e, t) {
216
216
  for (let e of t.split(".")) if (typeof n != "object" || !n || (n = n[e], n === void 0)) return;
217
217
  return n;
218
218
  }
219
- function p(e, t) {
220
- return t ? e.replace(/\{(\w+)\}/g, (e, n) => {
221
- let r = t[n];
222
- return r == null ? e : String(r);
219
+ var p = /* @__PURE__ */ new Map();
220
+ function m(e, t) {
221
+ let n = p.get(t);
222
+ if (!n) {
223
+ try {
224
+ n = new Intl.NumberFormat(t);
225
+ } catch {
226
+ n = new Intl.NumberFormat(a);
227
+ }
228
+ p.set(t, n);
229
+ }
230
+ return n.format(e);
231
+ }
232
+ function h(e, t, n) {
233
+ return t ? e.replace(/\{(\w+)\}/g, (e, r) => {
234
+ let i = t[r];
235
+ return i == null ? e : n !== void 0 && typeof i == "number" && Number.isFinite(i) ? m(i, n) : String(i);
223
236
  }) : e;
224
237
  }
225
- function m(e, t) {
238
+ function g(e, t) {
226
239
  let n = { ...e };
227
240
  for (let [e, r] of Object.entries(t)) {
228
241
  let t = n[e];
229
- r && typeof r == "object" && t && typeof t == "object" ? n[e] = m(t, r) : n[e] = r;
242
+ r && typeof r == "object" && t && typeof t == "object" ? n[e] = g(t, r) : n[e] = r;
230
243
  }
231
244
  return n;
232
245
  }
233
246
  //#endregion
234
247
  //#region src/catalogs.ts
235
- var h = Symbol.for("pie-element.i18n.registry");
236
- function g() {
248
+ var _ = Symbol.for("pie-element.i18n.registry");
249
+ function v() {
237
250
  let e = globalThis;
238
- return e[h] || (e[h] = {
251
+ return e[_] || (e[_] = {
239
252
  sets: /* @__PURE__ */ new Set(),
240
253
  messages: /* @__PURE__ */ new Map()
241
- }), e[h];
254
+ }), e[_];
242
255
  }
243
- function _(e) {
244
- let t = e.loaders ?? {}, n = g(), r = new d({
256
+ function y(e) {
257
+ let t = e.loaders ?? {}, n = v(), r = new d({
245
258
  source: e.source,
246
259
  availableLocales: [a, ...Object.keys(t)],
247
260
  loadCatalog: async (e) => (await t[e]()).default
@@ -268,16 +281,16 @@ function _(e) {
268
281
  };
269
282
  return n.sets.add(l), l;
270
283
  }
271
- function v(e) {
284
+ function b(e) {
272
285
  if (!e) return !0;
273
- for (let t of g().sets) if (t.needsLoad(e)) return !1;
286
+ for (let t of v().sets) if (t.needsLoad(e)) return !1;
274
287
  return !0;
275
288
  }
276
- async function y(e) {
277
- e && await Promise.all([...g().sets].map((t) => t.load(e)));
289
+ async function x(e) {
290
+ e && await Promise.all([...v().sets].map((t) => t.load(e)));
278
291
  }
279
- function b(e, t, n) {
280
- let r = g(), i = r.messages.get(e) ?? [];
292
+ function S(e, t, n) {
293
+ let r = v(), i = r.messages.get(e) ?? [];
281
294
  i.push({
282
295
  locale: t,
283
296
  messages: n
@@ -286,7 +299,7 @@ function b(e, t, n) {
286
299
  }
287
300
  //#endregion
288
301
  //#region src/element-language.ts
289
- function x(e) {
302
+ function C(e) {
290
303
  let n = t(e).split(/[.@]/)[0];
291
304
  if (/^[a-z]{2,3}(-|$)/i.test(n)) try {
292
305
  return Intl.getCanonicalLocales(n)[0];
@@ -294,16 +307,16 @@ function x(e) {
294
307
  return;
295
308
  }
296
309
  }
297
- function S(e) {
298
- let t = x(e);
310
+ function w(e) {
311
+ let t = C(e);
299
312
  return t ? {
300
313
  lang: t,
301
314
  dir: u(t)
302
315
  } : void 0;
303
316
  }
304
- function C(e, t) {
305
- let n = S(t);
317
+ function T(e, t) {
318
+ let n = w(t);
306
319
  n ? (e.setAttribute("lang", n.lang), e.setAttribute("dir", n.dir)) : (e.removeAttribute("lang"), e.removeAttribute("dir"));
307
320
  }
308
321
  //#endregion
309
- export { a as DEFAULT_LOCALE, d as SimpleI18n, x as canonicalLanguageTag, _ as defineCatalogs, o as dynamicMessageKey, S as elementLanguageAttributes, i as findBestLanguageMatch, v as isLocaleReady, r as languageTagLookupSequence, n as languageTagsEqual, y as loadLocale, u as localeDirection, e as normalizeLanguageTag, b as registerMessages, C as stampElementLanguage, t as toLanguageTag };
322
+ export { a as DEFAULT_LOCALE, d as SimpleI18n, C as canonicalLanguageTag, y as defineCatalogs, o as dynamicMessageKey, w as elementLanguageAttributes, i as findBestLanguageMatch, b as isLocaleReady, r as languageTagLookupSequence, n as languageTagsEqual, x as loadLocale, u as localeDirection, e as normalizeLanguageTag, S as registerMessages, T as stampElementLanguage, t as toLanguageTag };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-i18n",
3
- "version": "0.1.1-next.20261016234357",
3
+ "version": "0.1.1",
4
4
  "description": "Interface-string i18n engine for PIE elements: typed per-package catalogs, lazy locales, RFC 4647 resolution",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",