@intlify/core 12.0.0-alpha.4 → 12.0.0-alpha.6

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.
@@ -1,24 +1,8 @@
1
1
  /**
2
- * @intlify/core v12.0.0-alpha.4
2
+ * @intlify/core v12.0.0-alpha.6
3
3
  * (c) 2016-present kazuya kawaguchi and contributors
4
4
  * @license MIT
5
5
  **/
6
- //#region packages/shared/src/warn.ts
7
- function warn(msg, err) {
8
- if (typeof console !== "undefined") {
9
- console.warn(`[intlify] ` + msg);
10
- /* istanbul ignore if */
11
- if (err) console.warn(err.stack);
12
- }
13
- }
14
- const hasWarned = {};
15
- function warnOnce(msg) {
16
- if (!hasWarned[msg]) {
17
- hasWarned[msg] = true;
18
- warn(msg);
19
- }
20
- }
21
- //#endregion
22
6
  //#region packages/shared/src/utils.ts
23
7
  /**
24
8
  * Original Utilities
@@ -37,6 +21,7 @@ let measure;
37
21
  perf.measure(name, startTag, endTag);
38
22
  perf.clearMarks(startTag);
39
23
  perf.clearMarks(endTag);
24
+ perf.clearMeasures(name);
40
25
  };
41
26
  }
42
27
  }
@@ -55,75 +40,36 @@ const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({
55
40
  });
56
41
  const friendlyJSONstringify = (json) => JSON.stringify(json).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/\u0027/g, "\\u0027");
57
42
  const isNumber = (val) => typeof val === "number" && isFinite(val);
43
+ function toDevtoolsGroupId(type, key) {
44
+ return isString(key) || isNumber(key) ? `${type}:${key}` : type;
45
+ }
58
46
  const isDate = (val) => toTypeString(val) === "[object Date]";
59
47
  const isRegExp = (val) => toTypeString(val) === "[object RegExp]";
60
48
  const isKeylessObject = (val) => Object.keys(val).length === 0;
61
49
  const assign = Object.assign;
62
50
  const _create = Object.create;
63
51
  const create = (obj = null) => _create(obj);
64
- function escapeHtml(rawText) {
65
- return rawText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/\//g, "&#x2F;").replace(/=/g, "&#x3D;");
66
- }
67
- function escapeAttributeValue(value) {
68
- return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
69
- }
70
- const javascriptSchemePattern = /^\s*javascript\s*(?::|&#0*58;?|&#x0*3a;?|&colon;?)/i;
71
- const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
72
- function hasJavascriptScheme(value) {
73
- return javascriptSchemePattern.test(value);
74
- }
75
- function sanitizeStyleValue(value) {
76
- const urlPattern = /url\s*\(/gi;
77
- let sanitized = "";
78
- let cursor = 0;
79
- let match;
80
- while ((match = urlPattern.exec(value)) !== null) {
81
- const urlStart = match.index;
82
- const openParenIndex = urlPattern.lastIndex - 1;
83
- let index = openParenIndex + 1;
84
- let depth = 1;
85
- let quote = null;
86
- for (; index < value.length; index++) {
87
- const char = value[index];
88
- if (quote) {
89
- if (char === quote) quote = null;
90
- continue;
91
- }
92
- if (char === "\"" || char === "'") quote = char;
93
- else if (char === "(") depth++;
94
- else if (char === ")") {
95
- depth--;
96
- if (depth === 0) break;
97
- }
98
- }
99
- if (depth !== 0) break;
100
- const rawUrlValue = value.slice(openParenIndex + 1, index).trim();
101
- const unquotedUrlValue = rawUrlValue.startsWith("\"") && rawUrlValue.endsWith("\"") || rawUrlValue.startsWith("'") && rawUrlValue.endsWith("'") ? rawUrlValue.slice(1, -1).trim() : rawUrlValue;
102
- sanitized += value.slice(cursor, urlStart);
103
- sanitized += hasJavascriptScheme(unquotedUrlValue) ? "url(about:blank)" : value.slice(urlStart, index + 1);
104
- cursor = index + 1;
105
- }
106
- return sanitized + value.slice(cursor);
107
- }
108
- function sanitizeAttributeValue(attrName, value) {
109
- if (urlAttributePattern.test(attrName) && hasJavascriptScheme(value)) return "about:blank";
110
- return escapeAttributeValue(attrName.toLowerCase() === "style" ? sanitizeStyleValue(value) : value);
111
- }
112
- function sanitizeTranslatedHtml(html) {
113
- html = html.replace(/([\w:-]+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${sanitizeAttributeValue(attrName, attrValue)}"`);
114
- html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
115
- if (/\s*on\w+\s*=\s*["']?[^"'>]+["']?/i.test(html)) {
116
- warn("Potentially dangerous event handlers detected in translation. Consider removing onclick, onerror, etc. from your translation messages.");
117
- html = html.replace(/(\s+)on(\w+\s*=)/gi, "$1&#111;n$2");
118
- }
119
- html = html.replace(/(\s+(?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi, (match, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${prefix}about:blank` : match);
120
- return html;
121
- }
122
52
  const hasOwnProperty = Object.prototype.hasOwnProperty;
123
53
  function hasOwn(obj, key) {
124
54
  return hasOwnProperty.call(obj, key);
125
55
  }
126
56
  /**
57
+ * Get `obj[key]` only when `key` is an own property of `obj`, so that a key such as `constructor`
58
+ * does not read a property inherited from `Object.prototype`.
59
+ * The property is read before the check, so that a reactive `obj` tracks `key` even when it is missing.
60
+ */
61
+ function getOwn(obj, key) {
62
+ const value = obj[key];
63
+ return hasOwn(obj, key) ? value : void 0;
64
+ }
65
+ /**
66
+ * Whether `key` is a property name of `Object.prototype`, such as `__proto__`, `constructor` or `toString`.
67
+ * On a plain object, such a key reads a built-in, and assigning to `__proto__` replaces the prototype.
68
+ */
69
+ function isObjectPrototypeKey(key) {
70
+ return hasOwn(Object.prototype, key);
71
+ }
72
+ /**
127
73
  * Useful Utilities By Evan you
128
74
  * Modified by kazuya kawaguchi
129
75
  * MIT License
@@ -178,25 +124,130 @@ function generateCodeFrame(source, start = 0, end = source.length) {
178
124
  return res.join("\n");
179
125
  }
180
126
  //#endregion
127
+ //#region packages/shared/src/warn.ts
128
+ function warn(msg, err) {
129
+ if (typeof console !== "undefined") {
130
+ console.warn(`[intlify] ` + msg);
131
+ /* istanbul ignore if */
132
+ if (err) console.warn(err.stack);
133
+ }
134
+ }
135
+ const hasWarned = {};
136
+ function warnOnce(msg) {
137
+ if (!hasWarned[msg]) {
138
+ hasWarned[msg] = true;
139
+ warn(msg);
140
+ }
141
+ }
142
+ //#endregion
143
+ //#region packages/shared/src/sanitize.ts
144
+ function escapeHtml(rawText) {
145
+ return rawText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/\//g, "&#x2F;").replace(/=/g, "&#x3D;");
146
+ }
147
+ function escapeAttributeValue(value) {
148
+ return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
149
+ }
150
+ const javascriptSchemePattern = /^javascript:/i;
151
+ const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
152
+ const numericCharacterReferencePattern = /&#(?:x([0-9a-f]+)|(\d+));?/gi;
153
+ const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
154
+ const colonCharacterReferencePattern = /&colon;?/gi;
155
+ const controlOrWhitespacePattern = /[\u0000-\u0020\u007f-\u009f]/g;
156
+ const eventHandlerPattern = /(?:^|[\s"'<>/])on\w+\s*=\s*["']?[^"'>]+["']?/i;
157
+ const eventHandlerAttributePattern = /(^|[\s"'<>/])on(\w+\s*=)/gi;
158
+ const srcdocPattern = /(?:^|[\s"'<>/])srcdoc\s*=/i;
159
+ const srcdocAttributePattern = /(^|[\s"'<>/])s(rcdoc\s*=)/gi;
160
+ const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
161
+ function decodeNumericCharacterReference(match, hex, decimal) {
162
+ const digits = hex || decimal;
163
+ if (!digits) return match;
164
+ const codePoint = Number.parseInt(digits, hex ? 16 : 10);
165
+ return codePoint <= 127 ? String.fromCharCode(codePoint) : match;
166
+ }
167
+ function hasJavascriptScheme(value) {
168
+ const normalized = value.replace(numericCharacterReferencePattern, decodeNumericCharacterReference).replace(namedWhitespaceCharacterReferencePattern, "").replace(colonCharacterReferencePattern, ":").replace(controlOrWhitespacePattern, "");
169
+ return javascriptSchemePattern.test(normalized);
170
+ }
171
+ function sanitizeStyleValue(value) {
172
+ const urlPattern = /url\s*\(/gi;
173
+ let sanitized = "";
174
+ let cursor = 0;
175
+ let match;
176
+ while ((match = urlPattern.exec(value)) !== null) {
177
+ const urlStart = match.index;
178
+ const openParenIndex = urlPattern.lastIndex - 1;
179
+ let index = openParenIndex + 1;
180
+ let depth = 1;
181
+ let quote = null;
182
+ for (; index < value.length; index++) {
183
+ const char = value[index];
184
+ if (quote) {
185
+ if (char === quote) quote = null;
186
+ continue;
187
+ }
188
+ if (char === "\"" || char === "'") quote = char;
189
+ else if (char === "(") depth++;
190
+ else if (char === ")") {
191
+ depth--;
192
+ if (depth === 0) break;
193
+ }
194
+ }
195
+ if (depth !== 0) break;
196
+ const rawUrlValue = value.slice(openParenIndex + 1, index).trim();
197
+ const unquotedUrlValue = rawUrlValue.startsWith("\"") && rawUrlValue.endsWith("\"") || rawUrlValue.startsWith("'") && rawUrlValue.endsWith("'") ? rawUrlValue.slice(1, -1).trim() : rawUrlValue;
198
+ sanitized += value.slice(cursor, urlStart);
199
+ sanitized += hasJavascriptScheme(unquotedUrlValue) ? "url(about:blank)" : value.slice(urlStart, index + 1);
200
+ cursor = index + 1;
201
+ }
202
+ return sanitized + value.slice(cursor);
203
+ }
204
+ function sanitizeAttributeValue(attrName, value) {
205
+ if (urlAttributePattern.test(attrName) && hasJavascriptScheme(value)) return "about:blank";
206
+ return escapeAttributeValue(attrName.toLowerCase() === "style" ? sanitizeStyleValue(value) : value);
207
+ }
208
+ function sanitizeTranslatedHtml(html) {
209
+ html = html.replace(/([\w:-]+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${sanitizeAttributeValue(attrName, attrValue)}"`);
210
+ html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
211
+ if (eventHandlerPattern.test(html)) {
212
+ warn("Potentially dangerous event handlers detected in translation. Consider removing onclick, onerror, etc. from your translation messages.");
213
+ html = html.replace(eventHandlerAttributePattern, "$1&#111;n$2");
214
+ }
215
+ if (srcdocPattern.test(html)) {
216
+ warn("Potentially dangerous srcdoc attribute detected in translation. Consider removing srcdoc from your translation messages.");
217
+ html = html.replace(srcdocAttributePattern, "$1&#115;$2");
218
+ }
219
+ html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
220
+ return html;
221
+ }
222
+ //#endregion
181
223
  //#region packages/shared/src/messages.ts
182
224
  const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
183
225
  function deepCopy(src, des) {
184
- if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) throw new Error("Invalid value");
185
- const stack = [{
186
- src,
187
- des
188
- }];
226
+ if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des) || des === Object.prototype) throw new Error("Invalid value");
227
+ const stack = [src, des];
189
228
  while (stack.length) {
190
- const { src, des } = stack.pop();
191
- Object.keys(src).forEach((key) => {
192
- if (key === "__proto__") return;
193
- if (isObject(src[key]) && !isObject(des[key])) des[key] = Array.isArray(src[key]) ? [] : create();
194
- if (isNotObjectOrIsArray(des[key]) || isNotObjectOrIsArray(src[key])) des[key] = src[key];
195
- else stack.push({
196
- src: src[key],
197
- des: des[key]
198
- });
199
- });
229
+ const des = stack.pop();
230
+ const src = stack.pop();
231
+ const keys = Object.keys(src);
232
+ for (let i = 0; i < keys.length; i++) {
233
+ const key = keys[i];
234
+ if (key === "__proto__") continue;
235
+ const value = src[key];
236
+ if (!isObject(value)) {
237
+ des[key] = value;
238
+ continue;
239
+ }
240
+ if (isArray(value)) {
241
+ const copied = [];
242
+ copied.length = value.length;
243
+ des[key] = copied;
244
+ stack.push(value, copied);
245
+ continue;
246
+ }
247
+ let desValue = des[key];
248
+ if (!isObject(desValue) || isArray(desValue)) desValue = des[key] = create();
249
+ stack.push(value, desValue);
250
+ }
200
251
  }
201
252
  }
202
253
  //#endregion
@@ -363,11 +414,11 @@ let compileCache = create();
363
414
  function clearCompileCache() {
364
415
  compileCache = create();
365
416
  }
366
- /* @__NO_SIDE_EFFECTS__ */
417
+ /* #__NO_SIDE_EFFECTS__ */
367
418
  function compile(message, context) {
368
419
  {
369
420
  if (!isMessageAST(message)) {
370
- warn(`the message that is resolve with key '${context.key}' is not supported for jit compilation`);
421
+ warn(`Cannot compile the message of '${context.key}' key, because the message compiler is not included in this build. Pre-compile the message. So translate function returns the message as is.`);
371
422
  return (() => message);
372
423
  }
373
424
  const cacheKey = message.cacheKey;
@@ -384,12 +435,11 @@ const CoreErrorCodes = {
384
435
  INVALID_ARGUMENT: 17,
385
436
  INVALID_DATE_ARGUMENT: 18,
386
437
  INVALID_ISO_DATE_ARGUMENT: 19,
387
- NOT_SUPPORT_NON_STRING_MESSAGE: 20,
388
- NOT_SUPPORT_LOCALE_PROMISE_VALUE: 21,
389
- NOT_SUPPORT_LOCALE_ASYNC_FUNCTION: 22,
390
- NOT_SUPPORT_LOCALE_TYPE: 23
438
+ NOT_SUPPORT_LOCALE_PROMISE_VALUE: 20,
439
+ NOT_SUPPORT_LOCALE_ASYNC_FUNCTION: 21,
440
+ NOT_SUPPORT_LOCALE_TYPE: 22
391
441
  };
392
- const CORE_ERROR_CODES_EXTEND_POINT = 24;
442
+ const CORE_ERROR_CODES_EXTEND_POINT = 23;
393
443
  function createCoreError(code) {
394
444
  return createCompileError(code, null, { messages: errorMessages });
395
445
  }
@@ -398,7 +448,6 @@ const errorMessages = {
398
448
  [CoreErrorCodes.INVALID_ARGUMENT]: "Invalid arguments",
399
449
  [CoreErrorCodes.INVALID_DATE_ARGUMENT]: "The date provided is an invalid Date object.Make sure your Date represents a valid date.",
400
450
  [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: "The argument provided is not a valid ISO date string",
401
- [CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE]: "Not support non-string message",
402
451
  [CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE]: "cannot support promise value",
403
452
  [CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: "cannot support async function",
404
453
  [CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: "cannot support locale type"
@@ -413,13 +462,14 @@ let _resolveLocale;
413
462
  /** @internal */
414
463
  function resolveLocale(locale) {
415
464
  if (isString(locale)) return locale;
416
- else if (isFunction(locale)) if (locale.resolvedOnce && _resolveLocale != null) return _resolveLocale;
417
- else if (locale.constructor.name === "Function") {
418
- const resolve = locale();
419
- if (isPromise(resolve)) throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE);
420
- return _resolveLocale = resolve;
421
- } else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION);
422
- else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE);
465
+ else if (isFunction(locale)) {
466
+ if (locale.resolvedOnce && _resolveLocale != null) return _resolveLocale;
467
+ else if (locale.constructor.name === "Function") {
468
+ const resolve = locale();
469
+ if (isPromise(resolve)) throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE);
470
+ return _resolveLocale = resolve;
471
+ } else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION);
472
+ } else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE);
423
473
  }
424
474
  /**
425
475
  * Fallback with simple implemenation
@@ -427,7 +477,7 @@ function resolveLocale(locale) {
427
477
  * @remarks
428
478
  * A fallback locale function implemented with a simple fallback algorithm.
429
479
  *
430
- * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
480
+ * Basically, the chain consists of `start` plus the specified fallback: for a string or array `fallbackLocale`, the value as specified in the props is used; for a map `fallbackLocale`, the map's **keys** are used and the `default` key is skipped since it is not a locale name.
431
481
  *
432
482
  * @param ctx - A {@link CoreContext | context}
433
483
  * @param fallback - A {@link FallbackLocale | fallback locale}
@@ -438,7 +488,7 @@ function resolveLocale(locale) {
438
488
  * @VueI18nGeneral
439
489
  */
440
490
  function fallbackWithSimple(_ctx, fallback, start) {
441
- return [...new Set([start, ...isArray(fallback) ? fallback : isObject(fallback) ? Object.keys(fallback) : isString(fallback) ? [fallback] : [start]])];
491
+ return [.../* @__PURE__ */ new Set([start, ...isArray(fallback) ? fallback : isObject(fallback) ? Object.keys(fallback).filter((locale) => locale !== "default") : isString(fallback) ? [fallback] : [start]])];
442
492
  }
443
493
  /**
444
494
  * Fallback with locale chain
@@ -446,6 +496,9 @@ function fallbackWithSimple(_ctx, fallback, start) {
446
496
  * @remarks
447
497
  * A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
448
498
  *
499
+ * Chains are cached per fallback identity. If you mutate an object or array fallback in place,
500
+ * pass a new object or array instead so that the chain is recomputed.
501
+ *
449
502
  * @param ctx - A {@link CoreContext | context}
450
503
  * @param fallback - A {@link FallbackLocale | fallback locale}
451
504
  * @param start - A starting {@link Locale | locale}
@@ -459,17 +512,31 @@ function fallbackWithSimple(_ctx, fallback, start) {
459
512
  function fallbackWithLocaleChain(ctx, fallback, start) {
460
513
  const startLocale = isString(start) ? start : DEFAULT_LOCALE;
461
514
  const context = ctx;
462
- if (!context.__localeChainCache) context.__localeChainCache = /* @__PURE__ */ new Map();
463
- let chain = context.__localeChainCache.get(startLocale);
464
- if (!chain) {
465
- chain = [];
466
- let block = [start];
467
- while (isArray(block)) block = appendBlockToChain(chain, block, fallback);
468
- const defaults = isArray(fallback) || !isPlainObject(fallback) ? fallback : fallback["default"] ? fallback["default"] : null;
469
- block = isString(defaults) ? [defaults] : defaults;
470
- if (isArray(block)) appendBlockToChain(chain, block, false);
471
- context.__localeChainCache.set(startLocale, chain);
515
+ let chains;
516
+ if (isObject(fallback)) {
517
+ if (!context.__localeChainObjectCache) context.__localeChainObjectCache = /* @__PURE__ */ new WeakMap();
518
+ chains = context.__localeChainObjectCache.get(fallback);
519
+ if (!chains) {
520
+ chains = /* @__PURE__ */ new Map();
521
+ context.__localeChainObjectCache.set(fallback, chains);
522
+ }
523
+ } else {
524
+ if (!context.__localeChainCache) context.__localeChainCache = /* @__PURE__ */ new Map();
525
+ chains = context.__localeChainCache.get(fallback);
526
+ if (!chains) {
527
+ chains = /* @__PURE__ */ new Map();
528
+ context.__localeChainCache.set(fallback, chains);
529
+ }
472
530
  }
531
+ const cached = chains.get(startLocale);
532
+ if (cached) return cached;
533
+ const chain = [];
534
+ let block = [start];
535
+ while (isArray(block)) block = appendBlockToChain(chain, block, fallback);
536
+ const defaults = isArray(fallback) || !isPlainObject(fallback) ? fallback : fallback["default"] ? fallback["default"] : null;
537
+ block = isString(defaults) ? [defaults] : defaults;
538
+ if (isArray(block)) appendBlockToChain(chain, block, false);
539
+ chains.set(startLocale, chain);
473
540
  return chain;
474
541
  }
475
542
  function appendBlockToChain(chain, block, blocks) {
@@ -682,7 +749,7 @@ const cache = /* @__PURE__ */ new Map();
682
749
  * @VueI18nGeneral
683
750
  */
684
751
  function resolveWithKeyValue(obj, path) {
685
- return isObject(obj) ? obj[path] : null;
752
+ return isObject(obj) ? getOwn(obj, path) : null;
686
753
  }
687
754
  /**
688
755
  * message resolver
@@ -737,12 +804,15 @@ const CoreWarnCodes = {
737
804
  FALLBACK_TO_DATE_FORMAT: 6,
738
805
  EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7,
739
806
  INVALID_NUMBER_ARGUMENT: 8,
740
- INVALID_DATE_ARGUMENT: 9
807
+ INVALID_DATE_ARGUMENT: 9,
808
+ IGNORE_UNSAFE_LOCALE: 10,
809
+ FALLBACK_TO_DEFAULT_PLURAL_RULE: 11,
810
+ FALLBACK_FROM_INVALID_LOCALE: 12
741
811
  };
742
- const CORE_WARN_CODES_EXTEND_POINT = 10;
812
+ const CORE_WARN_CODES_EXTEND_POINT = 13;
743
813
  /** @internal */
744
814
  const warnMessages = {
745
- [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
815
+ [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale {resource}.`,
746
816
  [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
747
817
  [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
748
818
  [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
@@ -750,7 +820,10 @@ const warnMessages = {
750
820
  [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`,
751
821
  [CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER]: `This project is using Custom Message Compiler, which is an experimental feature. It may receive breaking changes or be removed in the future.`,
752
822
  [CoreWarnCodes.INVALID_NUMBER_ARGUMENT]: `Invalid argument for number formatting: expected a number but received '{value}'.`,
753
- [CoreWarnCodes.INVALID_DATE_ARGUMENT]: `Invalid argument for datetime formatting: expected a Date, number, or ISO string but received '{value}'.`
823
+ [CoreWarnCodes.INVALID_DATE_ARGUMENT]: `Invalid argument for datetime formatting: expected a Date, number, or ISO string but received '{value}'.`,
824
+ [CoreWarnCodes.IGNORE_UNSAFE_LOCALE]: `Ignore '{locale}' locale: it is a property name of Object.prototype`,
825
+ [CoreWarnCodes.FALLBACK_TO_DEFAULT_PLURAL_RULE]: `Fall back to the default plural rule for '{locale}' locale: Intl.PluralRules does not support it`,
826
+ [CoreWarnCodes.FALLBACK_FROM_INVALID_LOCALE]: `Fall back to '{target}' locale for {type} formatting with '{locale}' locale: it is not a BCP 47 language tag`
754
827
  };
755
828
  function getWarnMessage(code, ...args) {
756
829
  return format$1(warnMessages[code], ...args);
@@ -761,7 +834,7 @@ function getWarnMessage(code, ...args) {
761
834
  * Intlify core-base version
762
835
  * @internal
763
836
  */
764
- const VERSION = "12.0.0-alpha.4";
837
+ const VERSION = "12.0.0-alpha.6";
765
838
  const NOT_RESOLVED = -1;
766
839
  const DEFAULT_LOCALE = "en-US";
767
840
  const MISSING_RESOLVE_VALUE = "";
@@ -821,26 +894,21 @@ function registerLocaleFallbacker(fallbacker) {
821
894
  warnOnce(`registerLocaleFallbacker is deprecated. Use 'localeFallbacker' option of 'createI18n' or 'createCoreContext' instead.`);
822
895
  _fallbacker = fallbacker;
823
896
  }
824
- let _fallbackContext = null;
825
- const setFallbackContext = (context) => {
826
- _fallbackContext = context;
827
- };
828
- const getFallbackContext = () => _fallbackContext;
829
897
  let _cid = 0;
830
898
  function createCoreContext(options = {}) {
831
899
  const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
832
900
  const version = isString(options.version) ? options.version : VERSION;
833
901
  const locale = isString(options.locale) || isFunction(options.locale) ? options.locale : DEFAULT_LOCALE;
834
902
  const _locale = isFunction(locale) ? DEFAULT_LOCALE : locale;
835
- const fallbackLocale = isArray(options.fallbackLocale) || isPlainObject(options.fallbackLocale) || isString(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale;
903
+ const fallbackLocale = isFallbackLocale(options.fallbackLocale) ? options.fallbackLocale : _locale;
836
904
  const messages = isPlainObject(options.messages) ? options.messages : createResources(_locale);
837
905
  const datetimeFormats = isPlainObject(options.datetimeFormats) ? options.datetimeFormats : createResources(_locale);
838
906
  const numberFormats = isPlainObject(options.numberFormats) ? options.numberFormats : createResources(_locale);
839
907
  const modifiers = assign(create(), options.modifiers, getDefaultLinkedModifiers());
840
908
  const pluralRules = options.pluralRules || create();
841
909
  const missing = isFunction(options.missing) ? options.missing : null;
842
- const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn) ? options.missingWarn : true;
843
- const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn) ? options.fallbackWarn : true;
910
+ const missingWarn = isWarnOption(options.missingWarn) ? options.missingWarn : true;
911
+ const fallbackWarn = isWarnOption(options.fallbackWarn) ? options.fallbackWarn : true;
844
912
  const fallbackFormat = !!options.fallbackFormat;
845
913
  const unresolving = !!options.unresolving;
846
914
  const postTranslation = isFunction(options.postTranslation) ? options.postTranslation : null;
@@ -848,13 +916,9 @@ function createCoreContext(options = {}) {
848
916
  const warnHtmlMessage = isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true;
849
917
  const escapeParameter = !!options.escapeParameter;
850
918
  const messageCompiler = isFunction(options.messageCompiler) ? options.messageCompiler : _compiler || null;
851
- if (isFunction(options.messageCompiler)) warnOnce(getWarnMessage(CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER));
852
919
  const messageResolver = isFunction(options.messageResolver) ? options.messageResolver : _resolver || resolveWithKeyValue;
853
920
  const localeFallbacker = isFunction(options.localeFallbacker) ? options.localeFallbacker : _fallbacker || fallbackWithSimple;
854
921
  const fallbackContext = isObject(options.fallbackContext) ? options.fallbackContext : void 0;
855
- const internalOptions = options;
856
- const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters) ? internalOptions.__datetimeFormatters : /* @__PURE__ */ new Map();
857
- const __numberFormatters = isObject(internalOptions.__numberFormatters) ? internalOptions.__numberFormatters : /* @__PURE__ */ new Map();
858
922
  _cid++;
859
923
  const context = {
860
924
  version,
@@ -881,9 +945,8 @@ function createCoreContext(options = {}) {
881
945
  };
882
946
  context.datetimeFormats = datetimeFormats;
883
947
  context.numberFormats = numberFormats;
884
- context.__datetimeFormatters = __datetimeFormatters;
885
- context.__numberFormatters = __numberFormatters;
886
- context.__v_emitter = internalOptions.__v_emitter != null ? internalOptions.__v_emitter : void 0;
948
+ context.__datetimeFormatters = /* @__PURE__ */ new Map();
949
+ context.__numberFormatters = /* @__PURE__ */ new Map();
887
950
  return context;
888
951
  }
889
952
  const createResources = (locale) => ({ [locale]: create() });
@@ -891,7 +954,7 @@ const createResources = (locale) => ({ [locale]: create() });
891
954
  * @version 12.0.0
892
955
  */
893
956
  function getLocaleMessage(ctx, locale) {
894
- const src = ctx.messages[locale];
957
+ const src = getOwn(ctx.messages, locale);
895
958
  if (src == null) return;
896
959
  const dest = create();
897
960
  deepCopy(src, dest);
@@ -901,9 +964,21 @@ function getLocaleMessage(ctx, locale) {
901
964
  * @version 12.0.0
902
965
  */
903
966
  function setLocaleMessage(ctx, locale, messages) {
967
+ if (isObjectPrototypeKey(locale)) {
968
+ ctx.onWarn(getWarnMessage(CoreWarnCodes.IGNORE_UNSAFE_LOCALE, { locale }));
969
+ return;
970
+ }
904
971
  ctx.messages[locale] = messages;
905
972
  }
906
973
  /** @internal */
974
+ function isFallbackLocale(val) {
975
+ return isString(val) || isArray(val) || isPlainObject(val) || val === false;
976
+ }
977
+ /** @internal */
978
+ function isWarnOption(val) {
979
+ return isBoolean(val) || isRegExp(val);
980
+ }
981
+ /** @internal */
907
982
  function isTranslateFallbackWarn(fallback, key) {
908
983
  return isRegExp(fallback) ? fallback.test(key) : fallback;
909
984
  }
@@ -920,7 +995,7 @@ function handleMissing(context, key, locale, missingWarn, type) {
920
995
  locale,
921
996
  key,
922
997
  type,
923
- groupId: `${type}:${key}`
998
+ groupId: toDevtoolsGroupId(type, key)
924
999
  });
925
1000
  }
926
1001
  if (missing !== null) {
@@ -929,15 +1004,26 @@ function handleMissing(context, key, locale, missingWarn, type) {
929
1004
  } else {
930
1005
  if (isTranslateMissingWarn(missingWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, {
931
1006
  key,
932
- locale
1007
+ locale,
1008
+ resource: type === "datetime format" ? "datetime formats" : type === "number format" ? "number formats" : "messages"
933
1009
  }));
934
1010
  return key;
935
1011
  }
936
1012
  }
1013
+ function invalidateLocaleChainCache(ctx, fallback) {
1014
+ const context = ctx;
1015
+ if (isObject(fallback)) context.__localeChainObjectCache?.delete(fallback);
1016
+ else context.__localeChainCache?.delete(fallback);
1017
+ }
937
1018
  /** @internal */
938
1019
  function updateFallbackLocale(ctx, locale, fallback) {
939
- const context = ctx;
940
- context.__localeChainCache = /* @__PURE__ */ new Map();
1020
+ invalidateLocaleChainCache(ctx, fallback);
1021
+ if (ctx.fallbackContext) invalidateLocaleChainCache(ctx.fallbackContext, fallback);
1022
+ {
1023
+ const { __datetimeFormatters, __numberFormatters } = ctx;
1024
+ __datetimeFormatters.clear();
1025
+ __numberFormatters.clear();
1026
+ }
941
1027
  ctx.localeFallbacker(ctx, fallback, locale);
942
1028
  }
943
1029
  /** @internal */
@@ -953,41 +1039,14 @@ function isImplicitFallback(targetLocale, locales) {
953
1039
  return false;
954
1040
  }
955
1041
  //#endregion
956
- //#region packages/core-base/src/intl.ts
957
- const intlDefined = typeof Intl !== "undefined";
958
- const Availabilities = {
959
- dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== "undefined",
960
- numberFormat: intlDefined && typeof Intl.NumberFormat !== "undefined"
961
- };
962
- //#endregion
963
- //#region packages/core-base/src/datetime.ts
964
- function datetime(context, ...args) {
965
- const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
966
- const { __datetimeFormatters } = context;
967
- if (!Availabilities.dateTimeFormat) {
968
- onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
969
- return "";
970
- }
971
- if (!isString(args[0]) && !isDate(args[0]) && !isNumber(args[0])) {
972
- onWarn(getWarnMessage(CoreWarnCodes.INVALID_DATE_ARGUMENT, { value: String(args[0]) }));
973
- return "";
974
- }
975
- const [key, value, options, overrides] = parseDateTimeArgs(...args);
976
- const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
977
- const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
978
- const part = !!options.part;
979
- const locale = getLocale(context, options);
1042
+ //#region packages/core-base/src/formatter.ts
1043
+ function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
1044
+ const { fallbackLocale, localeFallbacker, onWarn } = context;
980
1045
  const locales = localeFallbacker(context, fallbackLocale, locale);
981
- if (!isString(key) || key === "") return new Intl.DateTimeFormat(locale.replace(/!/g, ""), overrides).format(value);
982
- let datetimeFormat = {};
983
- let targetLocale;
984
- let format = null;
985
1046
  let from = locale;
986
- let to = null;
987
- const type = "datetime format";
988
1047
  for (let i = 0; i < locales.length; i++) {
989
- targetLocale = to = locales[i];
990
- if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
1048
+ const targetLocale = locales[i];
1049
+ if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(type === "datetime format" ? CoreWarnCodes.FALLBACK_TO_DATE_FORMAT : CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
991
1050
  key,
992
1051
  target: targetLocale
993
1052
  }));
@@ -997,26 +1056,119 @@ function datetime(context, ...args) {
997
1056
  type,
998
1057
  key,
999
1058
  from,
1000
- to,
1001
- groupId: `${type}:${key}`
1059
+ to: targetLocale,
1060
+ groupId: toDevtoolsGroupId(type, key)
1002
1061
  });
1003
1062
  }
1004
- datetimeFormat = datetimeFormats[targetLocale] || {};
1005
- format = datetimeFormat[key];
1006
- if (isPlainObject(format)) break;
1063
+ const format = getOwn(getOwn(formats, targetLocale) || {}, key);
1064
+ if (isPlainObject(format) && isString(targetLocale)) return targetLocale;
1007
1065
  handleMissing(context, key, targetLocale, missingWarn, type);
1008
- from = to;
1066
+ from = targetLocale;
1009
1067
  }
1010
- if (!isPlainObject(format) || !isString(targetLocale)) return unresolving ? -1 : key;
1011
- let id = `${targetLocale}__${key}`;
1012
- if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
1013
- let formatter = __datetimeFormatters.get(id);
1068
+ return null;
1069
+ }
1070
+ function isLanguageTag(locale) {
1071
+ try {
1072
+ Intl.getCanonicalLocales(locale);
1073
+ return true;
1074
+ } catch {
1075
+ return false;
1076
+ }
1077
+ }
1078
+ /**
1079
+ * Create an `Intl.DateTimeFormat` or `Intl.NumberFormat` formatter
1080
+ *
1081
+ * @remarks
1082
+ * `Intl` throws a RangeError for a locale that is not a BCP 47 language tag (e.g. `pt_BR`),
1083
+ * so fall back to the first language tag in the locale chain, or the default locale
1084
+ */
1085
+ function createFormatter(context, IntlFormatter, locale, options, type) {
1086
+ try {
1087
+ return new IntlFormatter(locale, options);
1088
+ } catch (error) {
1089
+ if (isLanguageTag(locale)) throw error;
1090
+ const { fallbackLocale, localeFallbacker, onWarn } = context;
1091
+ const target = localeFallbacker(context, fallbackLocale, locale).find(isLanguageTag) || "en-US";
1092
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_FROM_INVALID_LOCALE, {
1093
+ locale,
1094
+ target,
1095
+ type: type === "datetime format" ? "datetime" : "number"
1096
+ }));
1097
+ return new IntlFormatter(target, options);
1098
+ }
1099
+ }
1100
+ /**
1101
+ * Format a value with the format of a key, or only with the overrides when no key is given
1102
+ *
1103
+ * @remarks
1104
+ * The common part of `datetime()` and `number()`, after they check and parse the arguments
1105
+ */
1106
+ function formatValue(context, [key, value, options, overrides], IntlFormatter, formatters, formats, type) {
1107
+ const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
1108
+ const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
1109
+ const part = !!options.part;
1110
+ const locale = getLocale(context, options);
1111
+ if (!isString(key) || key === "") {
1112
+ const formatter = createFormatter(context, IntlFormatter, locale.replace(/!/g, ""), overrides, type);
1113
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1114
+ }
1115
+ const targetLocale = resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type);
1116
+ if (!isString(targetLocale)) return context.unresolving ? -1 : key;
1117
+ const format = formats[targetLocale][key];
1118
+ const id = getFormatterCacheKey(targetLocale, key, overrides);
1119
+ let formatter = formatters.get(id);
1014
1120
  if (!formatter) {
1015
- formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
1016
- __datetimeFormatters.set(id, formatter);
1121
+ formatter = createFormatter(context, IntlFormatter, targetLocale, assign({}, format, overrides), type);
1122
+ formatters.set(id, formatter);
1017
1123
  }
1018
1124
  return !part ? formatter.format(value) : formatter.formatToParts(value);
1019
1125
  }
1126
+ function getFormatterCacheKey(locale, key, overrides) {
1127
+ let id = `${locale}__${key}`;
1128
+ if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
1129
+ return id;
1130
+ }
1131
+ function clearFormatCache(formatters, locale, format) {
1132
+ for (const key in format) {
1133
+ const prefix = `${locale}__${key}`;
1134
+ for (const id of formatters.keys()) if (id === prefix || id.startsWith(`${prefix}__`)) formatters.delete(id);
1135
+ }
1136
+ }
1137
+ function parseFormatArgs(args, options, initialOverrides, optionsKeys) {
1138
+ const [, arg2, arg3, arg4] = args;
1139
+ let overrides = initialOverrides;
1140
+ if (isString(arg2)) options.key = arg2;
1141
+ else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
1142
+ if (optionsKeys.includes(key)) overrides[key] = arg2[key];
1143
+ else options[key] = arg2[key];
1144
+ });
1145
+ if (isString(arg3)) options.locale = arg3;
1146
+ else if (isPlainObject(arg3)) overrides = arg3;
1147
+ if (isPlainObject(arg4)) overrides = arg4;
1148
+ return overrides;
1149
+ }
1150
+ //#endregion
1151
+ //#region packages/core-base/src/intl.ts
1152
+ const intlDefined = typeof Intl !== "undefined";
1153
+ const Availabilities = {
1154
+ dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== "undefined",
1155
+ numberFormat: intlDefined && typeof Intl.NumberFormat !== "undefined"
1156
+ };
1157
+ //#endregion
1158
+ //#region packages/core-base/src/datetime.ts
1159
+ function datetime(context, ...args) {
1160
+ const { datetimeFormats, onWarn } = context;
1161
+ const { __datetimeFormatters } = context;
1162
+ if (!Availabilities.dateTimeFormat) {
1163
+ onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
1164
+ return "";
1165
+ }
1166
+ if (!isString(args[0]) && !isDate(args[0]) && !isNumber(args[0])) {
1167
+ onWarn(getWarnMessage(CoreWarnCodes.INVALID_DATE_ARGUMENT, { value: String(args[0]) }));
1168
+ return "";
1169
+ }
1170
+ return formatValue(context, parseDateTimeArgs(...args), Intl.DateTimeFormat, __datetimeFormatters, datetimeFormats, "datetime format");
1171
+ }
1020
1172
  /** @internal */
1021
1173
  const DATETIME_FORMAT_OPTIONS_KEYS = [
1022
1174
  "localeMatcher",
@@ -1042,12 +1194,12 @@ const DATETIME_FORMAT_OPTIONS_KEYS = [
1042
1194
  ];
1043
1195
  /** @internal */
1044
1196
  function parseDateTimeArgs(...args) {
1045
- const [arg1, arg2, arg3, arg4] = args;
1197
+ const [arg1] = args;
1046
1198
  const options = create();
1047
- let overrides = create();
1199
+ const initialOverrides = create();
1048
1200
  let value;
1049
1201
  if (isString(arg1)) {
1050
- const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
1202
+ const matches = arg1.match(/^(\d{4}-\d{2}-\d{2})(?:(T|\s)(.+))?$/);
1051
1203
  if (!matches) throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1052
1204
  const dateTime = matches[3] ? matches[3].trim().startsWith("T") ? `${matches[1].trim()}${matches[3].trim()}` : `${matches[1].trim()}T${matches[3].trim()}` : matches[1].trim();
1053
1205
  value = new Date(dateTime);
@@ -1061,14 +1213,7 @@ function parseDateTimeArgs(...args) {
1061
1213
  value = arg1;
1062
1214
  } else if (isNumber(arg1)) value = arg1;
1063
1215
  else throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1064
- if (isString(arg2)) options.key = arg2;
1065
- else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
1066
- if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) overrides[key] = arg2[key];
1067
- else options[key] = arg2[key];
1068
- });
1069
- if (isString(arg3)) options.locale = arg3;
1070
- else if (isPlainObject(arg3)) overrides = arg3;
1071
- if (isPlainObject(arg4)) overrides = arg4;
1216
+ const overrides = parseFormatArgs(args, options, initialOverrides, DATETIME_FORMAT_OPTIONS_KEYS);
1072
1217
  return [
1073
1218
  options.key || "",
1074
1219
  value,
@@ -1078,17 +1223,12 @@ function parseDateTimeArgs(...args) {
1078
1223
  }
1079
1224
  /** @internal */
1080
1225
  function clearDateTimeFormat(ctx, locale, format) {
1081
- const context = ctx;
1082
- for (const key in format) {
1083
- const id = `${locale}__${key}`;
1084
- if (!context.__datetimeFormatters.has(id)) continue;
1085
- context.__datetimeFormatters.delete(id);
1086
- }
1226
+ clearFormatCache(ctx.__datetimeFormatters, locale, format);
1087
1227
  }
1088
1228
  //#endregion
1089
1229
  //#region packages/core-base/src/number.ts
1090
1230
  function number(context, ...args) {
1091
- const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1231
+ const { numberFormats, onWarn } = context;
1092
1232
  const { __numberFormatters } = context;
1093
1233
  if (!Availabilities.numberFormat) {
1094
1234
  onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
@@ -1098,50 +1238,7 @@ function number(context, ...args) {
1098
1238
  onWarn(getWarnMessage(CoreWarnCodes.INVALID_NUMBER_ARGUMENT, { value: String(args[0]) }));
1099
1239
  return "";
1100
1240
  }
1101
- const [key, value, options, overrides] = parseNumberArgs(...args);
1102
- const missingWarn = isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn;
1103
- const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
1104
- const part = !!options.part;
1105
- const locale = getLocale(context, options);
1106
- const locales = localeFallbacker(context, fallbackLocale, locale);
1107
- if (!isString(key) || key === "") return new Intl.NumberFormat(locale.replace(/!/g, ""), overrides).format(value);
1108
- let numberFormat = {};
1109
- let targetLocale;
1110
- let format = null;
1111
- let from = locale;
1112
- let to = null;
1113
- const type = "number format";
1114
- for (let i = 0; i < locales.length; i++) {
1115
- targetLocale = to = locales[i];
1116
- if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
1117
- key,
1118
- target: targetLocale
1119
- }));
1120
- if (locale !== targetLocale) {
1121
- const emitter = context.__v_emitter;
1122
- if (emitter) emitter.emit("fallback", {
1123
- type,
1124
- key,
1125
- from,
1126
- to,
1127
- groupId: `${type}:${key}`
1128
- });
1129
- }
1130
- numberFormat = numberFormats[targetLocale] || {};
1131
- format = numberFormat[key];
1132
- if (isPlainObject(format)) break;
1133
- handleMissing(context, key, targetLocale, missingWarn, type);
1134
- from = to;
1135
- }
1136
- if (!isPlainObject(format) || !isString(targetLocale)) return unresolving ? -1 : key;
1137
- let id = `${targetLocale}__${key}`;
1138
- if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
1139
- let formatter = __numberFormatters.get(id);
1140
- if (!formatter) {
1141
- formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
1142
- __numberFormatters.set(id, formatter);
1143
- }
1144
- return !part ? formatter.format(value) : formatter.formatToParts(value);
1241
+ return formatValue(context, parseNumberArgs(...args), Intl.NumberFormat, __numberFormatters, numberFormats, "number format");
1145
1242
  }
1146
1243
  /** @internal */
1147
1244
  const NUMBER_FORMAT_OPTIONS_KEYS = [
@@ -1168,19 +1265,12 @@ const NUMBER_FORMAT_OPTIONS_KEYS = [
1168
1265
  ];
1169
1266
  /** @internal */
1170
1267
  function parseNumberArgs(...args) {
1171
- const [arg1, arg2, arg3, arg4] = args;
1268
+ const [arg1] = args;
1172
1269
  const options = create();
1173
- let overrides = create();
1270
+ const initialOverrides = create();
1174
1271
  if (!isNumber(arg1)) throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1175
1272
  const value = arg1;
1176
- if (isString(arg2)) options.key = arg2;
1177
- else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
1178
- if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) overrides[key] = arg2[key];
1179
- else options[key] = arg2[key];
1180
- });
1181
- if (isString(arg3)) options.locale = arg3;
1182
- else if (isPlainObject(arg3)) overrides = arg3;
1183
- if (isPlainObject(arg4)) overrides = arg4;
1273
+ const overrides = parseFormatArgs(args, options, initialOverrides, NUMBER_FORMAT_OPTIONS_KEYS);
1184
1274
  return [
1185
1275
  options.key || "",
1186
1276
  value,
@@ -1190,12 +1280,7 @@ function parseNumberArgs(...args) {
1190
1280
  }
1191
1281
  /** @internal */
1192
1282
  function clearNumberFormat(ctx, locale, format) {
1193
- const context = ctx;
1194
- for (const key in format) {
1195
- const id = `${locale}__${key}`;
1196
- if (!context.__numberFormatters.has(id)) continue;
1197
- context.__numberFormatters.delete(id);
1198
- }
1283
+ clearFormatCache(ctx.__numberFormatters, locale, format);
1199
1284
  }
1200
1285
  //#endregion
1201
1286
  //#region packages/core-base/src/runtime.ts
@@ -1218,14 +1303,25 @@ const PLURAL_CATEGORY_ORDER = [
1218
1303
  "other"
1219
1304
  ];
1220
1305
  const intlPluralRulesCache = /* @__PURE__ */ new Map();
1221
- function getIntlPluralRules(locale) {
1222
- let cached = intlPluralRulesCache.get(locale);
1223
- if (!cached) {
1306
+ const INTL_PLURAL_RULES_CACHE_SIZE = 1e3;
1307
+ function createIntlPluralRules(locale) {
1308
+ try {
1309
+ if (Intl.PluralRules.supportedLocalesOf(locale).length === 0) return null;
1224
1310
  const rules = new Intl.PluralRules(locale);
1225
- cached = {
1311
+ return {
1226
1312
  rules,
1227
1313
  categories: rules.resolvedOptions().pluralCategories.slice().sort((a, b) => PLURAL_CATEGORY_ORDER.indexOf(a) - PLURAL_CATEGORY_ORDER.indexOf(b))
1228
1314
  };
1315
+ } catch {
1316
+ return null;
1317
+ }
1318
+ }
1319
+ function getIntlPluralRules(locale) {
1320
+ let cached = intlPluralRulesCache.get(locale);
1321
+ if (cached === void 0) {
1322
+ cached = createIntlPluralRules(locale);
1323
+ if (cached === null) warn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DEFAULT_PLURAL_RULE, { locale }));
1324
+ if (intlPluralRulesCache.size >= INTL_PLURAL_RULES_CACHE_SIZE) intlPluralRulesCache.delete(intlPluralRulesCache.keys().next().value);
1229
1325
  intlPluralRulesCache.set(locale, cached);
1230
1326
  }
1231
1327
  return cached;
@@ -1238,10 +1334,11 @@ function createMessageContext(options = {}) {
1238
1334
  const locale = options.locale;
1239
1335
  const pluralIndex = getPluralIndex(options);
1240
1336
  let resolvedPluralRule;
1241
- if (isString(locale) && isFunction(options.pluralRules?.[locale])) resolvedPluralRule = options.pluralRules[locale];
1337
+ if (isString(locale) && options.pluralRules && isFunction(getOwn(options.pluralRules, locale))) resolvedPluralRule = options.pluralRules[locale];
1242
1338
  else if (isString(locale) && typeof Intl !== "undefined" && typeof Intl.PluralRules !== "undefined") resolvedPluralRule = (choice, choicesLength) => {
1243
- const { rules, categories } = getIntlPluralRules(locale);
1244
- if (choicesLength > categories.length) return pluralDefault(choice, choicesLength);
1339
+ const intlPluralRules = getIntlPluralRules(locale);
1340
+ if (intlPluralRules === null || choicesLength > intlPluralRules.categories.length) return pluralDefault(choice, choicesLength);
1341
+ const { rules, categories } = intlPluralRules;
1245
1342
  const category = rules.select(Math.abs(choice));
1246
1343
  const index = categories.indexOf(category);
1247
1344
  return Math.min(index === -1 ? choicesLength - 1 : index, choicesLength - 1);
@@ -1252,16 +1349,16 @@ function createMessageContext(options = {}) {
1252
1349
  const _list = options.list || [];
1253
1350
  const list = (index) => _list[index];
1254
1351
  const _named = options.named || create();
1255
- if (isNumber(options.pluralIndex)) {
1256
- _named.count ??= options.pluralIndex;
1257
- _named.n ??= options.pluralIndex;
1258
- }
1259
- const named = (key) => _named[key];
1352
+ const hasPluralIndex = isNumber(options.pluralIndex);
1353
+ const named = (key) => {
1354
+ const value = isObjectPrototypeKey(key) ? getOwn(_named, key) : _named[key];
1355
+ return hasPluralIndex && value == null && (key === "count" || key === "n") ? options.pluralIndex : value;
1356
+ };
1260
1357
  function message(key, useLinked) {
1261
1358
  const msg = isFunction(options.messages) ? options.messages(key, !!useLinked) : isObject(options.messages) ? options.messages[key] : false;
1262
1359
  return !msg ? options.parent ? options.parent.message(key) : DEFAULT_MESSAGE : msg;
1263
1360
  }
1264
- const _modifier = (name) => options.modifiers ? options.modifiers[name] : DEFAULT_MODIFIER;
1361
+ const _modifier = (name) => options.modifiers ? getOwn(options.modifiers, name) : DEFAULT_MODIFIER;
1265
1362
  const normalize = isFunction(options.processor?.normalize) ? options.processor.normalize : DEFAULT_NORMALIZE;
1266
1363
  const interpolate = isFunction(options.processor?.interpolate) ? options.processor.interpolate : DEFAULT_INTERPOLATE;
1267
1364
  const type = isString(options.processor?.type) ? options.processor.type : DEFAULT_MESSAGE_DATA_TYPE;
@@ -1281,7 +1378,11 @@ function createMessageContext(options = {}) {
1281
1378
  const ret = message(key, true)(ctx);
1282
1379
  const resolved = ret === "" || ret === void 0 ? key : ret;
1283
1380
  const msg = type === "vnode" && isArray(resolved) && modifier ? resolved[0] : resolved;
1284
- return modifier ? _modifier(modifier)(msg, type) : msg;
1381
+ if (!modifier) return msg;
1382
+ const modify = _modifier(modifier);
1383
+ if (isFunction(modify)) return modify(msg, type);
1384
+ warnOnce(`Not found '${modifier}' modifier for the linked message of '${key}' key. Use a built-in modifier, or set a custom modifier with 'modifiers' option. So the linked message is used as is.`);
1385
+ return msg;
1285
1386
  };
1286
1387
  const ctx = {
1287
1388
  ["list"]: list,
@@ -1292,7 +1393,10 @@ function createMessageContext(options = {}) {
1292
1393
  ["type"]: type,
1293
1394
  ["interpolate"]: interpolate,
1294
1395
  ["normalize"]: normalize,
1295
- ["values"]: assign(create(), _list, _named)
1396
+ ["values"]: assign(create(), _list, _named, hasPluralIndex ? {
1397
+ count: named("count"),
1398
+ n: named("n")
1399
+ } : {})
1296
1400
  };
1297
1401
  return ctx;
1298
1402
  }
@@ -1300,6 +1404,8 @@ function createMessageContext(options = {}) {
1300
1404
  //#region packages/core-base/src/translate.ts
1301
1405
  const NOOP_MESSAGE_FUNCTION = () => "";
1302
1406
  const isMessageFunction = (val) => isFunction(val);
1407
+ /** @internal */
1408
+ const isMessageFormat = (val) => isString(val) || isMessageAST(val) || isMessageFunction(val);
1303
1409
  function translate(context, ...args) {
1304
1410
  const [key, options] = parseTranslateArgs(...args);
1305
1411
  const locale = getLocale(context, options);
@@ -1309,21 +1415,18 @@ function translate(context, ...args) {
1309
1415
  let [format, targetLocale, message] = !resolvedMessage ? resolveMessageFormat(context, key, locale, context.fallbackLocale, isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn, isBoolean(options.missingWarn) ? options.missingWarn : context.missingWarn) : [
1310
1416
  key,
1311
1417
  locale,
1312
- context.messages[locale] || create()
1418
+ getOwn(context.messages, locale) || create()
1313
1419
  ];
1314
1420
  let cacheBaseKey = key;
1315
- if (!resolvedMessage && !(isString(format) || isMessageAST(format) || isMessageFunction(format))) {
1421
+ if (!resolvedMessage && !isMessageFormat(format)) {
1316
1422
  const defaultMsgOrKey = isString(options.default) ? options.default : isBoolean(options.default) || context.fallbackFormat ? !context.messageCompiler ? () => key : key : null;
1317
1423
  if (context.fallbackFormat || defaultMsgOrKey != null && (isString(defaultMsgOrKey) || isFunction(defaultMsgOrKey))) {
1318
1424
  format = defaultMsgOrKey;
1319
1425
  cacheBaseKey = format;
1320
1426
  }
1321
1427
  }
1322
- if (!resolvedMessage && (!(isString(format) || isMessageAST(format) || isMessageFunction(format)) || !isString(targetLocale))) return context.unresolving ? -1 : key;
1323
- if (isString(format) && context.messageCompiler == null) {
1324
- warn(`The message format compilation is not supported in this build. Because message compiler isn't included. You need to pre-compilation all message format. So translate function return '${isString(key) ? key : isObject(key) ? JSON.stringify(key) : isFunction(key) ? key.name || "function" : ""}'.`);
1325
- return key;
1326
- }
1428
+ if (!resolvedMessage && (!isMessageFormat(format) || !isString(targetLocale))) return context.unresolving ? -1 : key;
1429
+ if (isString(format) && context.messageCompiler == null) warn(`Cannot compile the message of '${stringifyKey(key)}' key, because no message compiler is set. Use 'messageCompiler' option of 'createCoreContext', or pre-compile the message. So translate function returns the message as is.`);
1327
1430
  let occurred = false;
1328
1431
  const onError = () => {
1329
1432
  occurred = true;
@@ -1331,16 +1434,29 @@ function translate(context, ...args) {
1331
1434
  const msg = !isMessageFunction(format) ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) : format;
1332
1435
  if (occurred) return format;
1333
1436
  const msgContext = createMessageContext(getMessageContextOptions(context, targetLocale, message, options));
1334
- const messaged = inBrowser ? measureEvaluateMessage(context, msg, msgContext) : msg(msgContext);
1437
+ const timeline = startTimelineMeasure(context, "evaluation");
1438
+ const messaged = msg(msgContext);
1439
+ if (timeline) timeline.emitter.emit("message-evaluation", {
1440
+ type: "message-evaluation",
1441
+ value: messaged,
1442
+ time: endTimelineMeasure(timeline),
1443
+ groupId: toDevtoolsGroupId("translate", msg.key)
1444
+ });
1335
1445
  let ret = context.postTranslation ? context.postTranslation(messaged, key) : messaged;
1336
1446
  if (escapeParameter && isString(ret)) ret = sanitizeTranslatedHtml(ret);
1337
1447
  return ret;
1338
1448
  }
1339
1449
  function escapeParams(options) {
1340
1450
  if (isArray(options.list)) options.list = options.list.map((item) => isString(item) ? escapeHtml(item) : item);
1341
- else if (isObject(options.named)) Object.keys(options.named).forEach((key) => {
1342
- if (isString(options.named[key])) options.named[key] = escapeHtml(options.named[key]);
1343
- });
1451
+ if (isObject(options.named)) {
1452
+ const source = options.named;
1453
+ const named = create();
1454
+ for (const key of Object.keys(source)) {
1455
+ const value = source[key];
1456
+ named[key] = isString(value) ? escapeHtml(value) : value;
1457
+ }
1458
+ options.named = named;
1459
+ }
1344
1460
  }
1345
1461
  function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
1346
1462
  const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
@@ -1363,36 +1479,23 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
1363
1479
  key,
1364
1480
  from,
1365
1481
  to: targetLocale,
1366
- groupId: `${type}:${key}`
1482
+ groupId: toDevtoolsGroupId(type, key)
1367
1483
  });
1368
1484
  }
1369
- message = messages[targetLocale] || create();
1370
- let start = null;
1371
- let startTag;
1372
- let endTag;
1373
- if (inBrowser) {
1374
- start = window.performance.now();
1375
- startTag = "intlify-message-resolve-start";
1376
- endTag = "intlify-message-resolve-end";
1377
- mark?.(startTag);
1378
- }
1379
- if ((format = resolveValue(message, key)) === null) format = message[key];
1380
- if (inBrowser) {
1381
- const end = window.performance.now();
1382
- const emitter = context.__v_emitter;
1383
- if (emitter && start && format) emitter.emit("message-resolve", {
1485
+ message = getOwn(messages, targetLocale) || create();
1486
+ const timeline = startTimelineMeasure(context, "resolve");
1487
+ if ((format = resolveValue(message, key)) === null) format = getOwn(message, key);
1488
+ if (timeline) {
1489
+ const time = endTimelineMeasure(timeline);
1490
+ if (format) timeline.emitter.emit("message-resolve", {
1384
1491
  type: "message-resolve",
1385
1492
  key,
1386
1493
  message: format,
1387
- time: end - start,
1388
- groupId: `${type}:${key}`
1494
+ time,
1495
+ groupId: toDevtoolsGroupId(type, key)
1389
1496
  });
1390
- if (startTag && endTag && mark && measure) {
1391
- mark(endTag);
1392
- measure("intlify message resolve", startTag, endTag);
1393
- }
1394
1497
  }
1395
- if (isString(format) || isMessageAST(format) || isMessageFunction(format)) break;
1498
+ if (isMessageFormat(format)) break;
1396
1499
  if (!isImplicitFallback(targetLocale, locales)) {
1397
1500
  const missingRet = handleMissing(context, key, targetLocale, missingWarn, type);
1398
1501
  if (missingRet !== key) format = missingRet;
@@ -1405,6 +1508,9 @@ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn
1405
1508
  message
1406
1509
  ];
1407
1510
  }
1511
+ function stringifyKey(key) {
1512
+ return isString(key) ? key : isObject(key) ? JSON.stringify(key) : isFunction(key) ? key.name || "function" : "";
1513
+ }
1408
1514
  function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) {
1409
1515
  if (isMessageFunction(format)) {
1410
1516
  const msg = format;
@@ -1418,55 +1524,40 @@ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey,
1418
1524
  msg.key = key;
1419
1525
  return msg;
1420
1526
  }
1421
- let start = null;
1422
- let startTag;
1423
- let endTag;
1424
- if (inBrowser && mark) {
1425
- start = window.performance.now();
1426
- startTag = "intlify-message-compilation-start";
1427
- endTag = "intlify-message-compilation-end";
1428
- mark?.(startTag);
1429
- }
1527
+ const timeline = startTimelineMeasure(context, "compilation");
1430
1528
  const msg = context.messageCompiler(format, getCompileContext(context, targetLocale, cacheBaseKey, format, context.warnHtmlMessage, onError));
1431
- if (inBrowser) {
1432
- const end = window.performance.now();
1433
- const emitter = context.__v_emitter;
1434
- if (emitter && start) emitter.emit("message-compilation", {
1435
- type: "message-compilation",
1436
- message: format,
1437
- time: end - start,
1438
- groupId: `translate:${key}`
1439
- });
1440
- if (startTag && endTag && mark && measure) {
1441
- mark(endTag);
1442
- measure("intlify message compilation", startTag, endTag);
1443
- }
1444
- }
1529
+ if (timeline) timeline.emitter.emit("message-compilation", {
1530
+ type: "message-compilation",
1531
+ message: format,
1532
+ time: endTimelineMeasure(timeline),
1533
+ groupId: toDevtoolsGroupId("translate", key)
1534
+ });
1445
1535
  msg.locale = targetLocale;
1446
1536
  msg.key = key;
1447
1537
  msg.source = format;
1448
1538
  return msg;
1449
1539
  }
1450
- let measureEvaluateMessage;
1451
- if (inBrowser) {
1452
- const startTag = "intlify-message-evaluation-start";
1453
- const endTag = "intlify-message-evaluation-end";
1454
- measureEvaluateMessage = (context, msg, msgCtx) => {
1455
- const start = window.performance.now();
1456
- mark(startTag);
1457
- const messaged = msg(msgCtx);
1458
- const end = window.performance.now();
1459
- context.__v_emitter?.emit("message-evaluation", {
1460
- type: "message-evaluation",
1461
- value: messaged,
1462
- time: end - start,
1463
- groupId: `translate:${msg.key}`
1464
- });
1465
- mark(endTag);
1466
- measure("intlify message evaluation", startTag, endTag);
1467
- return messaged;
1540
+ function startTimelineMeasure(context, name) {
1541
+ const emitter = context.__v_emitter;
1542
+ if (!inBrowser || !emitter) return null;
1543
+ const start = window.performance.now();
1544
+ mark?.(`intlify-message-${name}-start`);
1545
+ return {
1546
+ emitter,
1547
+ name,
1548
+ start
1468
1549
  };
1469
1550
  }
1551
+ function endTimelineMeasure({ name, start }) {
1552
+ const time = window.performance.now() - start;
1553
+ if (mark && measure) {
1554
+ const startTag = `intlify-message-${name}-start`;
1555
+ const endTag = `intlify-message-${name}-end`;
1556
+ mark(endTag);
1557
+ measure(`intlify message ${name}`, startTag, endTag);
1558
+ }
1559
+ return time;
1560
+ }
1470
1561
  /** @internal */
1471
1562
  function parseTranslateArgs(...args) {
1472
1563
  const [arg1, arg2, arg3] = args;
@@ -1498,12 +1589,11 @@ function getCompileContext(context, locale, key, source, warnHtmlMessage, onErro
1498
1589
  error: err.message,
1499
1590
  start: err.location && err.location.start.offset,
1500
1591
  end: err.location && err.location.end.offset,
1501
- groupId: `translate:${key}`
1592
+ groupId: toDevtoolsGroupId("translate", key)
1502
1593
  });
1503
1594
  const message = `Message compilation error: ${err.message}`;
1504
1595
  throw new SyntaxError(codeFrame ? `${message}\n${codeFrame}` : message);
1505
1596
  }
1506
- throw err;
1507
1597
  },
1508
1598
  onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
1509
1599
  };
@@ -1542,9 +1632,4 @@ function getMessageContextOptions(context, locale, message, options) {
1542
1632
  };
1543
1633
  }
1544
1634
  //#endregion
1545
- //#region packages/core/src/runtime.ts
1546
- registerMessageCompiler(compile);
1547
- registerMessageResolver(resolveValue);
1548
- registerLocaleFallbacker(fallbackWithLocaleChain);
1549
- //#endregion
1550
- export { AST_NODE_PROPS_KEYS, CORE_ERROR_CODES_EXTEND_POINT, CORE_WARN_CODES_EXTEND_POINT, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_RESOLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getFallbackContext, getLocale, getLocaleMessage, getWarnMessage, handleMissing, isAlmostSameLocale, isImplicitFallback, isMessageAST, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue, resolveWithKeyValue, setFallbackContext, setLocaleMessage, translate, updateFallbackLocale };
1635
+ export { AST_NODE_PROPS_KEYS, CORE_ERROR_CODES_EXTEND_POINT, CORE_WARN_CODES_EXTEND_POINT, CoreWarnCodes, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, DEFAULT_MESSAGE_DATA_TYPE, MISSING_RESOLVE_VALUE, NOT_RESOLVED, NUMBER_FORMAT_OPTIONS_KEYS, VERSION, clearCompileCache, clearDateTimeFormat, clearNumberFormat, compile, createCompileError, createCoreContext, createCoreError, createMessageContext, datetime, fallbackWithLocaleChain, fallbackWithSimple, getLocale, getLocaleMessage, getWarnMessage, handleMissing, isAlmostSameLocale, isFallbackLocale, isImplicitFallback, isMessageAST, isMessageFormat, isMessageFunction, isTranslateFallbackWarn, isTranslateMissingWarn, isWarnOption, number, parse, parseDateTimeArgs, parseNumberArgs, parseTranslateArgs, registerLocaleFallbacker, registerMessageCompiler, registerMessageResolver, resolveLocale, resolveValue, resolveWithKeyValue, setLocaleMessage, translate, updateFallbackLocale };