@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.
- package/dist/index.js +40 -27
- 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) :
|
|
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) :
|
|
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] =
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
|
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] =
|
|
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
|
|
236
|
-
function
|
|
248
|
+
var _ = Symbol.for("pie-element.i18n.registry");
|
|
249
|
+
function v() {
|
|
237
250
|
let e = globalThis;
|
|
238
|
-
return e[
|
|
251
|
+
return e[_] || (e[_] = {
|
|
239
252
|
sets: /* @__PURE__ */ new Set(),
|
|
240
253
|
messages: /* @__PURE__ */ new Map()
|
|
241
|
-
}), e[
|
|
254
|
+
}), e[_];
|
|
242
255
|
}
|
|
243
|
-
function
|
|
244
|
-
let t = e.loaders ?? {}, n =
|
|
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
|
|
284
|
+
function b(e) {
|
|
272
285
|
if (!e) return !0;
|
|
273
|
-
for (let t of
|
|
286
|
+
for (let t of v().sets) if (t.needsLoad(e)) return !1;
|
|
274
287
|
return !0;
|
|
275
288
|
}
|
|
276
|
-
async function
|
|
277
|
-
e && await Promise.all([...
|
|
289
|
+
async function x(e) {
|
|
290
|
+
e && await Promise.all([...v().sets].map((t) => t.load(e)));
|
|
278
291
|
}
|
|
279
|
-
function
|
|
280
|
-
let r =
|
|
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
|
|
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
|
|
298
|
-
let t =
|
|
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
|
|
305
|
-
let n =
|
|
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,
|
|
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
|
|
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",
|