@intlify/core 12.0.0-alpha.4 → 12.0.0-alpha.5
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/core.esm-browser.js +323 -260
- package/dist/core.esm-browser.prod.js +590 -556
- package/dist/core.global.js +323 -261
- package/dist/core.global.prod.js +606 -564
- package/dist/core.js +1 -1
- package/dist/core.node.js +1 -1
- package/dist/core.runtime.esm-browser.js +296 -239
- package/dist/core.runtime.esm-browser.prod.js +451 -417
- package/dist/core.runtime.global.js +296 -240
- package/dist/core.runtime.global.prod.js +452 -416
- package/dist/core.runtime.js +1 -1
- package/dist/core.runtime.node.js +1 -1
- package/package.json +3 -3
package/dist/core.global.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @intlify/core v12.0.0-alpha.
|
|
2
|
+
* @intlify/core v12.0.0-alpha.5
|
|
3
3
|
* (c) 2016-present kazuya kawaguchi and contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
6
6
|
var IntlifyCore = (function(exports) {
|
|
7
7
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
-
//#region packages/shared/src/warn.ts
|
|
9
|
-
function warn(msg, err) {
|
|
10
|
-
if (typeof console !== "undefined") {
|
|
11
|
-
console.warn(`[intlify] ` + msg);
|
|
12
|
-
/* istanbul ignore if */
|
|
13
|
-
if (err) console.warn(err.stack);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const hasWarned = {};
|
|
17
|
-
function warnOnce(msg) {
|
|
18
|
-
if (!hasWarned[msg]) {
|
|
19
|
-
hasWarned[msg] = true;
|
|
20
|
-
warn(msg);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
8
|
//#region packages/shared/src/utils.ts
|
|
25
9
|
/**
|
|
26
10
|
* Original Utilities
|
|
@@ -39,6 +23,7 @@ var IntlifyCore = (function(exports) {
|
|
|
39
23
|
perf.measure(name, startTag, endTag);
|
|
40
24
|
perf.clearMarks(startTag);
|
|
41
25
|
perf.clearMarks(endTag);
|
|
26
|
+
perf.clearMeasures(name);
|
|
42
27
|
};
|
|
43
28
|
}
|
|
44
29
|
}
|
|
@@ -57,75 +42,36 @@ var IntlifyCore = (function(exports) {
|
|
|
57
42
|
});
|
|
58
43
|
const friendlyJSONstringify = (json) => JSON.stringify(json).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/\u0027/g, "\\u0027");
|
|
59
44
|
const isNumber = (val) => typeof val === "number" && isFinite(val);
|
|
45
|
+
function toDevtoolsGroupId(type, key) {
|
|
46
|
+
return isString(key) || isNumber(key) ? `${type}:${key}` : type;
|
|
47
|
+
}
|
|
60
48
|
const isDate = (val) => toTypeString(val) === "[object Date]";
|
|
61
49
|
const isRegExp = (val) => toTypeString(val) === "[object RegExp]";
|
|
62
50
|
const isKeylessObject = (val) => Object.keys(val).length === 0;
|
|
63
51
|
const assign = Object.assign;
|
|
64
52
|
const _create = Object.create;
|
|
65
53
|
const create = (obj = null) => _create(obj);
|
|
66
|
-
function escapeHtml(rawText) {
|
|
67
|
-
return rawText.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/\//g, "/").replace(/=/g, "=");
|
|
68
|
-
}
|
|
69
|
-
function escapeAttributeValue(value) {
|
|
70
|
-
return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
71
|
-
}
|
|
72
|
-
const javascriptSchemePattern = /^\s*javascript\s*(?::|�*58;?|�*3a;?|:?)/i;
|
|
73
|
-
const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
|
|
74
|
-
function hasJavascriptScheme(value) {
|
|
75
|
-
return javascriptSchemePattern.test(value);
|
|
76
|
-
}
|
|
77
|
-
function sanitizeStyleValue(value) {
|
|
78
|
-
const urlPattern = /url\s*\(/gi;
|
|
79
|
-
let sanitized = "";
|
|
80
|
-
let cursor = 0;
|
|
81
|
-
let match;
|
|
82
|
-
while ((match = urlPattern.exec(value)) !== null) {
|
|
83
|
-
const urlStart = match.index;
|
|
84
|
-
const openParenIndex = urlPattern.lastIndex - 1;
|
|
85
|
-
let index = openParenIndex + 1;
|
|
86
|
-
let depth = 1;
|
|
87
|
-
let quote = null;
|
|
88
|
-
for (; index < value.length; index++) {
|
|
89
|
-
const char = value[index];
|
|
90
|
-
if (quote) {
|
|
91
|
-
if (char === quote) quote = null;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (char === "\"" || char === "'") quote = char;
|
|
95
|
-
else if (char === "(") depth++;
|
|
96
|
-
else if (char === ")") {
|
|
97
|
-
depth--;
|
|
98
|
-
if (depth === 0) break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (depth !== 0) break;
|
|
102
|
-
const rawUrlValue = value.slice(openParenIndex + 1, index).trim();
|
|
103
|
-
const unquotedUrlValue = rawUrlValue.startsWith("\"") && rawUrlValue.endsWith("\"") || rawUrlValue.startsWith("'") && rawUrlValue.endsWith("'") ? rawUrlValue.slice(1, -1).trim() : rawUrlValue;
|
|
104
|
-
sanitized += value.slice(cursor, urlStart);
|
|
105
|
-
sanitized += hasJavascriptScheme(unquotedUrlValue) ? "url(about:blank)" : value.slice(urlStart, index + 1);
|
|
106
|
-
cursor = index + 1;
|
|
107
|
-
}
|
|
108
|
-
return sanitized + value.slice(cursor);
|
|
109
|
-
}
|
|
110
|
-
function sanitizeAttributeValue(attrName, value) {
|
|
111
|
-
if (urlAttributePattern.test(attrName) && hasJavascriptScheme(value)) return "about:blank";
|
|
112
|
-
return escapeAttributeValue(attrName.toLowerCase() === "style" ? sanitizeStyleValue(value) : value);
|
|
113
|
-
}
|
|
114
|
-
function sanitizeTranslatedHtml(html) {
|
|
115
|
-
html = html.replace(/([\w:-]+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${sanitizeAttributeValue(attrName, attrValue)}"`);
|
|
116
|
-
html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
|
|
117
|
-
if (/\s*on\w+\s*=\s*["']?[^"'>]+["']?/i.test(html)) {
|
|
118
|
-
warn("Potentially dangerous event handlers detected in translation. Consider removing onclick, onerror, etc. from your translation messages.");
|
|
119
|
-
html = html.replace(/(\s+)on(\w+\s*=)/gi, "$1on$2");
|
|
120
|
-
}
|
|
121
|
-
html = html.replace(/(\s+(?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi, (match, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${prefix}about:blank` : match);
|
|
122
|
-
return html;
|
|
123
|
-
}
|
|
124
54
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
125
55
|
function hasOwn(obj, key) {
|
|
126
56
|
return hasOwnProperty.call(obj, key);
|
|
127
57
|
}
|
|
128
58
|
/**
|
|
59
|
+
* Get `obj[key]` only when `key` is an own property of `obj`, so that a key such as `constructor`
|
|
60
|
+
* does not read a property inherited from `Object.prototype`.
|
|
61
|
+
* The property is read before the check, so that a reactive `obj` tracks `key` even when it is missing.
|
|
62
|
+
*/
|
|
63
|
+
function getOwn(obj, key) {
|
|
64
|
+
const value = obj[key];
|
|
65
|
+
return hasOwn(obj, key) ? value : void 0;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether `key` is a property name of `Object.prototype`, such as `__proto__`, `constructor` or `toString`.
|
|
69
|
+
* On a plain object, such a key reads a built-in, and assigning to `__proto__` replaces the prototype.
|
|
70
|
+
*/
|
|
71
|
+
function isObjectPrototypeKey(key) {
|
|
72
|
+
return hasOwn(Object.prototype, key);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
129
75
|
* Useful Utilities By Evan you
|
|
130
76
|
* Modified by kazuya kawaguchi
|
|
131
77
|
* MIT License
|
|
@@ -180,25 +126,130 @@ var IntlifyCore = (function(exports) {
|
|
|
180
126
|
return res.join("\n");
|
|
181
127
|
}
|
|
182
128
|
//#endregion
|
|
129
|
+
//#region packages/shared/src/warn.ts
|
|
130
|
+
function warn(msg, err) {
|
|
131
|
+
if (typeof console !== "undefined") {
|
|
132
|
+
console.warn(`[intlify] ` + msg);
|
|
133
|
+
/* istanbul ignore if */
|
|
134
|
+
if (err) console.warn(err.stack);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const hasWarned = {};
|
|
138
|
+
function warnOnce(msg) {
|
|
139
|
+
if (!hasWarned[msg]) {
|
|
140
|
+
hasWarned[msg] = true;
|
|
141
|
+
warn(msg);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region packages/shared/src/sanitize.ts
|
|
146
|
+
function escapeHtml(rawText) {
|
|
147
|
+
return rawText.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'").replace(/\//g, "/").replace(/=/g, "=");
|
|
148
|
+
}
|
|
149
|
+
function escapeAttributeValue(value) {
|
|
150
|
+
return value.replace(/&(?![a-z0-9#]{2,6};)/gi, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
151
|
+
}
|
|
152
|
+
const javascriptSchemePattern = /^javascript:/i;
|
|
153
|
+
const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
|
|
154
|
+
const numericCharacterReferencePattern = /&#(?:x([0-9a-f]+)|(\d+));?/gi;
|
|
155
|
+
const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
|
|
156
|
+
const colonCharacterReferencePattern = /:?/gi;
|
|
157
|
+
const controlOrWhitespacePattern = /[\u0000-\u0020\u007f-\u009f]/g;
|
|
158
|
+
const eventHandlerPattern = /(?:^|[\s"'<>/])on\w+\s*=\s*["']?[^"'>]+["']?/i;
|
|
159
|
+
const eventHandlerAttributePattern = /(^|[\s"'<>/])on(\w+\s*=)/gi;
|
|
160
|
+
const srcdocPattern = /(?:^|[\s"'<>/])srcdoc\s*=/i;
|
|
161
|
+
const srcdocAttributePattern = /(^|[\s"'<>/])s(rcdoc\s*=)/gi;
|
|
162
|
+
const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
|
|
163
|
+
function decodeNumericCharacterReference(match, hex, decimal) {
|
|
164
|
+
const digits = hex || decimal;
|
|
165
|
+
if (!digits) return match;
|
|
166
|
+
const codePoint = Number.parseInt(digits, hex ? 16 : 10);
|
|
167
|
+
return codePoint <= 127 ? String.fromCharCode(codePoint) : match;
|
|
168
|
+
}
|
|
169
|
+
function hasJavascriptScheme(value) {
|
|
170
|
+
const normalized = value.replace(numericCharacterReferencePattern, decodeNumericCharacterReference).replace(namedWhitespaceCharacterReferencePattern, "").replace(colonCharacterReferencePattern, ":").replace(controlOrWhitespacePattern, "");
|
|
171
|
+
return javascriptSchemePattern.test(normalized);
|
|
172
|
+
}
|
|
173
|
+
function sanitizeStyleValue(value) {
|
|
174
|
+
const urlPattern = /url\s*\(/gi;
|
|
175
|
+
let sanitized = "";
|
|
176
|
+
let cursor = 0;
|
|
177
|
+
let match;
|
|
178
|
+
while ((match = urlPattern.exec(value)) !== null) {
|
|
179
|
+
const urlStart = match.index;
|
|
180
|
+
const openParenIndex = urlPattern.lastIndex - 1;
|
|
181
|
+
let index = openParenIndex + 1;
|
|
182
|
+
let depth = 1;
|
|
183
|
+
let quote = null;
|
|
184
|
+
for (; index < value.length; index++) {
|
|
185
|
+
const char = value[index];
|
|
186
|
+
if (quote) {
|
|
187
|
+
if (char === quote) quote = null;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (char === "\"" || char === "'") quote = char;
|
|
191
|
+
else if (char === "(") depth++;
|
|
192
|
+
else if (char === ")") {
|
|
193
|
+
depth--;
|
|
194
|
+
if (depth === 0) break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (depth !== 0) break;
|
|
198
|
+
const rawUrlValue = value.slice(openParenIndex + 1, index).trim();
|
|
199
|
+
const unquotedUrlValue = rawUrlValue.startsWith("\"") && rawUrlValue.endsWith("\"") || rawUrlValue.startsWith("'") && rawUrlValue.endsWith("'") ? rawUrlValue.slice(1, -1).trim() : rawUrlValue;
|
|
200
|
+
sanitized += value.slice(cursor, urlStart);
|
|
201
|
+
sanitized += hasJavascriptScheme(unquotedUrlValue) ? "url(about:blank)" : value.slice(urlStart, index + 1);
|
|
202
|
+
cursor = index + 1;
|
|
203
|
+
}
|
|
204
|
+
return sanitized + value.slice(cursor);
|
|
205
|
+
}
|
|
206
|
+
function sanitizeAttributeValue(attrName, value) {
|
|
207
|
+
if (urlAttributePattern.test(attrName) && hasJavascriptScheme(value)) return "about:blank";
|
|
208
|
+
return escapeAttributeValue(attrName.toLowerCase() === "style" ? sanitizeStyleValue(value) : value);
|
|
209
|
+
}
|
|
210
|
+
function sanitizeTranslatedHtml(html) {
|
|
211
|
+
html = html.replace(/([\w:-]+)\s*=\s*"([^"]*)"/g, (_, attrName, attrValue) => `${attrName}="${sanitizeAttributeValue(attrName, attrValue)}"`);
|
|
212
|
+
html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
|
|
213
|
+
if (eventHandlerPattern.test(html)) {
|
|
214
|
+
warn("Potentially dangerous event handlers detected in translation. Consider removing onclick, onerror, etc. from your translation messages.");
|
|
215
|
+
html = html.replace(eventHandlerAttributePattern, "$1on$2");
|
|
216
|
+
}
|
|
217
|
+
if (srcdocPattern.test(html)) {
|
|
218
|
+
warn("Potentially dangerous srcdoc attribute detected in translation. Consider removing srcdoc from your translation messages.");
|
|
219
|
+
html = html.replace(srcdocAttributePattern, "$1s$2");
|
|
220
|
+
}
|
|
221
|
+
html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
|
|
222
|
+
return html;
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
183
225
|
//#region packages/shared/src/messages.ts
|
|
184
226
|
const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
|
|
185
227
|
function deepCopy(src, des) {
|
|
186
|
-
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) throw new Error("Invalid value");
|
|
187
|
-
const stack = [
|
|
188
|
-
src,
|
|
189
|
-
des
|
|
190
|
-
}];
|
|
228
|
+
if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des) || des === Object.prototype) throw new Error("Invalid value");
|
|
229
|
+
const stack = [src, des];
|
|
191
230
|
while (stack.length) {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
231
|
+
const des = stack.pop();
|
|
232
|
+
const src = stack.pop();
|
|
233
|
+
const keys = Object.keys(src);
|
|
234
|
+
for (let i = 0; i < keys.length; i++) {
|
|
235
|
+
const key = keys[i];
|
|
236
|
+
if (key === "__proto__") continue;
|
|
237
|
+
const value = src[key];
|
|
238
|
+
if (!isObject(value)) {
|
|
239
|
+
des[key] = value;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (isArray(value)) {
|
|
243
|
+
const copied = [];
|
|
244
|
+
copied.length = value.length;
|
|
245
|
+
des[key] = copied;
|
|
246
|
+
stack.push(value, copied);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
let desValue = des[key];
|
|
250
|
+
if (!isObject(desValue) || isArray(desValue)) desValue = des[key] = create();
|
|
251
|
+
stack.push(value, desValue);
|
|
252
|
+
}
|
|
202
253
|
}
|
|
203
254
|
}
|
|
204
255
|
//#endregion
|
|
@@ -476,10 +527,13 @@ var IntlifyCore = (function(exports) {
|
|
|
476
527
|
const ctx = context();
|
|
477
528
|
pos.column += offset;
|
|
478
529
|
pos.offset += offset;
|
|
479
|
-
if (onError)
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
530
|
+
if (onError) {
|
|
531
|
+
const err = createCompileError(code, location ? createLocation(ctx.startLoc, pos) : null, {
|
|
532
|
+
domain: ERROR_DOMAIN$1,
|
|
533
|
+
args
|
|
534
|
+
});
|
|
535
|
+
onError(err);
|
|
536
|
+
}
|
|
483
537
|
}
|
|
484
538
|
function getToken(context, type, value) {
|
|
485
539
|
context.endLoc = currentPosition();
|
|
@@ -612,7 +666,7 @@ var IntlifyCore = (function(exports) {
|
|
|
612
666
|
}
|
|
613
667
|
function takeChar(scnr, fn) {
|
|
614
668
|
const ch = scnr.currentChar();
|
|
615
|
-
if (ch === EOF) return
|
|
669
|
+
if (ch === EOF) return;
|
|
616
670
|
if (fn(ch)) {
|
|
617
671
|
scnr.next();
|
|
618
672
|
return ch;
|
|
@@ -669,15 +723,16 @@ var IntlifyCore = (function(exports) {
|
|
|
669
723
|
scnr.next();
|
|
670
724
|
}
|
|
671
725
|
} else if (ch === "{" || ch === "}" || ch === "@" || ch === "|" || !ch) break;
|
|
672
|
-
else if (ch === " " || ch === "\n")
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
726
|
+
else if (ch === " " || ch === "\n") {
|
|
727
|
+
if (isTextStart(scnr)) {
|
|
728
|
+
buf += ch;
|
|
729
|
+
scnr.next();
|
|
730
|
+
} else if (isPluralStart(scnr)) break;
|
|
731
|
+
else {
|
|
732
|
+
buf += ch;
|
|
733
|
+
scnr.next();
|
|
734
|
+
}
|
|
735
|
+
} else {
|
|
681
736
|
buf += ch;
|
|
682
737
|
scnr.next();
|
|
683
738
|
}
|
|
@@ -925,7 +980,6 @@ var IntlifyCore = (function(exports) {
|
|
|
925
980
|
return token;
|
|
926
981
|
}
|
|
927
982
|
if (isTextStart(scnr)) return getToken(context, 0, readText(scnr));
|
|
928
|
-
break;
|
|
929
983
|
}
|
|
930
984
|
return token;
|
|
931
985
|
}
|
|
@@ -973,10 +1027,13 @@ var IntlifyCore = (function(exports) {
|
|
|
973
1027
|
const end = tokenzer.currentPosition();
|
|
974
1028
|
end.offset += offset;
|
|
975
1029
|
end.column += offset;
|
|
976
|
-
if (onError)
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1030
|
+
if (onError) {
|
|
1031
|
+
const err = createCompileError(code, location ? createLocation(start, end) : null, {
|
|
1032
|
+
domain: ERROR_DOMAIN,
|
|
1033
|
+
args
|
|
1034
|
+
});
|
|
1035
|
+
onError(err);
|
|
1036
|
+
}
|
|
980
1037
|
}
|
|
981
1038
|
function startNode(type, offset, loc) {
|
|
982
1039
|
const node = { type };
|
|
@@ -1313,7 +1370,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1313
1370
|
code: ""
|
|
1314
1371
|
};
|
|
1315
1372
|
}
|
|
1316
|
-
/*
|
|
1373
|
+
/* #__NO_SIDE_EFFECTS__ */
|
|
1317
1374
|
function compile(message, context) {
|
|
1318
1375
|
if (isString(message)) {
|
|
1319
1376
|
checkHtmlMessage(message, isBoolean(context.warnHtmlMessage) ? context.warnHtmlMessage : true);
|
|
@@ -1347,12 +1404,11 @@ var IntlifyCore = (function(exports) {
|
|
|
1347
1404
|
INVALID_ARGUMENT: 17,
|
|
1348
1405
|
INVALID_DATE_ARGUMENT: 18,
|
|
1349
1406
|
INVALID_ISO_DATE_ARGUMENT: 19,
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
NOT_SUPPORT_LOCALE_TYPE: 23
|
|
1407
|
+
NOT_SUPPORT_LOCALE_PROMISE_VALUE: 20,
|
|
1408
|
+
NOT_SUPPORT_LOCALE_ASYNC_FUNCTION: 21,
|
|
1409
|
+
NOT_SUPPORT_LOCALE_TYPE: 22
|
|
1354
1410
|
};
|
|
1355
|
-
const CORE_ERROR_CODES_EXTEND_POINT =
|
|
1411
|
+
const CORE_ERROR_CODES_EXTEND_POINT = 23;
|
|
1356
1412
|
function createCoreError(code) {
|
|
1357
1413
|
return createCompileError(code, null, { messages: errorMessages });
|
|
1358
1414
|
}
|
|
@@ -1361,7 +1417,6 @@ var IntlifyCore = (function(exports) {
|
|
|
1361
1417
|
[CoreErrorCodes.INVALID_ARGUMENT]: "Invalid arguments",
|
|
1362
1418
|
[CoreErrorCodes.INVALID_DATE_ARGUMENT]: "The date provided is an invalid Date object.Make sure your Date represents a valid date.",
|
|
1363
1419
|
[CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: "The argument provided is not a valid ISO date string",
|
|
1364
|
-
[CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE]: "Not support non-string message",
|
|
1365
1420
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE]: "cannot support promise value",
|
|
1366
1421
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: "cannot support async function",
|
|
1367
1422
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: "cannot support locale type"
|
|
@@ -1376,13 +1431,14 @@ var IntlifyCore = (function(exports) {
|
|
|
1376
1431
|
/** @internal */
|
|
1377
1432
|
function resolveLocale(locale) {
|
|
1378
1433
|
if (isString(locale)) return locale;
|
|
1379
|
-
else if (isFunction(locale))
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1434
|
+
else if (isFunction(locale)) {
|
|
1435
|
+
if (locale.resolvedOnce && _resolveLocale != null) return _resolveLocale;
|
|
1436
|
+
else if (locale.constructor.name === "Function") {
|
|
1437
|
+
const resolve = locale();
|
|
1438
|
+
if (isPromise(resolve)) throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE);
|
|
1439
|
+
return _resolveLocale = resolve;
|
|
1440
|
+
} else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION);
|
|
1441
|
+
} else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE);
|
|
1386
1442
|
}
|
|
1387
1443
|
/**
|
|
1388
1444
|
* Fallback with simple implemenation
|
|
@@ -1390,7 +1446,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1390
1446
|
* @remarks
|
|
1391
1447
|
* A fallback locale function implemented with a simple fallback algorithm.
|
|
1392
1448
|
*
|
|
1393
|
-
* Basically,
|
|
1449
|
+
* 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.
|
|
1394
1450
|
*
|
|
1395
1451
|
* @param ctx - A {@link CoreContext | context}
|
|
1396
1452
|
* @param fallback - A {@link FallbackLocale | fallback locale}
|
|
@@ -1401,7 +1457,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1401
1457
|
* @VueI18nGeneral
|
|
1402
1458
|
*/
|
|
1403
1459
|
function fallbackWithSimple(_ctx, fallback, start) {
|
|
1404
|
-
return [
|
|
1460
|
+
return [.../* @__PURE__ */ new Set([start, ...isArray(fallback) ? fallback : isObject(fallback) ? Object.keys(fallback).filter((locale) => locale !== "default") : isString(fallback) ? [fallback] : [start]])];
|
|
1405
1461
|
}
|
|
1406
1462
|
/**
|
|
1407
1463
|
* Fallback with locale chain
|
|
@@ -1409,6 +1465,9 @@ var IntlifyCore = (function(exports) {
|
|
|
1409
1465
|
* @remarks
|
|
1410
1466
|
* A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
|
|
1411
1467
|
*
|
|
1468
|
+
* Chains are cached per fallback identity. If you mutate an object or array fallback in place,
|
|
1469
|
+
* pass a new object or array instead so that the chain is recomputed.
|
|
1470
|
+
*
|
|
1412
1471
|
* @param ctx - A {@link CoreContext | context}
|
|
1413
1472
|
* @param fallback - A {@link FallbackLocale | fallback locale}
|
|
1414
1473
|
* @param start - A starting {@link Locale | locale}
|
|
@@ -1422,17 +1481,31 @@ var IntlifyCore = (function(exports) {
|
|
|
1422
1481
|
function fallbackWithLocaleChain(ctx, fallback, start) {
|
|
1423
1482
|
const startLocale = isString(start) ? start : DEFAULT_LOCALE;
|
|
1424
1483
|
const context = ctx;
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
context.__localeChainCache.
|
|
1484
|
+
let chains;
|
|
1485
|
+
if (isObject(fallback)) {
|
|
1486
|
+
if (!context.__localeChainObjectCache) context.__localeChainObjectCache = /* @__PURE__ */ new WeakMap();
|
|
1487
|
+
chains = context.__localeChainObjectCache.get(fallback);
|
|
1488
|
+
if (!chains) {
|
|
1489
|
+
chains = /* @__PURE__ */ new Map();
|
|
1490
|
+
context.__localeChainObjectCache.set(fallback, chains);
|
|
1491
|
+
}
|
|
1492
|
+
} else {
|
|
1493
|
+
if (!context.__localeChainCache) context.__localeChainCache = /* @__PURE__ */ new Map();
|
|
1494
|
+
chains = context.__localeChainCache.get(fallback);
|
|
1495
|
+
if (!chains) {
|
|
1496
|
+
chains = /* @__PURE__ */ new Map();
|
|
1497
|
+
context.__localeChainCache.set(fallback, chains);
|
|
1498
|
+
}
|
|
1435
1499
|
}
|
|
1500
|
+
const cached = chains.get(startLocale);
|
|
1501
|
+
if (cached) return cached;
|
|
1502
|
+
const chain = [];
|
|
1503
|
+
let block = [start];
|
|
1504
|
+
while (isArray(block)) block = appendBlockToChain(chain, block, fallback);
|
|
1505
|
+
const defaults = isArray(fallback) || !isPlainObject(fallback) ? fallback : fallback["default"] ? fallback["default"] : null;
|
|
1506
|
+
block = isString(defaults) ? [defaults] : defaults;
|
|
1507
|
+
if (isArray(block)) appendBlockToChain(chain, block, false);
|
|
1508
|
+
chains.set(startLocale, chain);
|
|
1436
1509
|
return chain;
|
|
1437
1510
|
}
|
|
1438
1511
|
function appendBlockToChain(chain, block, blocks) {
|
|
@@ -1724,7 +1797,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1724
1797
|
* Intlify core-base version
|
|
1725
1798
|
* @internal
|
|
1726
1799
|
*/
|
|
1727
|
-
const VERSION = "12.0.0-alpha.
|
|
1800
|
+
const VERSION = "12.0.0-alpha.5";
|
|
1728
1801
|
const NOT_RESOLVED = -1;
|
|
1729
1802
|
const DEFAULT_LOCALE = "en-US";
|
|
1730
1803
|
const MISSING_RESOLVE_VALUE = "";
|
|
@@ -1784,11 +1857,6 @@ var IntlifyCore = (function(exports) {
|
|
|
1784
1857
|
warnOnce(`registerLocaleFallbacker is deprecated. Use 'localeFallbacker' option of 'createI18n' or 'createCoreContext' instead.`);
|
|
1785
1858
|
_fallbacker = fallbacker;
|
|
1786
1859
|
}
|
|
1787
|
-
let _fallbackContext = null;
|
|
1788
|
-
const setFallbackContext = (context) => {
|
|
1789
|
-
_fallbackContext = context;
|
|
1790
|
-
};
|
|
1791
|
-
const getFallbackContext = () => _fallbackContext;
|
|
1792
1860
|
let _cid = 0;
|
|
1793
1861
|
function createCoreContext(options = {}) {
|
|
1794
1862
|
const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
|
|
@@ -1853,7 +1921,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1853
1921
|
* @version 12.0.0
|
|
1854
1922
|
*/
|
|
1855
1923
|
function getLocaleMessage(ctx, locale) {
|
|
1856
|
-
const src = ctx.messages
|
|
1924
|
+
const src = getOwn(ctx.messages, locale);
|
|
1857
1925
|
if (src == null) return;
|
|
1858
1926
|
const dest = create();
|
|
1859
1927
|
deepCopy(src, dest);
|
|
@@ -1863,6 +1931,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1863
1931
|
* @version 12.0.0
|
|
1864
1932
|
*/
|
|
1865
1933
|
function setLocaleMessage(ctx, locale, messages) {
|
|
1934
|
+
if (isObjectPrototypeKey(locale)) return;
|
|
1866
1935
|
ctx.messages[locale] = messages;
|
|
1867
1936
|
}
|
|
1868
1937
|
/** @internal */
|
|
@@ -1882,7 +1951,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1882
1951
|
locale,
|
|
1883
1952
|
key,
|
|
1884
1953
|
type,
|
|
1885
|
-
groupId:
|
|
1954
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
1886
1955
|
});
|
|
1887
1956
|
}
|
|
1888
1957
|
if (missing !== null) {
|
|
@@ -1896,10 +1965,15 @@ var IntlifyCore = (function(exports) {
|
|
|
1896
1965
|
return key;
|
|
1897
1966
|
}
|
|
1898
1967
|
}
|
|
1968
|
+
function invalidateLocaleChainCache(ctx, fallback) {
|
|
1969
|
+
const context = ctx;
|
|
1970
|
+
if (isObject(fallback)) context.__localeChainObjectCache?.delete(fallback);
|
|
1971
|
+
else context.__localeChainCache?.delete(fallback);
|
|
1972
|
+
}
|
|
1899
1973
|
/** @internal */
|
|
1900
1974
|
function updateFallbackLocale(ctx, locale, fallback) {
|
|
1901
|
-
|
|
1902
|
-
|
|
1975
|
+
invalidateLocaleChainCache(ctx, fallback);
|
|
1976
|
+
if (ctx.fallbackContext) invalidateLocaleChainCache(ctx.fallbackContext, fallback);
|
|
1903
1977
|
ctx.localeFallbacker(ctx, fallback, locale);
|
|
1904
1978
|
}
|
|
1905
1979
|
/** @internal */
|
|
@@ -1915,6 +1989,59 @@ var IntlifyCore = (function(exports) {
|
|
|
1915
1989
|
return false;
|
|
1916
1990
|
}
|
|
1917
1991
|
//#endregion
|
|
1992
|
+
//#region packages/core-base/src/formatter.ts
|
|
1993
|
+
function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
|
|
1994
|
+
const { fallbackLocale, localeFallbacker, onWarn } = context;
|
|
1995
|
+
const locales = localeFallbacker(context, fallbackLocale, locale);
|
|
1996
|
+
let from = locale;
|
|
1997
|
+
for (let i = 0; i < locales.length; i++) {
|
|
1998
|
+
const targetLocale = locales[i];
|
|
1999
|
+
if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(type === "datetime format" ? CoreWarnCodes.FALLBACK_TO_DATE_FORMAT : CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
|
|
2000
|
+
key,
|
|
2001
|
+
target: targetLocale
|
|
2002
|
+
}));
|
|
2003
|
+
if (locale !== targetLocale) {
|
|
2004
|
+
const emitter = context.__v_emitter;
|
|
2005
|
+
if (emitter) emitter.emit("fallback", {
|
|
2006
|
+
type,
|
|
2007
|
+
key,
|
|
2008
|
+
from,
|
|
2009
|
+
to: targetLocale,
|
|
2010
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
const format = (formats[targetLocale] || {})[key];
|
|
2014
|
+
if (isPlainObject(format) && isString(targetLocale)) return targetLocale;
|
|
2015
|
+
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
2016
|
+
from = targetLocale;
|
|
2017
|
+
}
|
|
2018
|
+
return null;
|
|
2019
|
+
}
|
|
2020
|
+
function getFormatterCacheKey(locale, key, overrides) {
|
|
2021
|
+
let id = `${locale}__${key}`;
|
|
2022
|
+
if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
|
|
2023
|
+
return id;
|
|
2024
|
+
}
|
|
2025
|
+
function clearFormatCache(formatters, locale, format) {
|
|
2026
|
+
for (const key in format) {
|
|
2027
|
+
const prefix = `${locale}__${key}`;
|
|
2028
|
+
for (const id of formatters.keys()) if (id === prefix || id.startsWith(`${prefix}__`)) formatters.delete(id);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
function parseFormatArgs(args, options, initialOverrides, optionsKeys) {
|
|
2032
|
+
const [, arg2, arg3, arg4] = args;
|
|
2033
|
+
let overrides = initialOverrides;
|
|
2034
|
+
if (isString(arg2)) options.key = arg2;
|
|
2035
|
+
else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
|
|
2036
|
+
if (optionsKeys.includes(key)) overrides[key] = arg2[key];
|
|
2037
|
+
else options[key] = arg2[key];
|
|
2038
|
+
});
|
|
2039
|
+
if (isString(arg3)) options.locale = arg3;
|
|
2040
|
+
else if (isPlainObject(arg3)) overrides = arg3;
|
|
2041
|
+
if (isPlainObject(arg4)) overrides = arg4;
|
|
2042
|
+
return overrides;
|
|
2043
|
+
}
|
|
2044
|
+
//#endregion
|
|
1918
2045
|
//#region packages/core-base/src/intl.ts
|
|
1919
2046
|
const intlDefined = typeof Intl !== "undefined";
|
|
1920
2047
|
const Availabilities = {
|
|
@@ -1924,7 +2051,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1924
2051
|
//#endregion
|
|
1925
2052
|
//#region packages/core-base/src/datetime.ts
|
|
1926
2053
|
function datetime(context, ...args) {
|
|
1927
|
-
const { datetimeFormats, unresolving,
|
|
2054
|
+
const { datetimeFormats, unresolving, onWarn } = context;
|
|
1928
2055
|
const { __datetimeFormatters } = context;
|
|
1929
2056
|
if (!Availabilities.dateTimeFormat) {
|
|
1930
2057
|
onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
|
|
@@ -1939,39 +2066,14 @@ var IntlifyCore = (function(exports) {
|
|
|
1939
2066
|
const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
|
|
1940
2067
|
const part = !!options.part;
|
|
1941
2068
|
const locale = getLocale(context, options);
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
const
|
|
1950
|
-
for (let i = 0; i < locales.length; i++) {
|
|
1951
|
-
targetLocale = to = locales[i];
|
|
1952
|
-
if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
|
|
1953
|
-
key,
|
|
1954
|
-
target: targetLocale
|
|
1955
|
-
}));
|
|
1956
|
-
if (locale !== targetLocale) {
|
|
1957
|
-
const emitter = context.__v_emitter;
|
|
1958
|
-
if (emitter) emitter.emit("fallback", {
|
|
1959
|
-
type,
|
|
1960
|
-
key,
|
|
1961
|
-
from,
|
|
1962
|
-
to,
|
|
1963
|
-
groupId: `${type}:${key}`
|
|
1964
|
-
});
|
|
1965
|
-
}
|
|
1966
|
-
datetimeFormat = datetimeFormats[targetLocale] || {};
|
|
1967
|
-
format = datetimeFormat[key];
|
|
1968
|
-
if (isPlainObject(format)) break;
|
|
1969
|
-
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
1970
|
-
from = to;
|
|
1971
|
-
}
|
|
1972
|
-
if (!isPlainObject(format) || !isString(targetLocale)) return unresolving ? -1 : key;
|
|
1973
|
-
let id = `${targetLocale}__${key}`;
|
|
1974
|
-
if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
|
|
2069
|
+
if (!isString(key) || key === "") {
|
|
2070
|
+
const formatter = new Intl.DateTimeFormat(locale.replace(/!/g, ""), overrides);
|
|
2071
|
+
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
2072
|
+
}
|
|
2073
|
+
const targetLocale = resolveFormatLocale(context, key, locale, datetimeFormats, missingWarn, fallbackWarn, "datetime format");
|
|
2074
|
+
if (!isString(targetLocale)) return unresolving ? -1 : key;
|
|
2075
|
+
const format = datetimeFormats[targetLocale][key];
|
|
2076
|
+
const id = getFormatterCacheKey(targetLocale, key, overrides);
|
|
1975
2077
|
let formatter = __datetimeFormatters.get(id);
|
|
1976
2078
|
if (!formatter) {
|
|
1977
2079
|
formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
|
|
@@ -2004,12 +2106,12 @@ var IntlifyCore = (function(exports) {
|
|
|
2004
2106
|
];
|
|
2005
2107
|
/** @internal */
|
|
2006
2108
|
function parseDateTimeArgs(...args) {
|
|
2007
|
-
const [arg1
|
|
2109
|
+
const [arg1] = args;
|
|
2008
2110
|
const options = create();
|
|
2009
|
-
|
|
2111
|
+
const initialOverrides = create();
|
|
2010
2112
|
let value;
|
|
2011
2113
|
if (isString(arg1)) {
|
|
2012
|
-
const matches = arg1.match(
|
|
2114
|
+
const matches = arg1.match(/^(\d{4}-\d{2}-\d{2})(?:(T|\s)(.+))?$/);
|
|
2013
2115
|
if (!matches) throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
|
|
2014
2116
|
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();
|
|
2015
2117
|
value = new Date(dateTime);
|
|
@@ -2023,14 +2125,7 @@ var IntlifyCore = (function(exports) {
|
|
|
2023
2125
|
value = arg1;
|
|
2024
2126
|
} else if (isNumber(arg1)) value = arg1;
|
|
2025
2127
|
else throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
2026
|
-
|
|
2027
|
-
else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
|
|
2028
|
-
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) overrides[key] = arg2[key];
|
|
2029
|
-
else options[key] = arg2[key];
|
|
2030
|
-
});
|
|
2031
|
-
if (isString(arg3)) options.locale = arg3;
|
|
2032
|
-
else if (isPlainObject(arg3)) overrides = arg3;
|
|
2033
|
-
if (isPlainObject(arg4)) overrides = arg4;
|
|
2128
|
+
const overrides = parseFormatArgs(args, options, initialOverrides, DATETIME_FORMAT_OPTIONS_KEYS);
|
|
2034
2129
|
return [
|
|
2035
2130
|
options.key || "",
|
|
2036
2131
|
value,
|
|
@@ -2040,17 +2135,12 @@ var IntlifyCore = (function(exports) {
|
|
|
2040
2135
|
}
|
|
2041
2136
|
/** @internal */
|
|
2042
2137
|
function clearDateTimeFormat(ctx, locale, format) {
|
|
2043
|
-
|
|
2044
|
-
for (const key in format) {
|
|
2045
|
-
const id = `${locale}__${key}`;
|
|
2046
|
-
if (!context.__datetimeFormatters.has(id)) continue;
|
|
2047
|
-
context.__datetimeFormatters.delete(id);
|
|
2048
|
-
}
|
|
2138
|
+
clearFormatCache(ctx.__datetimeFormatters, locale, format);
|
|
2049
2139
|
}
|
|
2050
2140
|
//#endregion
|
|
2051
2141
|
//#region packages/core-base/src/number.ts
|
|
2052
2142
|
function number(context, ...args) {
|
|
2053
|
-
const { numberFormats, unresolving,
|
|
2143
|
+
const { numberFormats, unresolving, onWarn } = context;
|
|
2054
2144
|
const { __numberFormatters } = context;
|
|
2055
2145
|
if (!Availabilities.numberFormat) {
|
|
2056
2146
|
onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
|
|
@@ -2065,39 +2155,14 @@ var IntlifyCore = (function(exports) {
|
|
|
2065
2155
|
const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
|
|
2066
2156
|
const part = !!options.part;
|
|
2067
2157
|
const locale = getLocale(context, options);
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
const
|
|
2076
|
-
for (let i = 0; i < locales.length; i++) {
|
|
2077
|
-
targetLocale = to = locales[i];
|
|
2078
|
-
if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
|
|
2079
|
-
key,
|
|
2080
|
-
target: targetLocale
|
|
2081
|
-
}));
|
|
2082
|
-
if (locale !== targetLocale) {
|
|
2083
|
-
const emitter = context.__v_emitter;
|
|
2084
|
-
if (emitter) emitter.emit("fallback", {
|
|
2085
|
-
type,
|
|
2086
|
-
key,
|
|
2087
|
-
from,
|
|
2088
|
-
to,
|
|
2089
|
-
groupId: `${type}:${key}`
|
|
2090
|
-
});
|
|
2091
|
-
}
|
|
2092
|
-
numberFormat = numberFormats[targetLocale] || {};
|
|
2093
|
-
format = numberFormat[key];
|
|
2094
|
-
if (isPlainObject(format)) break;
|
|
2095
|
-
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
2096
|
-
from = to;
|
|
2097
|
-
}
|
|
2098
|
-
if (!isPlainObject(format) || !isString(targetLocale)) return unresolving ? -1 : key;
|
|
2099
|
-
let id = `${targetLocale}__${key}`;
|
|
2100
|
-
if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
|
|
2158
|
+
if (!isString(key) || key === "") {
|
|
2159
|
+
const formatter = new Intl.NumberFormat(locale.replace(/!/g, ""), overrides);
|
|
2160
|
+
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
2161
|
+
}
|
|
2162
|
+
const targetLocale = resolveFormatLocale(context, key, locale, numberFormats, missingWarn, fallbackWarn, "number format");
|
|
2163
|
+
if (!isString(targetLocale)) return unresolving ? -1 : key;
|
|
2164
|
+
const format = numberFormats[targetLocale][key];
|
|
2165
|
+
const id = getFormatterCacheKey(targetLocale, key, overrides);
|
|
2101
2166
|
let formatter = __numberFormatters.get(id);
|
|
2102
2167
|
if (!formatter) {
|
|
2103
2168
|
formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
|
|
@@ -2130,19 +2195,12 @@ var IntlifyCore = (function(exports) {
|
|
|
2130
2195
|
];
|
|
2131
2196
|
/** @internal */
|
|
2132
2197
|
function parseNumberArgs(...args) {
|
|
2133
|
-
const [arg1
|
|
2198
|
+
const [arg1] = args;
|
|
2134
2199
|
const options = create();
|
|
2135
|
-
|
|
2200
|
+
const initialOverrides = create();
|
|
2136
2201
|
if (!isNumber(arg1)) throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
2137
2202
|
const value = arg1;
|
|
2138
|
-
|
|
2139
|
-
else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
|
|
2140
|
-
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) overrides[key] = arg2[key];
|
|
2141
|
-
else options[key] = arg2[key];
|
|
2142
|
-
});
|
|
2143
|
-
if (isString(arg3)) options.locale = arg3;
|
|
2144
|
-
else if (isPlainObject(arg3)) overrides = arg3;
|
|
2145
|
-
if (isPlainObject(arg4)) overrides = arg4;
|
|
2203
|
+
const overrides = parseFormatArgs(args, options, initialOverrides, NUMBER_FORMAT_OPTIONS_KEYS);
|
|
2146
2204
|
return [
|
|
2147
2205
|
options.key || "",
|
|
2148
2206
|
value,
|
|
@@ -2152,12 +2210,7 @@ var IntlifyCore = (function(exports) {
|
|
|
2152
2210
|
}
|
|
2153
2211
|
/** @internal */
|
|
2154
2212
|
function clearNumberFormat(ctx, locale, format) {
|
|
2155
|
-
|
|
2156
|
-
for (const key in format) {
|
|
2157
|
-
const id = `${locale}__${key}`;
|
|
2158
|
-
if (!context.__numberFormatters.has(id)) continue;
|
|
2159
|
-
context.__numberFormatters.delete(id);
|
|
2160
|
-
}
|
|
2213
|
+
clearFormatCache(ctx.__numberFormatters, locale, format);
|
|
2161
2214
|
}
|
|
2162
2215
|
//#endregion
|
|
2163
2216
|
//#region packages/core-base/src/runtime.ts
|
|
@@ -2262,6 +2315,8 @@ var IntlifyCore = (function(exports) {
|
|
|
2262
2315
|
//#region packages/core-base/src/translate.ts
|
|
2263
2316
|
const NOOP_MESSAGE_FUNCTION = () => "";
|
|
2264
2317
|
const isMessageFunction = (val) => isFunction(val);
|
|
2318
|
+
/** @internal */
|
|
2319
|
+
const isMessageFormat = (val) => isString(val) || isMessageAST(val) || isMessageFunction(val);
|
|
2265
2320
|
function translate(context, ...args) {
|
|
2266
2321
|
const [key, options] = parseTranslateArgs(...args);
|
|
2267
2322
|
const locale = getLocale(context, options);
|
|
@@ -2274,16 +2329,16 @@ var IntlifyCore = (function(exports) {
|
|
|
2274
2329
|
context.messages[locale] || create()
|
|
2275
2330
|
];
|
|
2276
2331
|
let cacheBaseKey = key;
|
|
2277
|
-
if (!resolvedMessage && !(
|
|
2332
|
+
if (!resolvedMessage && !isMessageFormat(format)) {
|
|
2278
2333
|
const defaultMsgOrKey = isString(options.default) ? options.default : isBoolean(options.default) || context.fallbackFormat ? !context.messageCompiler ? () => key : key : null;
|
|
2279
2334
|
if (context.fallbackFormat || defaultMsgOrKey != null && (isString(defaultMsgOrKey) || isFunction(defaultMsgOrKey))) {
|
|
2280
2335
|
format = defaultMsgOrKey;
|
|
2281
2336
|
cacheBaseKey = format;
|
|
2282
2337
|
}
|
|
2283
2338
|
}
|
|
2284
|
-
if (!resolvedMessage && (!(
|
|
2339
|
+
if (!resolvedMessage && (!isMessageFormat(format) || !isString(targetLocale))) return context.unresolving ? -1 : key;
|
|
2285
2340
|
if (isString(format) && context.messageCompiler == null) {
|
|
2286
|
-
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 '${
|
|
2341
|
+
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 '${stringifyKey(key)}'.`);
|
|
2287
2342
|
return key;
|
|
2288
2343
|
}
|
|
2289
2344
|
let occurred = false;
|
|
@@ -2300,9 +2355,15 @@ var IntlifyCore = (function(exports) {
|
|
|
2300
2355
|
}
|
|
2301
2356
|
function escapeParams(options) {
|
|
2302
2357
|
if (isArray(options.list)) options.list = options.list.map((item) => isString(item) ? escapeHtml(item) : item);
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2358
|
+
if (isObject(options.named)) {
|
|
2359
|
+
const source = options.named;
|
|
2360
|
+
const named = create();
|
|
2361
|
+
for (const key of Object.keys(source)) {
|
|
2362
|
+
const value = source[key];
|
|
2363
|
+
named[key] = isString(value) ? escapeHtml(value) : value;
|
|
2364
|
+
}
|
|
2365
|
+
options.named = named;
|
|
2366
|
+
}
|
|
2306
2367
|
}
|
|
2307
2368
|
function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
|
|
2308
2369
|
const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
|
|
@@ -2325,7 +2386,7 @@ var IntlifyCore = (function(exports) {
|
|
|
2325
2386
|
key,
|
|
2326
2387
|
from,
|
|
2327
2388
|
to: targetLocale,
|
|
2328
|
-
groupId:
|
|
2389
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
2329
2390
|
});
|
|
2330
2391
|
}
|
|
2331
2392
|
message = messages[targetLocale] || create();
|
|
@@ -2347,14 +2408,14 @@ var IntlifyCore = (function(exports) {
|
|
|
2347
2408
|
key,
|
|
2348
2409
|
message: format,
|
|
2349
2410
|
time: end - start,
|
|
2350
|
-
groupId:
|
|
2411
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
2351
2412
|
});
|
|
2352
2413
|
if (startTag && endTag && mark && measure) {
|
|
2353
2414
|
mark(endTag);
|
|
2354
2415
|
measure("intlify message resolve", startTag, endTag);
|
|
2355
2416
|
}
|
|
2356
2417
|
}
|
|
2357
|
-
if (
|
|
2418
|
+
if (isMessageFormat(format)) break;
|
|
2358
2419
|
if (!isImplicitFallback(targetLocale, locales)) {
|
|
2359
2420
|
const missingRet = handleMissing(context, key, targetLocale, missingWarn, type);
|
|
2360
2421
|
if (missingRet !== key) format = missingRet;
|
|
@@ -2367,6 +2428,9 @@ var IntlifyCore = (function(exports) {
|
|
|
2367
2428
|
message
|
|
2368
2429
|
];
|
|
2369
2430
|
}
|
|
2431
|
+
function stringifyKey(key) {
|
|
2432
|
+
return isString(key) ? key : isObject(key) ? JSON.stringify(key) : isFunction(key) ? key.name || "function" : "";
|
|
2433
|
+
}
|
|
2370
2434
|
function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) {
|
|
2371
2435
|
if (isMessageFunction(format)) {
|
|
2372
2436
|
const msg = format;
|
|
@@ -2397,7 +2461,7 @@ var IntlifyCore = (function(exports) {
|
|
|
2397
2461
|
type: "message-compilation",
|
|
2398
2462
|
message: format,
|
|
2399
2463
|
time: end - start,
|
|
2400
|
-
groupId:
|
|
2464
|
+
groupId: toDevtoolsGroupId("translate", key)
|
|
2401
2465
|
});
|
|
2402
2466
|
if (startTag && endTag && mark && measure) {
|
|
2403
2467
|
mark(endTag);
|
|
@@ -2422,7 +2486,7 @@ var IntlifyCore = (function(exports) {
|
|
|
2422
2486
|
type: "message-evaluation",
|
|
2423
2487
|
value: messaged,
|
|
2424
2488
|
time: end - start,
|
|
2425
|
-
groupId:
|
|
2489
|
+
groupId: toDevtoolsGroupId("translate", msg.key)
|
|
2426
2490
|
});
|
|
2427
2491
|
mark(endTag);
|
|
2428
2492
|
measure("intlify message evaluation", startTag, endTag);
|
|
@@ -2460,12 +2524,11 @@ var IntlifyCore = (function(exports) {
|
|
|
2460
2524
|
error: err.message,
|
|
2461
2525
|
start: err.location && err.location.start.offset,
|
|
2462
2526
|
end: err.location && err.location.end.offset,
|
|
2463
|
-
groupId:
|
|
2527
|
+
groupId: toDevtoolsGroupId("translate", key)
|
|
2464
2528
|
});
|
|
2465
2529
|
const message = `Message compilation error: ${err.message}`;
|
|
2466
2530
|
throw new SyntaxError(codeFrame ? `${message}\n${codeFrame}` : message);
|
|
2467
2531
|
}
|
|
2468
|
-
throw err;
|
|
2469
2532
|
},
|
|
2470
2533
|
onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
|
|
2471
2534
|
};
|
|
@@ -2526,7 +2589,6 @@ var IntlifyCore = (function(exports) {
|
|
|
2526
2589
|
exports.datetime = datetime;
|
|
2527
2590
|
exports.fallbackWithLocaleChain = fallbackWithLocaleChain;
|
|
2528
2591
|
exports.fallbackWithSimple = fallbackWithSimple;
|
|
2529
|
-
exports.getFallbackContext = getFallbackContext;
|
|
2530
2592
|
exports.getLocale = getLocale;
|
|
2531
2593
|
exports.getLocaleMessage = getLocaleMessage;
|
|
2532
2594
|
exports.getWarnMessage = getWarnMessage;
|
|
@@ -2534,6 +2596,7 @@ var IntlifyCore = (function(exports) {
|
|
|
2534
2596
|
exports.isAlmostSameLocale = isAlmostSameLocale;
|
|
2535
2597
|
exports.isImplicitFallback = isImplicitFallback;
|
|
2536
2598
|
exports.isMessageAST = isMessageAST;
|
|
2599
|
+
exports.isMessageFormat = isMessageFormat;
|
|
2537
2600
|
exports.isMessageFunction = isMessageFunction;
|
|
2538
2601
|
exports.isTranslateFallbackWarn = isTranslateFallbackWarn;
|
|
2539
2602
|
exports.isTranslateMissingWarn = isTranslateMissingWarn;
|
|
@@ -2548,7 +2611,6 @@ var IntlifyCore = (function(exports) {
|
|
|
2548
2611
|
exports.resolveLocale = resolveLocale;
|
|
2549
2612
|
exports.resolveValue = resolveValue;
|
|
2550
2613
|
exports.resolveWithKeyValue = resolveWithKeyValue;
|
|
2551
|
-
exports.setFallbackContext = setFallbackContext;
|
|
2552
2614
|
exports.setLocaleMessage = setLocaleMessage;
|
|
2553
2615
|
exports.translate = translate;
|
|
2554
2616
|
exports.updateFallbackLocale = updateFallbackLocale;
|