@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
|
@@ -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
|
|
@@ -365,7 +416,7 @@ var IntlifyCore = (function(exports) {
|
|
|
365
416
|
function clearCompileCache() {
|
|
366
417
|
compileCache = create();
|
|
367
418
|
}
|
|
368
|
-
/*
|
|
419
|
+
/* #__NO_SIDE_EFFECTS__ */
|
|
369
420
|
function compile(message, context) {
|
|
370
421
|
{
|
|
371
422
|
if (!isMessageAST(message)) {
|
|
@@ -386,12 +437,11 @@ var IntlifyCore = (function(exports) {
|
|
|
386
437
|
INVALID_ARGUMENT: 17,
|
|
387
438
|
INVALID_DATE_ARGUMENT: 18,
|
|
388
439
|
INVALID_ISO_DATE_ARGUMENT: 19,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
NOT_SUPPORT_LOCALE_TYPE: 23
|
|
440
|
+
NOT_SUPPORT_LOCALE_PROMISE_VALUE: 20,
|
|
441
|
+
NOT_SUPPORT_LOCALE_ASYNC_FUNCTION: 21,
|
|
442
|
+
NOT_SUPPORT_LOCALE_TYPE: 22
|
|
393
443
|
};
|
|
394
|
-
const CORE_ERROR_CODES_EXTEND_POINT =
|
|
444
|
+
const CORE_ERROR_CODES_EXTEND_POINT = 23;
|
|
395
445
|
function createCoreError(code) {
|
|
396
446
|
return createCompileError(code, null, { messages: errorMessages });
|
|
397
447
|
}
|
|
@@ -400,7 +450,6 @@ var IntlifyCore = (function(exports) {
|
|
|
400
450
|
[CoreErrorCodes.INVALID_ARGUMENT]: "Invalid arguments",
|
|
401
451
|
[CoreErrorCodes.INVALID_DATE_ARGUMENT]: "The date provided is an invalid Date object.Make sure your Date represents a valid date.",
|
|
402
452
|
[CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: "The argument provided is not a valid ISO date string",
|
|
403
|
-
[CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE]: "Not support non-string message",
|
|
404
453
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE]: "cannot support promise value",
|
|
405
454
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION]: "cannot support async function",
|
|
406
455
|
[CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE]: "cannot support locale type"
|
|
@@ -415,13 +464,14 @@ var IntlifyCore = (function(exports) {
|
|
|
415
464
|
/** @internal */
|
|
416
465
|
function resolveLocale(locale) {
|
|
417
466
|
if (isString(locale)) return locale;
|
|
418
|
-
else if (isFunction(locale))
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
467
|
+
else if (isFunction(locale)) {
|
|
468
|
+
if (locale.resolvedOnce && _resolveLocale != null) return _resolveLocale;
|
|
469
|
+
else if (locale.constructor.name === "Function") {
|
|
470
|
+
const resolve = locale();
|
|
471
|
+
if (isPromise(resolve)) throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_PROMISE_VALUE);
|
|
472
|
+
return _resolveLocale = resolve;
|
|
473
|
+
} else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_ASYNC_FUNCTION);
|
|
474
|
+
} else throw createCoreError(CoreErrorCodes.NOT_SUPPORT_LOCALE_TYPE);
|
|
425
475
|
}
|
|
426
476
|
/**
|
|
427
477
|
* Fallback with simple implemenation
|
|
@@ -429,7 +479,7 @@ var IntlifyCore = (function(exports) {
|
|
|
429
479
|
* @remarks
|
|
430
480
|
* A fallback locale function implemented with a simple fallback algorithm.
|
|
431
481
|
*
|
|
432
|
-
* Basically,
|
|
482
|
+
* 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.
|
|
433
483
|
*
|
|
434
484
|
* @param ctx - A {@link CoreContext | context}
|
|
435
485
|
* @param fallback - A {@link FallbackLocale | fallback locale}
|
|
@@ -440,7 +490,7 @@ var IntlifyCore = (function(exports) {
|
|
|
440
490
|
* @VueI18nGeneral
|
|
441
491
|
*/
|
|
442
492
|
function fallbackWithSimple(_ctx, fallback, start) {
|
|
443
|
-
return [
|
|
493
|
+
return [.../* @__PURE__ */ new Set([start, ...isArray(fallback) ? fallback : isObject(fallback) ? Object.keys(fallback).filter((locale) => locale !== "default") : isString(fallback) ? [fallback] : [start]])];
|
|
444
494
|
}
|
|
445
495
|
/**
|
|
446
496
|
* Fallback with locale chain
|
|
@@ -448,6 +498,9 @@ var IntlifyCore = (function(exports) {
|
|
|
448
498
|
* @remarks
|
|
449
499
|
* A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
|
|
450
500
|
*
|
|
501
|
+
* Chains are cached per fallback identity. If you mutate an object or array fallback in place,
|
|
502
|
+
* pass a new object or array instead so that the chain is recomputed.
|
|
503
|
+
*
|
|
451
504
|
* @param ctx - A {@link CoreContext | context}
|
|
452
505
|
* @param fallback - A {@link FallbackLocale | fallback locale}
|
|
453
506
|
* @param start - A starting {@link Locale | locale}
|
|
@@ -461,17 +514,31 @@ var IntlifyCore = (function(exports) {
|
|
|
461
514
|
function fallbackWithLocaleChain(ctx, fallback, start) {
|
|
462
515
|
const startLocale = isString(start) ? start : DEFAULT_LOCALE;
|
|
463
516
|
const context = ctx;
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
context.__localeChainCache.
|
|
517
|
+
let chains;
|
|
518
|
+
if (isObject(fallback)) {
|
|
519
|
+
if (!context.__localeChainObjectCache) context.__localeChainObjectCache = /* @__PURE__ */ new WeakMap();
|
|
520
|
+
chains = context.__localeChainObjectCache.get(fallback);
|
|
521
|
+
if (!chains) {
|
|
522
|
+
chains = /* @__PURE__ */ new Map();
|
|
523
|
+
context.__localeChainObjectCache.set(fallback, chains);
|
|
524
|
+
}
|
|
525
|
+
} else {
|
|
526
|
+
if (!context.__localeChainCache) context.__localeChainCache = /* @__PURE__ */ new Map();
|
|
527
|
+
chains = context.__localeChainCache.get(fallback);
|
|
528
|
+
if (!chains) {
|
|
529
|
+
chains = /* @__PURE__ */ new Map();
|
|
530
|
+
context.__localeChainCache.set(fallback, chains);
|
|
531
|
+
}
|
|
474
532
|
}
|
|
533
|
+
const cached = chains.get(startLocale);
|
|
534
|
+
if (cached) return cached;
|
|
535
|
+
const chain = [];
|
|
536
|
+
let block = [start];
|
|
537
|
+
while (isArray(block)) block = appendBlockToChain(chain, block, fallback);
|
|
538
|
+
const defaults = isArray(fallback) || !isPlainObject(fallback) ? fallback : fallback["default"] ? fallback["default"] : null;
|
|
539
|
+
block = isString(defaults) ? [defaults] : defaults;
|
|
540
|
+
if (isArray(block)) appendBlockToChain(chain, block, false);
|
|
541
|
+
chains.set(startLocale, chain);
|
|
475
542
|
return chain;
|
|
476
543
|
}
|
|
477
544
|
function appendBlockToChain(chain, block, blocks) {
|
|
@@ -763,7 +830,7 @@ var IntlifyCore = (function(exports) {
|
|
|
763
830
|
* Intlify core-base version
|
|
764
831
|
* @internal
|
|
765
832
|
*/
|
|
766
|
-
const VERSION = "12.0.0-alpha.
|
|
833
|
+
const VERSION = "12.0.0-alpha.5";
|
|
767
834
|
const NOT_RESOLVED = -1;
|
|
768
835
|
const DEFAULT_LOCALE = "en-US";
|
|
769
836
|
const MISSING_RESOLVE_VALUE = "";
|
|
@@ -823,11 +890,6 @@ var IntlifyCore = (function(exports) {
|
|
|
823
890
|
warnOnce(`registerLocaleFallbacker is deprecated. Use 'localeFallbacker' option of 'createI18n' or 'createCoreContext' instead.`);
|
|
824
891
|
_fallbacker = fallbacker;
|
|
825
892
|
}
|
|
826
|
-
let _fallbackContext = null;
|
|
827
|
-
const setFallbackContext = (context) => {
|
|
828
|
-
_fallbackContext = context;
|
|
829
|
-
};
|
|
830
|
-
const getFallbackContext = () => _fallbackContext;
|
|
831
893
|
let _cid = 0;
|
|
832
894
|
function createCoreContext(options = {}) {
|
|
833
895
|
const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
|
|
@@ -892,7 +954,7 @@ var IntlifyCore = (function(exports) {
|
|
|
892
954
|
* @version 12.0.0
|
|
893
955
|
*/
|
|
894
956
|
function getLocaleMessage(ctx, locale) {
|
|
895
|
-
const src = ctx.messages
|
|
957
|
+
const src = getOwn(ctx.messages, locale);
|
|
896
958
|
if (src == null) return;
|
|
897
959
|
const dest = create();
|
|
898
960
|
deepCopy(src, dest);
|
|
@@ -902,6 +964,7 @@ var IntlifyCore = (function(exports) {
|
|
|
902
964
|
* @version 12.0.0
|
|
903
965
|
*/
|
|
904
966
|
function setLocaleMessage(ctx, locale, messages) {
|
|
967
|
+
if (isObjectPrototypeKey(locale)) return;
|
|
905
968
|
ctx.messages[locale] = messages;
|
|
906
969
|
}
|
|
907
970
|
/** @internal */
|
|
@@ -921,7 +984,7 @@ var IntlifyCore = (function(exports) {
|
|
|
921
984
|
locale,
|
|
922
985
|
key,
|
|
923
986
|
type,
|
|
924
|
-
groupId:
|
|
987
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
925
988
|
});
|
|
926
989
|
}
|
|
927
990
|
if (missing !== null) {
|
|
@@ -935,10 +998,15 @@ var IntlifyCore = (function(exports) {
|
|
|
935
998
|
return key;
|
|
936
999
|
}
|
|
937
1000
|
}
|
|
1001
|
+
function invalidateLocaleChainCache(ctx, fallback) {
|
|
1002
|
+
const context = ctx;
|
|
1003
|
+
if (isObject(fallback)) context.__localeChainObjectCache?.delete(fallback);
|
|
1004
|
+
else context.__localeChainCache?.delete(fallback);
|
|
1005
|
+
}
|
|
938
1006
|
/** @internal */
|
|
939
1007
|
function updateFallbackLocale(ctx, locale, fallback) {
|
|
940
|
-
|
|
941
|
-
|
|
1008
|
+
invalidateLocaleChainCache(ctx, fallback);
|
|
1009
|
+
if (ctx.fallbackContext) invalidateLocaleChainCache(ctx.fallbackContext, fallback);
|
|
942
1010
|
ctx.localeFallbacker(ctx, fallback, locale);
|
|
943
1011
|
}
|
|
944
1012
|
/** @internal */
|
|
@@ -954,6 +1022,59 @@ var IntlifyCore = (function(exports) {
|
|
|
954
1022
|
return false;
|
|
955
1023
|
}
|
|
956
1024
|
//#endregion
|
|
1025
|
+
//#region packages/core-base/src/formatter.ts
|
|
1026
|
+
function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
|
|
1027
|
+
const { fallbackLocale, localeFallbacker, onWarn } = context;
|
|
1028
|
+
const locales = localeFallbacker(context, fallbackLocale, locale);
|
|
1029
|
+
let from = locale;
|
|
1030
|
+
for (let i = 0; i < locales.length; i++) {
|
|
1031
|
+
const targetLocale = locales[i];
|
|
1032
|
+
if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(type === "datetime format" ? CoreWarnCodes.FALLBACK_TO_DATE_FORMAT : CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
|
|
1033
|
+
key,
|
|
1034
|
+
target: targetLocale
|
|
1035
|
+
}));
|
|
1036
|
+
if (locale !== targetLocale) {
|
|
1037
|
+
const emitter = context.__v_emitter;
|
|
1038
|
+
if (emitter) emitter.emit("fallback", {
|
|
1039
|
+
type,
|
|
1040
|
+
key,
|
|
1041
|
+
from,
|
|
1042
|
+
to: targetLocale,
|
|
1043
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
const format = (formats[targetLocale] || {})[key];
|
|
1047
|
+
if (isPlainObject(format) && isString(targetLocale)) return targetLocale;
|
|
1048
|
+
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
1049
|
+
from = targetLocale;
|
|
1050
|
+
}
|
|
1051
|
+
return null;
|
|
1052
|
+
}
|
|
1053
|
+
function getFormatterCacheKey(locale, key, overrides) {
|
|
1054
|
+
let id = `${locale}__${key}`;
|
|
1055
|
+
if (isPlainObject(overrides) && !isKeylessObject(overrides)) id = `${id}__${JSON.stringify(overrides)}`;
|
|
1056
|
+
return id;
|
|
1057
|
+
}
|
|
1058
|
+
function clearFormatCache(formatters, locale, format) {
|
|
1059
|
+
for (const key in format) {
|
|
1060
|
+
const prefix = `${locale}__${key}`;
|
|
1061
|
+
for (const id of formatters.keys()) if (id === prefix || id.startsWith(`${prefix}__`)) formatters.delete(id);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
function parseFormatArgs(args, options, initialOverrides, optionsKeys) {
|
|
1065
|
+
const [, arg2, arg3, arg4] = args;
|
|
1066
|
+
let overrides = initialOverrides;
|
|
1067
|
+
if (isString(arg2)) options.key = arg2;
|
|
1068
|
+
else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
|
|
1069
|
+
if (optionsKeys.includes(key)) overrides[key] = arg2[key];
|
|
1070
|
+
else options[key] = arg2[key];
|
|
1071
|
+
});
|
|
1072
|
+
if (isString(arg3)) options.locale = arg3;
|
|
1073
|
+
else if (isPlainObject(arg3)) overrides = arg3;
|
|
1074
|
+
if (isPlainObject(arg4)) overrides = arg4;
|
|
1075
|
+
return overrides;
|
|
1076
|
+
}
|
|
1077
|
+
//#endregion
|
|
957
1078
|
//#region packages/core-base/src/intl.ts
|
|
958
1079
|
const intlDefined = typeof Intl !== "undefined";
|
|
959
1080
|
const Availabilities = {
|
|
@@ -963,7 +1084,7 @@ var IntlifyCore = (function(exports) {
|
|
|
963
1084
|
//#endregion
|
|
964
1085
|
//#region packages/core-base/src/datetime.ts
|
|
965
1086
|
function datetime(context, ...args) {
|
|
966
|
-
const { datetimeFormats, unresolving,
|
|
1087
|
+
const { datetimeFormats, unresolving, onWarn } = context;
|
|
967
1088
|
const { __datetimeFormatters } = context;
|
|
968
1089
|
if (!Availabilities.dateTimeFormat) {
|
|
969
1090
|
onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
|
|
@@ -978,39 +1099,14 @@ var IntlifyCore = (function(exports) {
|
|
|
978
1099
|
const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
|
|
979
1100
|
const part = !!options.part;
|
|
980
1101
|
const locale = getLocale(context, options);
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
let targetLocale;
|
|
985
|
-
let format = null;
|
|
986
|
-
let from = locale;
|
|
987
|
-
let to = null;
|
|
988
|
-
const type = "datetime format";
|
|
989
|
-
for (let i = 0; i < locales.length; i++) {
|
|
990
|
-
targetLocale = to = locales[i];
|
|
991
|
-
if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
|
|
992
|
-
key,
|
|
993
|
-
target: targetLocale
|
|
994
|
-
}));
|
|
995
|
-
if (locale !== targetLocale) {
|
|
996
|
-
const emitter = context.__v_emitter;
|
|
997
|
-
if (emitter) emitter.emit("fallback", {
|
|
998
|
-
type,
|
|
999
|
-
key,
|
|
1000
|
-
from,
|
|
1001
|
-
to,
|
|
1002
|
-
groupId: `${type}:${key}`
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
datetimeFormat = datetimeFormats[targetLocale] || {};
|
|
1006
|
-
format = datetimeFormat[key];
|
|
1007
|
-
if (isPlainObject(format)) break;
|
|
1008
|
-
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
1009
|
-
from = to;
|
|
1102
|
+
if (!isString(key) || key === "") {
|
|
1103
|
+
const formatter = new Intl.DateTimeFormat(locale.replace(/!/g, ""), overrides);
|
|
1104
|
+
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1010
1105
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1106
|
+
const targetLocale = resolveFormatLocale(context, key, locale, datetimeFormats, missingWarn, fallbackWarn, "datetime format");
|
|
1107
|
+
if (!isString(targetLocale)) return unresolving ? -1 : key;
|
|
1108
|
+
const format = datetimeFormats[targetLocale][key];
|
|
1109
|
+
const id = getFormatterCacheKey(targetLocale, key, overrides);
|
|
1014
1110
|
let formatter = __datetimeFormatters.get(id);
|
|
1015
1111
|
if (!formatter) {
|
|
1016
1112
|
formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
|
|
@@ -1043,12 +1139,12 @@ var IntlifyCore = (function(exports) {
|
|
|
1043
1139
|
];
|
|
1044
1140
|
/** @internal */
|
|
1045
1141
|
function parseDateTimeArgs(...args) {
|
|
1046
|
-
const [arg1
|
|
1142
|
+
const [arg1] = args;
|
|
1047
1143
|
const options = create();
|
|
1048
|
-
|
|
1144
|
+
const initialOverrides = create();
|
|
1049
1145
|
let value;
|
|
1050
1146
|
if (isString(arg1)) {
|
|
1051
|
-
const matches = arg1.match(
|
|
1147
|
+
const matches = arg1.match(/^(\d{4}-\d{2}-\d{2})(?:(T|\s)(.+))?$/);
|
|
1052
1148
|
if (!matches) throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
|
|
1053
1149
|
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();
|
|
1054
1150
|
value = new Date(dateTime);
|
|
@@ -1062,14 +1158,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1062
1158
|
value = arg1;
|
|
1063
1159
|
} else if (isNumber(arg1)) value = arg1;
|
|
1064
1160
|
else throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
1065
|
-
|
|
1066
|
-
else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
|
|
1067
|
-
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) overrides[key] = arg2[key];
|
|
1068
|
-
else options[key] = arg2[key];
|
|
1069
|
-
});
|
|
1070
|
-
if (isString(arg3)) options.locale = arg3;
|
|
1071
|
-
else if (isPlainObject(arg3)) overrides = arg3;
|
|
1072
|
-
if (isPlainObject(arg4)) overrides = arg4;
|
|
1161
|
+
const overrides = parseFormatArgs(args, options, initialOverrides, DATETIME_FORMAT_OPTIONS_KEYS);
|
|
1073
1162
|
return [
|
|
1074
1163
|
options.key || "",
|
|
1075
1164
|
value,
|
|
@@ -1079,17 +1168,12 @@ var IntlifyCore = (function(exports) {
|
|
|
1079
1168
|
}
|
|
1080
1169
|
/** @internal */
|
|
1081
1170
|
function clearDateTimeFormat(ctx, locale, format) {
|
|
1082
|
-
|
|
1083
|
-
for (const key in format) {
|
|
1084
|
-
const id = `${locale}__${key}`;
|
|
1085
|
-
if (!context.__datetimeFormatters.has(id)) continue;
|
|
1086
|
-
context.__datetimeFormatters.delete(id);
|
|
1087
|
-
}
|
|
1171
|
+
clearFormatCache(ctx.__datetimeFormatters, locale, format);
|
|
1088
1172
|
}
|
|
1089
1173
|
//#endregion
|
|
1090
1174
|
//#region packages/core-base/src/number.ts
|
|
1091
1175
|
function number(context, ...args) {
|
|
1092
|
-
const { numberFormats, unresolving,
|
|
1176
|
+
const { numberFormats, unresolving, onWarn } = context;
|
|
1093
1177
|
const { __numberFormatters } = context;
|
|
1094
1178
|
if (!Availabilities.numberFormat) {
|
|
1095
1179
|
onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
|
|
@@ -1104,39 +1188,14 @@ var IntlifyCore = (function(exports) {
|
|
|
1104
1188
|
const fallbackWarn = isBoolean(options.fallbackWarn) ? options.fallbackWarn : context.fallbackWarn;
|
|
1105
1189
|
const part = !!options.part;
|
|
1106
1190
|
const locale = getLocale(context, options);
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
let targetLocale;
|
|
1111
|
-
let format = null;
|
|
1112
|
-
let from = locale;
|
|
1113
|
-
let to = null;
|
|
1114
|
-
const type = "number format";
|
|
1115
|
-
for (let i = 0; i < locales.length; i++) {
|
|
1116
|
-
targetLocale = to = locales[i];
|
|
1117
|
-
if (locale !== targetLocale && isTranslateFallbackWarn(fallbackWarn, key)) onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
|
|
1118
|
-
key,
|
|
1119
|
-
target: targetLocale
|
|
1120
|
-
}));
|
|
1121
|
-
if (locale !== targetLocale) {
|
|
1122
|
-
const emitter = context.__v_emitter;
|
|
1123
|
-
if (emitter) emitter.emit("fallback", {
|
|
1124
|
-
type,
|
|
1125
|
-
key,
|
|
1126
|
-
from,
|
|
1127
|
-
to,
|
|
1128
|
-
groupId: `${type}:${key}`
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
numberFormat = numberFormats[targetLocale] || {};
|
|
1132
|
-
format = numberFormat[key];
|
|
1133
|
-
if (isPlainObject(format)) break;
|
|
1134
|
-
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
1135
|
-
from = to;
|
|
1191
|
+
if (!isString(key) || key === "") {
|
|
1192
|
+
const formatter = new Intl.NumberFormat(locale.replace(/!/g, ""), overrides);
|
|
1193
|
+
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1136
1194
|
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1195
|
+
const targetLocale = resolveFormatLocale(context, key, locale, numberFormats, missingWarn, fallbackWarn, "number format");
|
|
1196
|
+
if (!isString(targetLocale)) return unresolving ? -1 : key;
|
|
1197
|
+
const format = numberFormats[targetLocale][key];
|
|
1198
|
+
const id = getFormatterCacheKey(targetLocale, key, overrides);
|
|
1140
1199
|
let formatter = __numberFormatters.get(id);
|
|
1141
1200
|
if (!formatter) {
|
|
1142
1201
|
formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
|
|
@@ -1169,19 +1228,12 @@ var IntlifyCore = (function(exports) {
|
|
|
1169
1228
|
];
|
|
1170
1229
|
/** @internal */
|
|
1171
1230
|
function parseNumberArgs(...args) {
|
|
1172
|
-
const [arg1
|
|
1231
|
+
const [arg1] = args;
|
|
1173
1232
|
const options = create();
|
|
1174
|
-
|
|
1233
|
+
const initialOverrides = create();
|
|
1175
1234
|
if (!isNumber(arg1)) throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
1176
1235
|
const value = arg1;
|
|
1177
|
-
|
|
1178
|
-
else if (isPlainObject(arg2)) Object.keys(arg2).forEach((key) => {
|
|
1179
|
-
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) overrides[key] = arg2[key];
|
|
1180
|
-
else options[key] = arg2[key];
|
|
1181
|
-
});
|
|
1182
|
-
if (isString(arg3)) options.locale = arg3;
|
|
1183
|
-
else if (isPlainObject(arg3)) overrides = arg3;
|
|
1184
|
-
if (isPlainObject(arg4)) overrides = arg4;
|
|
1236
|
+
const overrides = parseFormatArgs(args, options, initialOverrides, NUMBER_FORMAT_OPTIONS_KEYS);
|
|
1185
1237
|
return [
|
|
1186
1238
|
options.key || "",
|
|
1187
1239
|
value,
|
|
@@ -1191,12 +1243,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1191
1243
|
}
|
|
1192
1244
|
/** @internal */
|
|
1193
1245
|
function clearNumberFormat(ctx, locale, format) {
|
|
1194
|
-
|
|
1195
|
-
for (const key in format) {
|
|
1196
|
-
const id = `${locale}__${key}`;
|
|
1197
|
-
if (!context.__numberFormatters.has(id)) continue;
|
|
1198
|
-
context.__numberFormatters.delete(id);
|
|
1199
|
-
}
|
|
1246
|
+
clearFormatCache(ctx.__numberFormatters, locale, format);
|
|
1200
1247
|
}
|
|
1201
1248
|
//#endregion
|
|
1202
1249
|
//#region packages/core-base/src/runtime.ts
|
|
@@ -1301,6 +1348,8 @@ var IntlifyCore = (function(exports) {
|
|
|
1301
1348
|
//#region packages/core-base/src/translate.ts
|
|
1302
1349
|
const NOOP_MESSAGE_FUNCTION = () => "";
|
|
1303
1350
|
const isMessageFunction = (val) => isFunction(val);
|
|
1351
|
+
/** @internal */
|
|
1352
|
+
const isMessageFormat = (val) => isString(val) || isMessageAST(val) || isMessageFunction(val);
|
|
1304
1353
|
function translate(context, ...args) {
|
|
1305
1354
|
const [key, options] = parseTranslateArgs(...args);
|
|
1306
1355
|
const locale = getLocale(context, options);
|
|
@@ -1313,16 +1362,16 @@ var IntlifyCore = (function(exports) {
|
|
|
1313
1362
|
context.messages[locale] || create()
|
|
1314
1363
|
];
|
|
1315
1364
|
let cacheBaseKey = key;
|
|
1316
|
-
if (!resolvedMessage && !(
|
|
1365
|
+
if (!resolvedMessage && !isMessageFormat(format)) {
|
|
1317
1366
|
const defaultMsgOrKey = isString(options.default) ? options.default : isBoolean(options.default) || context.fallbackFormat ? !context.messageCompiler ? () => key : key : null;
|
|
1318
1367
|
if (context.fallbackFormat || defaultMsgOrKey != null && (isString(defaultMsgOrKey) || isFunction(defaultMsgOrKey))) {
|
|
1319
1368
|
format = defaultMsgOrKey;
|
|
1320
1369
|
cacheBaseKey = format;
|
|
1321
1370
|
}
|
|
1322
1371
|
}
|
|
1323
|
-
if (!resolvedMessage && (!(
|
|
1372
|
+
if (!resolvedMessage && (!isMessageFormat(format) || !isString(targetLocale))) return context.unresolving ? -1 : key;
|
|
1324
1373
|
if (isString(format) && context.messageCompiler == null) {
|
|
1325
|
-
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 '${
|
|
1374
|
+
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)}'.`);
|
|
1326
1375
|
return key;
|
|
1327
1376
|
}
|
|
1328
1377
|
let occurred = false;
|
|
@@ -1339,9 +1388,15 @@ var IntlifyCore = (function(exports) {
|
|
|
1339
1388
|
}
|
|
1340
1389
|
function escapeParams(options) {
|
|
1341
1390
|
if (isArray(options.list)) options.list = options.list.map((item) => isString(item) ? escapeHtml(item) : item);
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1391
|
+
if (isObject(options.named)) {
|
|
1392
|
+
const source = options.named;
|
|
1393
|
+
const named = create();
|
|
1394
|
+
for (const key of Object.keys(source)) {
|
|
1395
|
+
const value = source[key];
|
|
1396
|
+
named[key] = isString(value) ? escapeHtml(value) : value;
|
|
1397
|
+
}
|
|
1398
|
+
options.named = named;
|
|
1399
|
+
}
|
|
1345
1400
|
}
|
|
1346
1401
|
function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
|
|
1347
1402
|
const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
|
|
@@ -1364,7 +1419,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1364
1419
|
key,
|
|
1365
1420
|
from,
|
|
1366
1421
|
to: targetLocale,
|
|
1367
|
-
groupId:
|
|
1422
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
1368
1423
|
});
|
|
1369
1424
|
}
|
|
1370
1425
|
message = messages[targetLocale] || create();
|
|
@@ -1386,14 +1441,14 @@ var IntlifyCore = (function(exports) {
|
|
|
1386
1441
|
key,
|
|
1387
1442
|
message: format,
|
|
1388
1443
|
time: end - start,
|
|
1389
|
-
groupId:
|
|
1444
|
+
groupId: toDevtoolsGroupId(type, key)
|
|
1390
1445
|
});
|
|
1391
1446
|
if (startTag && endTag && mark && measure) {
|
|
1392
1447
|
mark(endTag);
|
|
1393
1448
|
measure("intlify message resolve", startTag, endTag);
|
|
1394
1449
|
}
|
|
1395
1450
|
}
|
|
1396
|
-
if (
|
|
1451
|
+
if (isMessageFormat(format)) break;
|
|
1397
1452
|
if (!isImplicitFallback(targetLocale, locales)) {
|
|
1398
1453
|
const missingRet = handleMissing(context, key, targetLocale, missingWarn, type);
|
|
1399
1454
|
if (missingRet !== key) format = missingRet;
|
|
@@ -1406,6 +1461,9 @@ var IntlifyCore = (function(exports) {
|
|
|
1406
1461
|
message
|
|
1407
1462
|
];
|
|
1408
1463
|
}
|
|
1464
|
+
function stringifyKey(key) {
|
|
1465
|
+
return isString(key) ? key : isObject(key) ? JSON.stringify(key) : isFunction(key) ? key.name || "function" : "";
|
|
1466
|
+
}
|
|
1409
1467
|
function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) {
|
|
1410
1468
|
if (isMessageFunction(format)) {
|
|
1411
1469
|
const msg = format;
|
|
@@ -1436,7 +1494,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1436
1494
|
type: "message-compilation",
|
|
1437
1495
|
message: format,
|
|
1438
1496
|
time: end - start,
|
|
1439
|
-
groupId:
|
|
1497
|
+
groupId: toDevtoolsGroupId("translate", key)
|
|
1440
1498
|
});
|
|
1441
1499
|
if (startTag && endTag && mark && measure) {
|
|
1442
1500
|
mark(endTag);
|
|
@@ -1461,7 +1519,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1461
1519
|
type: "message-evaluation",
|
|
1462
1520
|
value: messaged,
|
|
1463
1521
|
time: end - start,
|
|
1464
|
-
groupId:
|
|
1522
|
+
groupId: toDevtoolsGroupId("translate", msg.key)
|
|
1465
1523
|
});
|
|
1466
1524
|
mark(endTag);
|
|
1467
1525
|
measure("intlify message evaluation", startTag, endTag);
|
|
@@ -1499,12 +1557,11 @@ var IntlifyCore = (function(exports) {
|
|
|
1499
1557
|
error: err.message,
|
|
1500
1558
|
start: err.location && err.location.start.offset,
|
|
1501
1559
|
end: err.location && err.location.end.offset,
|
|
1502
|
-
groupId:
|
|
1560
|
+
groupId: toDevtoolsGroupId("translate", key)
|
|
1503
1561
|
});
|
|
1504
1562
|
const message = `Message compilation error: ${err.message}`;
|
|
1505
1563
|
throw new SyntaxError(codeFrame ? `${message}\n${codeFrame}` : message);
|
|
1506
1564
|
}
|
|
1507
|
-
throw err;
|
|
1508
1565
|
},
|
|
1509
1566
|
onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
|
|
1510
1567
|
};
|
|
@@ -1570,7 +1627,6 @@ var IntlifyCore = (function(exports) {
|
|
|
1570
1627
|
exports.datetime = datetime;
|
|
1571
1628
|
exports.fallbackWithLocaleChain = fallbackWithLocaleChain;
|
|
1572
1629
|
exports.fallbackWithSimple = fallbackWithSimple;
|
|
1573
|
-
exports.getFallbackContext = getFallbackContext;
|
|
1574
1630
|
exports.getLocale = getLocale;
|
|
1575
1631
|
exports.getLocaleMessage = getLocaleMessage;
|
|
1576
1632
|
exports.getWarnMessage = getWarnMessage;
|
|
@@ -1578,6 +1634,7 @@ var IntlifyCore = (function(exports) {
|
|
|
1578
1634
|
exports.isAlmostSameLocale = isAlmostSameLocale;
|
|
1579
1635
|
exports.isImplicitFallback = isImplicitFallback;
|
|
1580
1636
|
exports.isMessageAST = isMessageAST;
|
|
1637
|
+
exports.isMessageFormat = isMessageFormat;
|
|
1581
1638
|
exports.isMessageFunction = isMessageFunction;
|
|
1582
1639
|
exports.isTranslateFallbackWarn = isTranslateFallbackWarn;
|
|
1583
1640
|
exports.isTranslateMissingWarn = isTranslateMissingWarn;
|
|
@@ -1592,7 +1649,6 @@ var IntlifyCore = (function(exports) {
|
|
|
1592
1649
|
exports.resolveLocale = resolveLocale;
|
|
1593
1650
|
exports.resolveValue = resolveValue;
|
|
1594
1651
|
exports.resolveWithKeyValue = resolveWithKeyValue;
|
|
1595
|
-
exports.setFallbackContext = setFallbackContext;
|
|
1596
1652
|
exports.setLocaleMessage = setLocaleMessage;
|
|
1597
1653
|
exports.translate = translate;
|
|
1598
1654
|
exports.updateFallbackLocale = updateFallbackLocale;
|