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