@intlify/core 11.4.7 → 11.4.8
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.cjs +1 -1
- package/dist/core.esm-browser.js +215 -248
- package/dist/core.esm-browser.prod.js +2 -2
- package/dist/core.global.js +208 -241
- package/dist/core.global.prod.js +2 -2
- package/dist/core.mjs +1 -1
- package/dist/core.node.mjs +1 -1
- package/dist/core.prod.cjs +1 -1
- package/dist/core.runtime.esm-browser.js +215 -248
- package/dist/core.runtime.esm-browser.prod.js +2 -2
- package/dist/core.runtime.global.js +208 -241
- package/dist/core.runtime.global.prod.js +2 -2
- package/dist/core.runtime.mjs +1 -1
- package/dist/core.runtime.node.mjs +1 -1
- package/package.json +3 -3
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* core v11.4.
|
|
2
|
+
* core v11.4.8
|
|
3
3
|
* (c) 2026 kazuya kawaguchi
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
function warn(msg, err) {
|
|
7
|
-
if (typeof console !== 'undefined') {
|
|
8
|
-
console.warn(`[intlify] ` + msg);
|
|
9
|
-
/* istanbul ignore if */
|
|
10
|
-
if (err) {
|
|
11
|
-
console.warn(err.stack);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const hasWarned = {};
|
|
16
|
-
function warnOnce(msg) {
|
|
17
|
-
if (!hasWarned[msg]) {
|
|
18
|
-
hasWarned[msg] = true;
|
|
19
|
-
warn(msg);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
6
|
/**
|
|
24
7
|
* Original Utilities
|
|
25
8
|
* written by kazuya kawaguchi
|
|
@@ -70,6 +53,93 @@ const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length ===
|
|
|
70
53
|
const assign = Object.assign;
|
|
71
54
|
const _create = Object.create;
|
|
72
55
|
const create = (obj = null) => _create(obj);
|
|
56
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
57
|
+
function hasOwn(obj, key) {
|
|
58
|
+
return hasOwnProperty.call(obj, key);
|
|
59
|
+
}
|
|
60
|
+
/* eslint-enable */
|
|
61
|
+
/**
|
|
62
|
+
* Useful Utilities By Evan you
|
|
63
|
+
* Modified by kazuya kawaguchi
|
|
64
|
+
* MIT License
|
|
65
|
+
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
|
|
66
|
+
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
|
|
67
|
+
*/
|
|
68
|
+
const isArray = Array.isArray;
|
|
69
|
+
const isFunction = (val) => typeof val === 'function';
|
|
70
|
+
const isString = (val) => typeof val === 'string';
|
|
71
|
+
const isBoolean = (val) => typeof val === 'boolean';
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
const isObject = (val) => val !== null && typeof val === 'object';
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
const isPromise = (val) => {
|
|
76
|
+
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
|
|
77
|
+
};
|
|
78
|
+
const objectToString = Object.prototype.toString;
|
|
79
|
+
const toTypeString = (value) => objectToString.call(value);
|
|
80
|
+
const isPlainObject = (val) => toTypeString(val) === '[object Object]';
|
|
81
|
+
// for converting list and named values to displayed strings.
|
|
82
|
+
const toDisplayString = (val) => {
|
|
83
|
+
return val == null
|
|
84
|
+
? ''
|
|
85
|
+
: isArray(val) || (isPlainObject(val) && val.toString === objectToString)
|
|
86
|
+
? JSON.stringify(val, null, 2)
|
|
87
|
+
: String(val);
|
|
88
|
+
};
|
|
89
|
+
function join(items, separator = '') {
|
|
90
|
+
return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
|
|
91
|
+
}
|
|
92
|
+
const RANGE = 2;
|
|
93
|
+
function generateCodeFrame(source, start = 0, end = source.length) {
|
|
94
|
+
const lines = source.split(/\r?\n/);
|
|
95
|
+
let count = 0;
|
|
96
|
+
const res = [];
|
|
97
|
+
for (let i = 0; i < lines.length; i++) {
|
|
98
|
+
count += lines[i].length + 1;
|
|
99
|
+
if (count >= start) {
|
|
100
|
+
for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
|
|
101
|
+
if (j < 0 || j >= lines.length)
|
|
102
|
+
continue;
|
|
103
|
+
const line = j + 1;
|
|
104
|
+
res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
|
|
105
|
+
const lineLength = lines[j].length;
|
|
106
|
+
if (j === i) {
|
|
107
|
+
// push underline
|
|
108
|
+
const pad = start - (count - lineLength) + 1;
|
|
109
|
+
const length = Math.max(1, end > count ? lineLength - pad : end - start);
|
|
110
|
+
res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
|
|
111
|
+
}
|
|
112
|
+
else if (j > i) {
|
|
113
|
+
if (end > count) {
|
|
114
|
+
const length = Math.max(Math.min(end - count, lineLength), 1);
|
|
115
|
+
res.push(` | ` + '^'.repeat(length));
|
|
116
|
+
}
|
|
117
|
+
count += lineLength + 1;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return res.join('\n');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function warn(msg, err) {
|
|
127
|
+
if (typeof console !== 'undefined') {
|
|
128
|
+
console.warn(`[intlify] ` + msg);
|
|
129
|
+
/* istanbul ignore if */
|
|
130
|
+
if (err) {
|
|
131
|
+
console.warn(err.stack);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const hasWarned = {};
|
|
136
|
+
function warnOnce(msg) {
|
|
137
|
+
if (!hasWarned[msg]) {
|
|
138
|
+
hasWarned[msg] = true;
|
|
139
|
+
warn(msg);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
73
143
|
function escapeHtml(rawText) {
|
|
74
144
|
return rawText
|
|
75
145
|
.replace(/&/g, '&') // escape `&` first to avoid double escaping
|
|
@@ -82,16 +152,37 @@ function escapeHtml(rawText) {
|
|
|
82
152
|
}
|
|
83
153
|
function escapeAttributeValue(value) {
|
|
84
154
|
return value
|
|
85
|
-
.replace(/&(?![a-
|
|
155
|
+
.replace(/&(?![a-z0-9#]{2,6};)/gi, '&') // escape unescaped `&`
|
|
86
156
|
.replace(/"/g, '"')
|
|
87
157
|
.replace(/'/g, ''')
|
|
88
158
|
.replace(/</g, '<')
|
|
89
159
|
.replace(/>/g, '>');
|
|
90
160
|
}
|
|
91
|
-
const javascriptSchemePattern =
|
|
161
|
+
const javascriptSchemePattern = /^javascript:/i;
|
|
92
162
|
const urlAttributePattern = /^(?:href|src|action|formaction)$/i;
|
|
163
|
+
const numericCharacterReferencePattern = /&#(?:x([0-9a-f]+)|(\d+));?/gi;
|
|
164
|
+
const namedWhitespaceCharacterReferencePattern = /&(?:Tab|NewLine);/g;
|
|
165
|
+
const colonCharacterReferencePattern = /:?/gi;
|
|
166
|
+
// eslint-disable-next-line no-control-regex -- URL scheme normalization requires the full control range
|
|
167
|
+
const controlOrWhitespacePattern = /[\u0000-\u0020\u007f-\u009f]/g;
|
|
168
|
+
const eventHandlerPattern = /(?:^|[\s"'<>/])on\w+\s*=\s*["']?[^"'>]+["']?/i;
|
|
169
|
+
const eventHandlerAttributePattern = /(^|[\s"'<>/])on(\w+\s*=)/gi;
|
|
170
|
+
const unquotedUrlAttributePattern = /(^|[\s"'<>/])((?:href|src|action|formaction)\s*=\s*)([^\s"'=<>`]+)/gi;
|
|
171
|
+
function decodeNumericCharacterReference(match, hex, decimal) {
|
|
172
|
+
const digits = hex || decimal;
|
|
173
|
+
if (!digits) {
|
|
174
|
+
return match;
|
|
175
|
+
}
|
|
176
|
+
const codePoint = Number.parseInt(digits, hex ? 16 : 10);
|
|
177
|
+
return codePoint <= 0x7f ? String.fromCharCode(codePoint) : match;
|
|
178
|
+
}
|
|
93
179
|
function hasJavascriptScheme(value) {
|
|
94
|
-
|
|
180
|
+
const normalized = value
|
|
181
|
+
.replace(numericCharacterReferencePattern, decodeNumericCharacterReference)
|
|
182
|
+
.replace(namedWhitespaceCharacterReferencePattern, '')
|
|
183
|
+
.replace(colonCharacterReferencePattern, ':')
|
|
184
|
+
.replace(controlOrWhitespacePattern, '');
|
|
185
|
+
return javascriptSchemePattern.test(normalized);
|
|
95
186
|
}
|
|
96
187
|
function sanitizeStyleValue(value) {
|
|
97
188
|
const urlPattern = /url\s*\(/gi;
|
|
@@ -155,88 +246,18 @@ function sanitizeTranslatedHtml(html) {
|
|
|
155
246
|
// Process attributes with single quotes
|
|
156
247
|
html = html.replace(/([\w:-]+)\s*=\s*'([^']*)'/g, (_, attrName, attrValue) => `${attrName}='${sanitizeAttributeValue(attrName, attrValue)}'`);
|
|
157
248
|
// Detect and neutralize event handler attributes
|
|
158
|
-
const eventHandlerPattern = /\s*on\w+\s*=\s*["']?[^"'>]+["']?/gi;
|
|
159
249
|
if (eventHandlerPattern.test(html)) {
|
|
160
250
|
{
|
|
161
251
|
warn('Potentially dangerous event handlers detected in translation. ' +
|
|
162
252
|
'Consider removing onclick, onerror, etc. from your translation messages.');
|
|
163
253
|
}
|
|
164
254
|
// Neutralize event handler attributes by escaping 'on'
|
|
165
|
-
html = html.replace(
|
|
255
|
+
html = html.replace(eventHandlerAttributePattern, '$1on$2');
|
|
166
256
|
}
|
|
167
257
|
// Disable javascript: URLs in unquoted attributes
|
|
168
|
-
html = html.replace(
|
|
258
|
+
html = html.replace(unquotedUrlAttributePattern, (match, boundary, prefix, attrValue) => hasJavascriptScheme(attrValue) ? `${boundary}${prefix}about:blank` : match);
|
|
169
259
|
return html;
|
|
170
260
|
}
|
|
171
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
172
|
-
function hasOwn(obj, key) {
|
|
173
|
-
return hasOwnProperty.call(obj, key);
|
|
174
|
-
}
|
|
175
|
-
/* eslint-enable */
|
|
176
|
-
/**
|
|
177
|
-
* Useful Utilities By Evan you
|
|
178
|
-
* Modified by kazuya kawaguchi
|
|
179
|
-
* MIT License
|
|
180
|
-
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
|
|
181
|
-
* https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
|
|
182
|
-
*/
|
|
183
|
-
const isArray = Array.isArray;
|
|
184
|
-
const isFunction = (val) => typeof val === 'function';
|
|
185
|
-
const isString = (val) => typeof val === 'string';
|
|
186
|
-
const isBoolean = (val) => typeof val === 'boolean';
|
|
187
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
188
|
-
const isObject = (val) => val !== null && typeof val === 'object';
|
|
189
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
190
|
-
const isPromise = (val) => {
|
|
191
|
-
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
|
|
192
|
-
};
|
|
193
|
-
const objectToString = Object.prototype.toString;
|
|
194
|
-
const toTypeString = (value) => objectToString.call(value);
|
|
195
|
-
const isPlainObject = (val) => toTypeString(val) === '[object Object]';
|
|
196
|
-
// for converting list and named values to displayed strings.
|
|
197
|
-
const toDisplayString = (val) => {
|
|
198
|
-
return val == null
|
|
199
|
-
? ''
|
|
200
|
-
: isArray(val) || (isPlainObject(val) && val.toString === objectToString)
|
|
201
|
-
? JSON.stringify(val, null, 2)
|
|
202
|
-
: String(val);
|
|
203
|
-
};
|
|
204
|
-
function join(items, separator = '') {
|
|
205
|
-
return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
|
|
206
|
-
}
|
|
207
|
-
const RANGE = 2;
|
|
208
|
-
function generateCodeFrame(source, start = 0, end = source.length) {
|
|
209
|
-
const lines = source.split(/\r?\n/);
|
|
210
|
-
let count = 0;
|
|
211
|
-
const res = [];
|
|
212
|
-
for (let i = 0; i < lines.length; i++) {
|
|
213
|
-
count += lines[i].length + 1;
|
|
214
|
-
if (count >= start) {
|
|
215
|
-
for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
|
|
216
|
-
if (j < 0 || j >= lines.length)
|
|
217
|
-
continue;
|
|
218
|
-
const line = j + 1;
|
|
219
|
-
res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
|
|
220
|
-
const lineLength = lines[j].length;
|
|
221
|
-
if (j === i) {
|
|
222
|
-
// push underline
|
|
223
|
-
const pad = start - (count - lineLength) + 1;
|
|
224
|
-
const length = Math.max(1, end > count ? lineLength - pad : end - start);
|
|
225
|
-
res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
|
|
226
|
-
}
|
|
227
|
-
else if (j > i) {
|
|
228
|
-
if (end > count) {
|
|
229
|
-
const length = Math.max(Math.min(end - count, lineLength), 1);
|
|
230
|
-
res.push(` | ` + '^'.repeat(length));
|
|
231
|
-
}
|
|
232
|
-
count += lineLength + 1;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return res.join('\n');
|
|
239
|
-
}
|
|
240
261
|
|
|
241
262
|
const CompileErrorCodes = {
|
|
242
263
|
// tokenizer error codes
|
|
@@ -995,7 +1016,7 @@ function getWarnMessage(code, ...args) {
|
|
|
995
1016
|
* Intlify core-base version
|
|
996
1017
|
* @internal
|
|
997
1018
|
*/
|
|
998
|
-
const VERSION = '11.4.
|
|
1019
|
+
const VERSION = '11.4.8';
|
|
999
1020
|
const NOT_REOSLVED = -1;
|
|
1000
1021
|
const DEFAULT_LOCALE = 'en-US';
|
|
1001
1022
|
const MISSING_RESOLVE_VALUE = '';
|
|
@@ -1245,6 +1266,88 @@ function isImplicitFallback(targetLocale, locales) {
|
|
|
1245
1266
|
}
|
|
1246
1267
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
1247
1268
|
|
|
1269
|
+
function resolveFormatLocale(context, key, locale, formats, missingWarn, fallbackWarn, type) {
|
|
1270
|
+
const { fallbackLocale, localeFallbacker, onWarn } = context;
|
|
1271
|
+
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1272
|
+
fallbackLocale, locale);
|
|
1273
|
+
let from = locale;
|
|
1274
|
+
for (let i = 0; i < locales.length; i++) {
|
|
1275
|
+
const targetLocale = locales[i];
|
|
1276
|
+
if (locale !== targetLocale &&
|
|
1277
|
+
isTranslateFallbackWarn(fallbackWarn, key)) {
|
|
1278
|
+
onWarn(getWarnMessage(type === 'datetime format'
|
|
1279
|
+
? CoreWarnCodes.FALLBACK_TO_DATE_FORMAT
|
|
1280
|
+
: CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
|
|
1281
|
+
key,
|
|
1282
|
+
target: targetLocale
|
|
1283
|
+
}));
|
|
1284
|
+
}
|
|
1285
|
+
if (locale !== targetLocale) {
|
|
1286
|
+
const emitter = context.__v_emitter;
|
|
1287
|
+
if (emitter) {
|
|
1288
|
+
emitter.emit('fallback', {
|
|
1289
|
+
type,
|
|
1290
|
+
key,
|
|
1291
|
+
from,
|
|
1292
|
+
to: targetLocale,
|
|
1293
|
+
groupId: `${type}:${key}`
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
const format = (formats[targetLocale] || {})[key];
|
|
1298
|
+
if (isPlainObject(format) && isString(targetLocale)) {
|
|
1299
|
+
return targetLocale;
|
|
1300
|
+
}
|
|
1301
|
+
handleMissing(context, key, targetLocale, missingWarn, type);
|
|
1302
|
+
from = targetLocale;
|
|
1303
|
+
}
|
|
1304
|
+
return null;
|
|
1305
|
+
}
|
|
1306
|
+
function getFormatterCacheKey(locale, key, overrides) {
|
|
1307
|
+
let id = `${locale}__${key}`;
|
|
1308
|
+
if (isPlainObject(overrides) && !isEmptyObject(overrides)) {
|
|
1309
|
+
id = `${id}__${JSON.stringify(overrides)}`;
|
|
1310
|
+
}
|
|
1311
|
+
return id;
|
|
1312
|
+
}
|
|
1313
|
+
function clearFormatCache(formatters, locale, format) {
|
|
1314
|
+
for (const key in format) {
|
|
1315
|
+
const prefix = `${locale}__${key}`;
|
|
1316
|
+
for (const id of formatters.keys()) {
|
|
1317
|
+
if (id === prefix || id.startsWith(`${prefix}__`)) {
|
|
1318
|
+
formatters.delete(id);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
function parseFormatArgs(args, options, initialOverrides, optionsKeys) {
|
|
1324
|
+
const [, arg2, arg3, arg4] = args;
|
|
1325
|
+
let overrides = initialOverrides;
|
|
1326
|
+
if (isString(arg2)) {
|
|
1327
|
+
options.key = arg2;
|
|
1328
|
+
}
|
|
1329
|
+
else if (isPlainObject(arg2)) {
|
|
1330
|
+
Object.keys(arg2).forEach(key => {
|
|
1331
|
+
if (optionsKeys.includes(key)) {
|
|
1332
|
+
overrides[key] = arg2[key];
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
options[key] = arg2[key];
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
if (isString(arg3)) {
|
|
1340
|
+
options.locale = arg3;
|
|
1341
|
+
}
|
|
1342
|
+
else if (isPlainObject(arg3)) {
|
|
1343
|
+
overrides = arg3;
|
|
1344
|
+
}
|
|
1345
|
+
if (isPlainObject(arg4)) {
|
|
1346
|
+
overrides = arg4;
|
|
1347
|
+
}
|
|
1348
|
+
return overrides;
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1248
1351
|
const intlDefined = typeof Intl !== 'undefined';
|
|
1249
1352
|
const Availabilities = {
|
|
1250
1353
|
dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
|
|
@@ -1253,7 +1356,7 @@ const Availabilities = {
|
|
|
1253
1356
|
|
|
1254
1357
|
// implementation of `datetime` function
|
|
1255
1358
|
function datetime(context, ...args) {
|
|
1256
|
-
const { datetimeFormats, unresolving,
|
|
1359
|
+
const { datetimeFormats, unresolving, onWarn } = context;
|
|
1257
1360
|
const { __datetimeFormatters } = context;
|
|
1258
1361
|
if (!Availabilities.dateTimeFormat) {
|
|
1259
1362
|
onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
|
|
@@ -1276,57 +1379,16 @@ function datetime(context, ...args) {
|
|
|
1276
1379
|
: context.fallbackWarn;
|
|
1277
1380
|
const part = !!options.part;
|
|
1278
1381
|
const locale = getLocale(context, options);
|
|
1279
|
-
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1280
|
-
fallbackLocale, locale);
|
|
1281
1382
|
if (!isString(key) || key === '') {
|
|
1282
1383
|
const formatter = new Intl.DateTimeFormat(locale.replace(/!/g, ''), overrides);
|
|
1283
1384
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1284
1385
|
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
let targetLocale;
|
|
1288
|
-
let format = null;
|
|
1289
|
-
let from = locale;
|
|
1290
|
-
let to = null;
|
|
1291
|
-
const type = 'datetime format';
|
|
1292
|
-
for (let i = 0; i < locales.length; i++) {
|
|
1293
|
-
targetLocale = to = locales[i];
|
|
1294
|
-
if (locale !== targetLocale &&
|
|
1295
|
-
isTranslateFallbackWarn(fallbackWarn, key)) {
|
|
1296
|
-
onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
|
|
1297
|
-
key,
|
|
1298
|
-
target: targetLocale
|
|
1299
|
-
}));
|
|
1300
|
-
}
|
|
1301
|
-
// for vue-devtools timeline event
|
|
1302
|
-
if (locale !== targetLocale) {
|
|
1303
|
-
const emitter = context.__v_emitter;
|
|
1304
|
-
if (emitter) {
|
|
1305
|
-
emitter.emit('fallback', {
|
|
1306
|
-
type,
|
|
1307
|
-
key,
|
|
1308
|
-
from,
|
|
1309
|
-
to,
|
|
1310
|
-
groupId: `${type}:${key}`
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
datetimeFormat =
|
|
1315
|
-
datetimeFormats[targetLocale] || {};
|
|
1316
|
-
format = datetimeFormat[key];
|
|
1317
|
-
if (isPlainObject(format))
|
|
1318
|
-
break;
|
|
1319
|
-
handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1320
|
-
from = to;
|
|
1321
|
-
}
|
|
1322
|
-
// checking format and target locale
|
|
1323
|
-
if (!isPlainObject(format) || !isString(targetLocale)) {
|
|
1386
|
+
const targetLocale = resolveFormatLocale(context, key, locale, datetimeFormats, missingWarn, fallbackWarn, 'datetime format');
|
|
1387
|
+
if (!isString(targetLocale)) {
|
|
1324
1388
|
return unresolving ? NOT_REOSLVED : key;
|
|
1325
1389
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
id = `${id}__${JSON.stringify(overrides)}`;
|
|
1329
|
-
}
|
|
1390
|
+
const format = datetimeFormats[targetLocale][key];
|
|
1391
|
+
const id = getFormatterCacheKey(targetLocale, key, overrides);
|
|
1330
1392
|
let formatter = __datetimeFormatters.get(id);
|
|
1331
1393
|
if (!formatter) {
|
|
1332
1394
|
formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
|
|
@@ -1359,9 +1421,9 @@ const DATETIME_FORMAT_OPTIONS_KEYS = [
|
|
|
1359
1421
|
];
|
|
1360
1422
|
/** @internal */
|
|
1361
1423
|
function parseDateTimeArgs(...args) {
|
|
1362
|
-
const [arg1
|
|
1424
|
+
const [arg1] = args;
|
|
1363
1425
|
const options = create();
|
|
1364
|
-
|
|
1426
|
+
const initialOverrides = create();
|
|
1365
1427
|
let value;
|
|
1366
1428
|
if (isString(arg1)) {
|
|
1367
1429
|
// Only allow ISO strings - other date formats are often supported,
|
|
@@ -1398,45 +1460,18 @@ function parseDateTimeArgs(...args) {
|
|
|
1398
1460
|
else {
|
|
1399
1461
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
1400
1462
|
}
|
|
1401
|
-
|
|
1402
|
-
options.key = arg2;
|
|
1403
|
-
}
|
|
1404
|
-
else if (isPlainObject(arg2)) {
|
|
1405
|
-
Object.keys(arg2).forEach(key => {
|
|
1406
|
-
if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1407
|
-
overrides[key] = arg2[key];
|
|
1408
|
-
}
|
|
1409
|
-
else {
|
|
1410
|
-
options[key] = arg2[key];
|
|
1411
|
-
}
|
|
1412
|
-
});
|
|
1413
|
-
}
|
|
1414
|
-
if (isString(arg3)) {
|
|
1415
|
-
options.locale = arg3;
|
|
1416
|
-
}
|
|
1417
|
-
else if (isPlainObject(arg3)) {
|
|
1418
|
-
overrides = arg3;
|
|
1419
|
-
}
|
|
1420
|
-
if (isPlainObject(arg4)) {
|
|
1421
|
-
overrides = arg4;
|
|
1422
|
-
}
|
|
1463
|
+
const overrides = parseFormatArgs(args, options, initialOverrides, DATETIME_FORMAT_OPTIONS_KEYS);
|
|
1423
1464
|
return [options.key || '', value, options, overrides];
|
|
1424
1465
|
}
|
|
1425
1466
|
/** @internal */
|
|
1426
1467
|
function clearDateTimeFormat(ctx, locale, format) {
|
|
1427
1468
|
const context = ctx;
|
|
1428
|
-
|
|
1429
|
-
const id = `${locale}__${key}`;
|
|
1430
|
-
if (!context.__datetimeFormatters.has(id)) {
|
|
1431
|
-
continue;
|
|
1432
|
-
}
|
|
1433
|
-
context.__datetimeFormatters.delete(id);
|
|
1434
|
-
}
|
|
1469
|
+
clearFormatCache(context.__datetimeFormatters, locale, format);
|
|
1435
1470
|
}
|
|
1436
1471
|
|
|
1437
1472
|
// implementation of `number` function
|
|
1438
1473
|
function number(context, ...args) {
|
|
1439
|
-
const { numberFormats, unresolving,
|
|
1474
|
+
const { numberFormats, unresolving, onWarn } = context;
|
|
1440
1475
|
const { __numberFormatters } = context;
|
|
1441
1476
|
if (!Availabilities.numberFormat) {
|
|
1442
1477
|
onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
|
|
@@ -1459,57 +1494,16 @@ function number(context, ...args) {
|
|
|
1459
1494
|
: context.fallbackWarn;
|
|
1460
1495
|
const part = !!options.part;
|
|
1461
1496
|
const locale = getLocale(context, options);
|
|
1462
|
-
const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1463
|
-
fallbackLocale, locale);
|
|
1464
1497
|
if (!isString(key) || key === '') {
|
|
1465
1498
|
const formatter = new Intl.NumberFormat(locale.replace(/!/g, ''), overrides);
|
|
1466
1499
|
return !part ? formatter.format(value) : formatter.formatToParts(value);
|
|
1467
1500
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
let targetLocale;
|
|
1471
|
-
let format = null;
|
|
1472
|
-
let from = locale;
|
|
1473
|
-
let to = null;
|
|
1474
|
-
const type = 'number format';
|
|
1475
|
-
for (let i = 0; i < locales.length; i++) {
|
|
1476
|
-
targetLocale = to = locales[i];
|
|
1477
|
-
if (locale !== targetLocale &&
|
|
1478
|
-
isTranslateFallbackWarn(fallbackWarn, key)) {
|
|
1479
|
-
onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
|
|
1480
|
-
key,
|
|
1481
|
-
target: targetLocale
|
|
1482
|
-
}));
|
|
1483
|
-
}
|
|
1484
|
-
// for vue-devtools timeline event
|
|
1485
|
-
if (locale !== targetLocale) {
|
|
1486
|
-
const emitter = context.__v_emitter;
|
|
1487
|
-
if (emitter) {
|
|
1488
|
-
emitter.emit('fallback', {
|
|
1489
|
-
type,
|
|
1490
|
-
key,
|
|
1491
|
-
from,
|
|
1492
|
-
to,
|
|
1493
|
-
groupId: `${type}:${key}`
|
|
1494
|
-
});
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
numberFormat =
|
|
1498
|
-
numberFormats[targetLocale] || {};
|
|
1499
|
-
format = numberFormat[key];
|
|
1500
|
-
if (isPlainObject(format))
|
|
1501
|
-
break;
|
|
1502
|
-
handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
1503
|
-
from = to;
|
|
1504
|
-
}
|
|
1505
|
-
// checking format and target locale
|
|
1506
|
-
if (!isPlainObject(format) || !isString(targetLocale)) {
|
|
1501
|
+
const targetLocale = resolveFormatLocale(context, key, locale, numberFormats, missingWarn, fallbackWarn, 'number format');
|
|
1502
|
+
if (!isString(targetLocale)) {
|
|
1507
1503
|
return unresolving ? NOT_REOSLVED : key;
|
|
1508
1504
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
id = `${id}__${JSON.stringify(overrides)}`;
|
|
1512
|
-
}
|
|
1505
|
+
const format = numberFormats[targetLocale][key];
|
|
1506
|
+
const id = getFormatterCacheKey(targetLocale, key, overrides);
|
|
1513
1507
|
let formatter = __numberFormatters.get(id);
|
|
1514
1508
|
if (!formatter) {
|
|
1515
1509
|
formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
|
|
@@ -1542,47 +1536,20 @@ const NUMBER_FORMAT_OPTIONS_KEYS = [
|
|
|
1542
1536
|
];
|
|
1543
1537
|
/** @internal */
|
|
1544
1538
|
function parseNumberArgs(...args) {
|
|
1545
|
-
const [arg1
|
|
1539
|
+
const [arg1] = args;
|
|
1546
1540
|
const options = create();
|
|
1547
|
-
|
|
1541
|
+
const initialOverrides = create();
|
|
1548
1542
|
if (!isNumber(arg1)) {
|
|
1549
1543
|
throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
|
|
1550
1544
|
}
|
|
1551
1545
|
const value = arg1;
|
|
1552
|
-
|
|
1553
|
-
options.key = arg2;
|
|
1554
|
-
}
|
|
1555
|
-
else if (isPlainObject(arg2)) {
|
|
1556
|
-
Object.keys(arg2).forEach(key => {
|
|
1557
|
-
if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
|
|
1558
|
-
overrides[key] = arg2[key];
|
|
1559
|
-
}
|
|
1560
|
-
else {
|
|
1561
|
-
options[key] = arg2[key];
|
|
1562
|
-
}
|
|
1563
|
-
});
|
|
1564
|
-
}
|
|
1565
|
-
if (isString(arg3)) {
|
|
1566
|
-
options.locale = arg3;
|
|
1567
|
-
}
|
|
1568
|
-
else if (isPlainObject(arg3)) {
|
|
1569
|
-
overrides = arg3;
|
|
1570
|
-
}
|
|
1571
|
-
if (isPlainObject(arg4)) {
|
|
1572
|
-
overrides = arg4;
|
|
1573
|
-
}
|
|
1546
|
+
const overrides = parseFormatArgs(args, options, initialOverrides, NUMBER_FORMAT_OPTIONS_KEYS);
|
|
1574
1547
|
return [options.key || '', value, options, overrides];
|
|
1575
1548
|
}
|
|
1576
1549
|
/** @internal */
|
|
1577
1550
|
function clearNumberFormat(ctx, locale, format) {
|
|
1578
1551
|
const context = ctx;
|
|
1579
|
-
|
|
1580
|
-
const id = `${locale}__${key}`;
|
|
1581
|
-
if (!context.__numberFormatters.has(id)) {
|
|
1582
|
-
continue;
|
|
1583
|
-
}
|
|
1584
|
-
context.__numberFormatters.delete(id);
|
|
1585
|
-
}
|
|
1552
|
+
clearFormatCache(context.__numberFormatters, locale, format);
|
|
1586
1553
|
}
|
|
1587
1554
|
|
|
1588
1555
|
const DEFAULT_MODIFIER = (str) => str;
|