@intlify/core 9.3.0-beta.9 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1709 +1,1850 @@
1
1
  /*!
2
- * core v9.3.0-beta.9
3
- * (c) 2022 kazuya kawaguchi
2
+ * core v9.3.0
3
+ * (c) 2023 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
6
6
  var IntlifyCore = (function (exports) {
7
7
  'use strict';
8
8
 
9
- /**
10
- * Original Utilities
11
- * written by kazuya kawaguchi
12
- */
13
- const inBrowser = typeof window !== 'undefined';
14
- let mark;
15
- let measure;
16
- {
17
- const perf = inBrowser && window.performance;
18
- if (perf &&
19
- perf.mark &&
20
- perf.measure &&
21
- perf.clearMarks &&
22
- perf.clearMeasures) {
23
- mark = (tag) => perf.mark(tag);
24
- measure = (name, startTag, endTag) => {
25
- perf.measure(name, startTag, endTag);
26
- perf.clearMarks(startTag);
27
- perf.clearMarks(endTag);
28
- };
29
- }
30
- }
31
- const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
32
- /* eslint-disable */
33
- function format(message, ...args) {
34
- if (args.length === 1 && isObject(args[0])) {
35
- args = args[0];
36
- }
37
- if (!args || !args.hasOwnProperty) {
38
- args = {};
39
- }
40
- return message.replace(RE_ARGS, (match, identifier) => {
41
- return args.hasOwnProperty(identifier) ? args[identifier] : '';
42
- });
43
- }
44
- const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
45
- const friendlyJSONstringify = (json) => JSON.stringify(json)
46
- .replace(/\u2028/g, '\\u2028')
47
- .replace(/\u2029/g, '\\u2029')
48
- .replace(/\u0027/g, '\\u0027');
49
- const isNumber = (val) => typeof val === 'number' && isFinite(val);
50
- const isDate = (val) => toTypeString(val) === '[object Date]';
51
- const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
52
- const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
53
- function warn(msg, err) {
54
- if (typeof console !== 'undefined') {
55
- console.warn(`[intlify] ` + msg);
56
- /* istanbul ignore if */
57
- if (err) {
58
- console.warn(err.stack);
59
- }
60
- }
61
- }
62
- const assign = Object.assign;
63
- function escapeHtml(rawText) {
64
- return rawText
65
- .replace(/</g, '&lt;')
66
- .replace(/>/g, '&gt;')
67
- .replace(/"/g, '&quot;')
68
- .replace(/'/g, '&apos;');
69
- }
70
- /* eslint-enable */
71
- /**
72
- * Useful Utilities By Evan you
73
- * Modified by kazuya kawaguchi
74
- * MIT License
75
- * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
76
- * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
77
- */
78
- const isArray = Array.isArray;
79
- const isFunction = (val) => typeof val === 'function';
80
- const isString = (val) => typeof val === 'string';
81
- const isBoolean = (val) => typeof val === 'boolean';
82
- const isObject = (val) => // eslint-disable-line
83
- val !== null && typeof val === 'object';
84
- const objectToString = Object.prototype.toString;
85
- const toTypeString = (value) => objectToString.call(value);
86
- const isPlainObject = (val) => toTypeString(val) === '[object Object]';
87
- // for converting list and named values to displayed strings.
88
- const toDisplayString = (val) => {
89
- return val == null
90
- ? ''
91
- : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
92
- ? JSON.stringify(val, null, 2)
93
- : String(val);
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');
9
+ /**
10
+ * Original Utilities
11
+ * written by kazuya kawaguchi
12
+ */
13
+ const inBrowser = typeof window !== 'undefined';
14
+ let mark;
15
+ let measure;
16
+ {
17
+ const perf = inBrowser && window.performance;
18
+ if (perf &&
19
+ perf.mark &&
20
+ perf.measure &&
21
+ perf.clearMarks &&
22
+ // @ts-ignore browser compat
23
+ perf.clearMeasures) {
24
+ mark = (tag) => {
25
+ perf.mark(tag);
26
+ };
27
+ measure = (name, startTag, endTag) => {
28
+ perf.measure(name, startTag, endTag);
29
+ perf.clearMarks(startTag);
30
+ perf.clearMarks(endTag);
31
+ };
32
+ }
33
+ }
34
+ const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
35
+ /* eslint-disable */
36
+ function format$1(message, ...args) {
37
+ if (args.length === 1 && isObject(args[0])) {
38
+ args = args[0];
39
+ }
40
+ if (!args || !args.hasOwnProperty) {
41
+ args = {};
42
+ }
43
+ return message.replace(RE_ARGS, (match, identifier) => {
44
+ return args.hasOwnProperty(identifier) ? args[identifier] : '';
45
+ });
46
+ }
47
+ const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
48
+ const friendlyJSONstringify = (json) => JSON.stringify(json)
49
+ .replace(/\u2028/g, '\\u2028')
50
+ .replace(/\u2029/g, '\\u2029')
51
+ .replace(/\u0027/g, '\\u0027');
52
+ const isNumber = (val) => typeof val === 'number' && isFinite(val);
53
+ const isDate = (val) => toTypeString(val) === '[object Date]';
54
+ const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
55
+ const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
56
+ const assign = Object.assign;
57
+ function escapeHtml(rawText) {
58
+ return rawText
59
+ .replace(/</g, '&lt;')
60
+ .replace(/>/g, '&gt;')
61
+ .replace(/"/g, '&quot;')
62
+ .replace(/'/g, '&apos;');
63
+ }
64
+ /* eslint-enable */
65
+ /**
66
+ * Useful Utilities By Evan you
67
+ * Modified by kazuya kawaguchi
68
+ * MIT License
69
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
70
+ * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
71
+ */
72
+ const isArray = Array.isArray;
73
+ const isFunction = (val) => typeof val === 'function';
74
+ const isString = (val) => typeof val === 'string';
75
+ const isBoolean = (val) => typeof val === 'boolean';
76
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
+ const isObject = (val) => val !== null && typeof val === 'object';
78
+ const objectToString = Object.prototype.toString;
79
+ const toTypeString = (value) => objectToString.call(value);
80
+ const isPlainObject = (val) => {
81
+ if (!isObject(val))
82
+ return false;
83
+ const proto = Object.getPrototypeOf(val);
84
+ return proto === null || proto.constructor === Object;
85
+ };
86
+ // for converting list and named values to displayed strings.
87
+ const toDisplayString = (val) => {
88
+ return val == null
89
+ ? ''
90
+ : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
91
+ ? JSON.stringify(val, null, 2)
92
+ : String(val);
93
+ };
94
+ function join(items, separator = '') {
95
+ return items.reduce((str, item, index) => (index === 0 ? str + item : str + separator + item), '');
96
+ }
97
+ const RANGE = 2;
98
+ function generateCodeFrame(source, start = 0, end = source.length) {
99
+ const lines = source.split(/\r?\n/);
100
+ let count = 0;
101
+ const res = [];
102
+ for (let i = 0; i < lines.length; i++) {
103
+ count += lines[i].length + 1;
104
+ if (count >= start) {
105
+ for (let j = i - RANGE; j <= i + RANGE || end > count; j++) {
106
+ if (j < 0 || j >= lines.length)
107
+ continue;
108
+ const line = j + 1;
109
+ res.push(`${line}${' '.repeat(3 - String(line).length)}| ${lines[j]}`);
110
+ const lineLength = lines[j].length;
111
+ if (j === i) {
112
+ // push underline
113
+ const pad = start - (count - lineLength) + 1;
114
+ const length = Math.max(1, end > count ? lineLength - pad : end - start);
115
+ res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
116
+ }
117
+ else if (j > i) {
118
+ if (end > count) {
119
+ const length = Math.max(Math.min(end - count, lineLength), 1);
120
+ res.push(` | ` + '^'.repeat(length));
121
+ }
122
+ count += lineLength + 1;
123
+ }
124
+ }
125
+ break;
126
+ }
127
+ }
128
+ return res.join('\n');
129
+ }
130
+ function incrementer(code) {
131
+ let current = code;
132
+ return () => ++current;
127
133
  }
128
134
 
129
- const CompileErrorCodes = {
130
- // tokenizer error codes
131
- EXPECTED_TOKEN: 1,
132
- INVALID_TOKEN_IN_PLACEHOLDER: 2,
133
- UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
134
- UNKNOWN_ESCAPE_SEQUENCE: 4,
135
- INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
136
- UNBALANCED_CLOSING_BRACE: 6,
137
- UNTERMINATED_CLOSING_BRACE: 7,
138
- EMPTY_PLACEHOLDER: 8,
139
- NOT_ALLOW_NEST_PLACEHOLDER: 9,
140
- INVALID_LINKED_FORMAT: 10,
141
- // parser error codes
142
- MUST_HAVE_MESSAGES_IN_PLURAL: 11,
143
- UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
144
- UNEXPECTED_EMPTY_LINKED_KEY: 13,
145
- UNEXPECTED_LEXICAL_ANALYSIS: 14,
146
- // Special value for higher-order compilers to pick up the last code
147
- // to avoid collision of error codes. This should always be kept as the last
148
- // item.
149
- __EXTEND_POINT__: 15
150
- };
151
- /** @internal */
152
- const errorMessages$1 = {
153
- // tokenizer error messages
154
- [CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
155
- [CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
156
- [CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
157
- [CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
158
- [CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
159
- [CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
160
- [CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
161
- [CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
162
- [CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
163
- [CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
164
- // parser error messages
165
- [CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
166
- [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
167
- [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
168
- [CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`
169
- };
170
- function createCompileError(code, loc, options = {}) {
171
- const { domain, messages, args } = options;
172
- const msg = format((messages || errorMessages$1)[code] || '', ...(args || []))
173
- ;
174
- const error = new SyntaxError(String(msg));
175
- error.code = code;
176
- if (loc) {
177
- error.location = loc;
178
- }
179
- error.domain = domain;
180
- return error;
135
+ function warn(msg, err) {
136
+ if (typeof console !== 'undefined') {
137
+ console.warn(`[intlify] ` + msg);
138
+ /* istanbul ignore if */
139
+ if (err) {
140
+ console.warn(err.stack);
141
+ }
142
+ }
181
143
  }
182
144
 
183
- const pathStateMachine = [];
184
- pathStateMachine[0 /* BEFORE_PATH */] = {
185
- ["w" /* WORKSPACE */]: [0 /* BEFORE_PATH */],
186
- ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
187
- ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
188
- ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
189
- };
190
- pathStateMachine[1 /* IN_PATH */] = {
191
- ["w" /* WORKSPACE */]: [1 /* IN_PATH */],
192
- ["." /* DOT */]: [2 /* BEFORE_IDENT */],
193
- ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
194
- ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
195
- };
196
- pathStateMachine[2 /* BEFORE_IDENT */] = {
197
- ["w" /* WORKSPACE */]: [2 /* BEFORE_IDENT */],
198
- ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
199
- ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */]
200
- };
201
- pathStateMachine[3 /* IN_IDENT */] = {
202
- ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
203
- ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */],
204
- ["w" /* WORKSPACE */]: [1 /* IN_PATH */, 1 /* PUSH */],
205
- ["." /* DOT */]: [2 /* BEFORE_IDENT */, 1 /* PUSH */],
206
- ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */, 1 /* PUSH */],
207
- ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */, 1 /* PUSH */]
208
- };
209
- pathStateMachine[4 /* IN_SUB_PATH */] = {
210
- ["'" /* SINGLE_QUOTE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */],
211
- ["\"" /* DOUBLE_QUOTE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */],
212
- ["[" /* LEFT_BRACKET */]: [
213
- 4 /* IN_SUB_PATH */,
214
- 2 /* INC_SUB_PATH_DEPTH */
215
- ],
216
- ["]" /* RIGHT_BRACKET */]: [1 /* IN_PATH */, 3 /* PUSH_SUB_PATH */],
217
- ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
218
- ["l" /* ELSE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */]
219
- };
220
- pathStateMachine[5 /* IN_SINGLE_QUOTE */] = {
221
- ["'" /* SINGLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
222
- ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
223
- ["l" /* ELSE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */]
224
- };
225
- pathStateMachine[6 /* IN_DOUBLE_QUOTE */] = {
226
- ["\"" /* DOUBLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
227
- ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
228
- ["l" /* ELSE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */]
229
- };
230
- /**
231
- * Check if an expression is a literal value.
232
- */
233
- const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
234
- function isLiteral(exp) {
235
- return literalValueRE.test(exp);
236
- }
237
- /**
238
- * Strip quotes from a string
239
- */
240
- function stripQuotes(str) {
241
- const a = str.charCodeAt(0);
242
- const b = str.charCodeAt(str.length - 1);
243
- return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
244
- }
245
- /**
246
- * Determine the type of a character in a keypath.
247
- */
248
- function getPathCharType(ch) {
249
- if (ch === undefined || ch === null) {
250
- return "o" /* END_OF_FAIL */;
251
- }
252
- const code = ch.charCodeAt(0);
253
- switch (code) {
254
- case 0x5b: // [
255
- case 0x5d: // ]
256
- case 0x2e: // .
257
- case 0x22: // "
258
- case 0x27: // '
259
- return ch;
260
- case 0x5f: // _
261
- case 0x24: // $
262
- case 0x2d: // -
263
- return "i" /* IDENT */;
264
- case 0x09: // Tab (HT)
265
- case 0x0a: // Newline (LF)
266
- case 0x0d: // Return (CR)
267
- case 0xa0: // No-break space (NBSP)
268
- case 0xfeff: // Byte Order Mark (BOM)
269
- case 0x2028: // Line Separator (LS)
270
- case 0x2029: // Paragraph Separator (PS)
271
- return "w" /* WORKSPACE */;
272
- }
273
- return "i" /* IDENT */;
274
- }
275
- /**
276
- * Format a subPath, return its plain form if it is
277
- * a literal string or number. Otherwise prepend the
278
- * dynamic indicator (*).
279
- */
280
- function formatSubPath(path) {
281
- const trimmed = path.trim();
282
- // invalid leading 0
283
- if (path.charAt(0) === '0' && isNaN(parseInt(path))) {
284
- return false;
285
- }
286
- return isLiteral(trimmed)
287
- ? stripQuotes(trimmed)
288
- : "*" /* ASTARISK */ + trimmed;
289
- }
290
- /**
291
- * Parse a string path into an array of segments
292
- */
293
- function parse(path) {
294
- const keys = [];
295
- let index = -1;
296
- let mode = 0 /* BEFORE_PATH */;
297
- let subPathDepth = 0;
298
- let c;
299
- let key; // eslint-disable-line
300
- let newChar;
301
- let type;
302
- let transition;
303
- let action;
304
- let typeMap;
305
- const actions = [];
306
- actions[0 /* APPEND */] = () => {
307
- if (key === undefined) {
308
- key = newChar;
309
- }
310
- else {
311
- key += newChar;
312
- }
313
- };
314
- actions[1 /* PUSH */] = () => {
315
- if (key !== undefined) {
316
- keys.push(key);
317
- key = undefined;
318
- }
319
- };
320
- actions[2 /* INC_SUB_PATH_DEPTH */] = () => {
321
- actions[0 /* APPEND */]();
322
- subPathDepth++;
323
- };
324
- actions[3 /* PUSH_SUB_PATH */] = () => {
325
- if (subPathDepth > 0) {
326
- subPathDepth--;
327
- mode = 4 /* IN_SUB_PATH */;
328
- actions[0 /* APPEND */]();
329
- }
330
- else {
331
- subPathDepth = 0;
332
- if (key === undefined) {
333
- return false;
334
- }
335
- key = formatSubPath(key);
336
- if (key === false) {
337
- return false;
338
- }
339
- else {
340
- actions[1 /* PUSH */]();
341
- }
342
- }
343
- };
344
- function maybeUnescapeQuote() {
345
- const nextChar = path[index + 1];
346
- if ((mode === 5 /* IN_SINGLE_QUOTE */ &&
347
- nextChar === "'" /* SINGLE_QUOTE */) ||
348
- (mode === 6 /* IN_DOUBLE_QUOTE */ &&
349
- nextChar === "\"" /* DOUBLE_QUOTE */)) {
350
- index++;
351
- newChar = '\\' + nextChar;
352
- actions[0 /* APPEND */]();
353
- return true;
354
- }
355
- }
356
- while (mode !== null) {
357
- index++;
358
- c = path[index];
359
- if (c === '\\' && maybeUnescapeQuote()) {
360
- continue;
361
- }
362
- type = getPathCharType(c);
363
- typeMap = pathStateMachine[mode];
364
- transition = typeMap[type] || typeMap["l" /* ELSE */] || 8 /* ERROR */;
365
- // check parse error
366
- if (transition === 8 /* ERROR */) {
367
- return;
368
- }
369
- mode = transition[0];
370
- if (transition[1] !== undefined) {
371
- action = actions[transition[1]];
372
- if (action) {
373
- newChar = c;
374
- if (action() === false) {
375
- return;
376
- }
377
- }
378
- }
379
- // check parse finish
380
- if (mode === 7 /* AFTER_PATH */) {
381
- return keys;
382
- }
383
- }
384
- }
385
- // path token cache
386
- const cache = new Map();
387
- /**
388
- * key-value message resolver
389
- *
390
- * @remarks
391
- * Resolves messages with the key-value structure. Note that messages with a hierarchical structure such as objects cannot be resolved
392
- *
393
- * @param obj - A target object to be resolved with path
394
- * @param path - A {@link Path | path} to resolve the value of message
395
- *
396
- * @returns A resolved {@link PathValue | path value}
397
- *
398
- * @VueI18nGeneral
399
- */
400
- function resolveWithKeyValue(obj, path) {
401
- return isObject(obj) ? obj[path] : null;
402
- }
403
- /**
404
- * message resolver
405
- *
406
- * @remarks
407
- * Resolves messages. messages with a hierarchical structure such as objects can be resolved. This resolver is used in VueI18n as default.
408
- *
409
- * @param obj - A target object to be resolved with path
410
- * @param path - A {@link Path | path} to resolve the value of message
411
- *
412
- * @returns A resolved {@link PathValue | path value}
413
- *
414
- * @VueI18nGeneral
415
- */
416
- function resolveValue(obj, path) {
417
- // check object
418
- if (!isObject(obj)) {
419
- return null;
420
- }
421
- // parse path
422
- let hit = cache.get(path);
423
- if (!hit) {
424
- hit = parse(path);
425
- if (hit) {
426
- cache.set(path, hit);
427
- }
428
- }
429
- // check hit
430
- if (!hit) {
431
- return null;
432
- }
433
- // resolve path value
434
- const len = hit.length;
435
- let last = obj;
436
- let i = 0;
437
- while (i < len) {
438
- const val = last[hit[i]];
439
- if (val === undefined) {
440
- return null;
441
- }
442
- last = val;
443
- i++;
444
- }
445
- return last;
145
+ const CompileErrorCodes = {
146
+ // tokenizer error codes
147
+ EXPECTED_TOKEN: 1,
148
+ INVALID_TOKEN_IN_PLACEHOLDER: 2,
149
+ UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
150
+ UNKNOWN_ESCAPE_SEQUENCE: 4,
151
+ INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
152
+ UNBALANCED_CLOSING_BRACE: 6,
153
+ UNTERMINATED_CLOSING_BRACE: 7,
154
+ EMPTY_PLACEHOLDER: 8,
155
+ NOT_ALLOW_NEST_PLACEHOLDER: 9,
156
+ INVALID_LINKED_FORMAT: 10,
157
+ // parser error codes
158
+ MUST_HAVE_MESSAGES_IN_PLURAL: 11,
159
+ UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
160
+ UNEXPECTED_EMPTY_LINKED_KEY: 13,
161
+ UNEXPECTED_LEXICAL_ANALYSIS: 14,
162
+ // generator error codes
163
+ UNHANDLED_CODEGEN_NODE_TYPE: 15,
164
+ // minifier error codes
165
+ UNHANDLED_MINIFIER_NODE_TYPE: 16,
166
+ // Special value for higher-order compilers to pick up the last code
167
+ // to avoid collision of error codes. This should always be kept as the last
168
+ // item.
169
+ __EXTEND_POINT__: 17
170
+ };
171
+ /** @internal */
172
+ const errorMessages$1 = {
173
+ // tokenizer error messages
174
+ [CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
175
+ [CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
176
+ [CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
177
+ [CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
178
+ [CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
179
+ [CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
180
+ [CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
181
+ [CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
182
+ [CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
183
+ [CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
184
+ // parser error messages
185
+ [CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
186
+ [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
187
+ [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
188
+ [CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`,
189
+ // generator error messages
190
+ [CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE]: `unhandled codegen node type: '{0}'`,
191
+ // minimizer error messages
192
+ [CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE]: `unhandled mimifier node type: '{0}'`
193
+ };
194
+ function createCompileError(code, loc, options = {}) {
195
+ const { domain, messages, args } = options;
196
+ const msg = format$1((messages || errorMessages$1)[code] || '', ...(args || []))
197
+ ;
198
+ const error = new SyntaxError(String(msg));
199
+ error.code = code;
200
+ if (loc) {
201
+ error.location = loc;
202
+ }
203
+ error.domain = domain;
204
+ return error;
446
205
  }
447
206
 
448
- const DEFAULT_MODIFIER = (str) => str;
449
- const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
450
- const DEFAULT_MESSAGE_DATA_TYPE = 'text';
451
- const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
452
- const DEFAULT_INTERPOLATE = toDisplayString;
453
- function pluralDefault(choice, choicesLength) {
454
- choice = Math.abs(choice);
455
- if (choicesLength === 2) {
456
- // prettier-ignore
457
- return choice
458
- ? choice > 1
459
- ? 1
460
- : 0
461
- : 1;
462
- }
463
- return choice ? Math.min(choice, 2) : 0;
464
- }
465
- function getPluralIndex(options) {
466
- // prettier-ignore
467
- const index = isNumber(options.pluralIndex)
468
- ? options.pluralIndex
469
- : -1;
470
- // prettier-ignore
471
- return options.named && (isNumber(options.named.count) || isNumber(options.named.n))
472
- ? isNumber(options.named.count)
473
- ? options.named.count
474
- : isNumber(options.named.n)
475
- ? options.named.n
476
- : index
477
- : index;
478
- }
479
- function normalizeNamed(pluralIndex, props) {
480
- if (!props.count) {
481
- props.count = pluralIndex;
482
- }
483
- if (!props.n) {
484
- props.n = pluralIndex;
485
- }
486
- }
487
- function createMessageContext(options = {}) {
488
- const locale = options.locale;
489
- const pluralIndex = getPluralIndex(options);
490
- const pluralRule = isObject(options.pluralRules) &&
491
- isString(locale) &&
492
- isFunction(options.pluralRules[locale])
493
- ? options.pluralRules[locale]
494
- : pluralDefault;
495
- const orgPluralRule = isObject(options.pluralRules) &&
496
- isString(locale) &&
497
- isFunction(options.pluralRules[locale])
498
- ? pluralDefault
499
- : undefined;
500
- const plural = (messages) => {
501
- return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
502
- };
503
- const _list = options.list || [];
504
- const list = (index) => _list[index];
505
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
506
- const _named = options.named || {};
507
- isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
508
- const named = (key) => _named[key];
509
- function message(key) {
510
- // prettier-ignore
511
- const msg = isFunction(options.messages)
512
- ? options.messages(key)
513
- : isObject(options.messages)
514
- ? options.messages[key]
515
- : false;
516
- return !msg
517
- ? options.parent
518
- ? options.parent.message(key) // resolve from parent messages
519
- : DEFAULT_MESSAGE
520
- : msg;
521
- }
522
- const _modifier = (name) => options.modifiers
523
- ? options.modifiers[name]
524
- : DEFAULT_MODIFIER;
525
- const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize)
526
- ? options.processor.normalize
527
- : DEFAULT_NORMALIZE;
528
- const interpolate = isPlainObject(options.processor) &&
529
- isFunction(options.processor.interpolate)
530
- ? options.processor.interpolate
531
- : DEFAULT_INTERPOLATE;
532
- const type = isPlainObject(options.processor) && isString(options.processor.type)
533
- ? options.processor.type
534
- : DEFAULT_MESSAGE_DATA_TYPE;
535
- const linked = (key, ...args) => {
536
- const [arg1, arg2] = args;
537
- let type = 'text';
538
- let modifier = '';
539
- if (args.length === 1) {
540
- if (isObject(arg1)) {
541
- modifier = arg1.modifier || modifier;
542
- type = arg1.type || type;
543
- }
544
- else if (isString(arg1)) {
545
- modifier = arg1 || modifier;
546
- }
547
- }
548
- else if (args.length === 2) {
549
- if (isString(arg1)) {
550
- modifier = arg1 || modifier;
551
- }
552
- if (isString(arg2)) {
553
- type = arg2 || type;
554
- }
555
- }
556
- let msg = message(key)(ctx);
557
- // The message in vnode resolved with linked are returned as an array by processor.nomalize
558
- if (type === 'vnode' && isArray(msg) && modifier) {
559
- msg = msg[0];
560
- }
561
- return modifier ? _modifier(modifier)(msg, type) : msg;
562
- };
563
- const ctx = {
564
- ["list" /* LIST */]: list,
565
- ["named" /* NAMED */]: named,
566
- ["plural" /* PLURAL */]: plural,
567
- ["linked" /* LINKED */]: linked,
568
- ["message" /* MESSAGE */]: message,
569
- ["type" /* TYPE */]: type,
570
- ["interpolate" /* INTERPOLATE */]: interpolate,
571
- ["normalize" /* NORMALIZE */]: normalize
572
- };
573
- return ctx;
207
+ const pathStateMachine = [];
208
+ pathStateMachine[0 /* States.BEFORE_PATH */] = {
209
+ ["w" /* PathCharTypes.WORKSPACE */]: [0 /* States.BEFORE_PATH */],
210
+ ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
211
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */],
212
+ ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */]
213
+ };
214
+ pathStateMachine[1 /* States.IN_PATH */] = {
215
+ ["w" /* PathCharTypes.WORKSPACE */]: [1 /* States.IN_PATH */],
216
+ ["." /* PathCharTypes.DOT */]: [2 /* States.BEFORE_IDENT */],
217
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */],
218
+ ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */]
219
+ };
220
+ pathStateMachine[2 /* States.BEFORE_IDENT */] = {
221
+ ["w" /* PathCharTypes.WORKSPACE */]: [2 /* States.BEFORE_IDENT */],
222
+ ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
223
+ ["0" /* PathCharTypes.ZERO */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */]
224
+ };
225
+ pathStateMachine[3 /* States.IN_IDENT */] = {
226
+ ["i" /* PathCharTypes.IDENT */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
227
+ ["0" /* PathCharTypes.ZERO */]: [3 /* States.IN_IDENT */, 0 /* Actions.APPEND */],
228
+ ["w" /* PathCharTypes.WORKSPACE */]: [1 /* States.IN_PATH */, 1 /* Actions.PUSH */],
229
+ ["." /* PathCharTypes.DOT */]: [2 /* States.BEFORE_IDENT */, 1 /* Actions.PUSH */],
230
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [4 /* States.IN_SUB_PATH */, 1 /* Actions.PUSH */],
231
+ ["o" /* PathCharTypes.END_OF_FAIL */]: [7 /* States.AFTER_PATH */, 1 /* Actions.PUSH */]
232
+ };
233
+ pathStateMachine[4 /* States.IN_SUB_PATH */] = {
234
+ ["'" /* PathCharTypes.SINGLE_QUOTE */]: [5 /* States.IN_SINGLE_QUOTE */, 0 /* Actions.APPEND */],
235
+ ["\"" /* PathCharTypes.DOUBLE_QUOTE */]: [6 /* States.IN_DOUBLE_QUOTE */, 0 /* Actions.APPEND */],
236
+ ["[" /* PathCharTypes.LEFT_BRACKET */]: [
237
+ 4 /* States.IN_SUB_PATH */,
238
+ 2 /* Actions.INC_SUB_PATH_DEPTH */
239
+ ],
240
+ ["]" /* PathCharTypes.RIGHT_BRACKET */]: [1 /* States.IN_PATH */, 3 /* Actions.PUSH_SUB_PATH */],
241
+ ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
242
+ ["l" /* PathCharTypes.ELSE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */]
243
+ };
244
+ pathStateMachine[5 /* States.IN_SINGLE_QUOTE */] = {
245
+ ["'" /* PathCharTypes.SINGLE_QUOTE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */],
246
+ ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
247
+ ["l" /* PathCharTypes.ELSE */]: [5 /* States.IN_SINGLE_QUOTE */, 0 /* Actions.APPEND */]
248
+ };
249
+ pathStateMachine[6 /* States.IN_DOUBLE_QUOTE */] = {
250
+ ["\"" /* PathCharTypes.DOUBLE_QUOTE */]: [4 /* States.IN_SUB_PATH */, 0 /* Actions.APPEND */],
251
+ ["o" /* PathCharTypes.END_OF_FAIL */]: 8 /* States.ERROR */,
252
+ ["l" /* PathCharTypes.ELSE */]: [6 /* States.IN_DOUBLE_QUOTE */, 0 /* Actions.APPEND */]
253
+ };
254
+ /**
255
+ * Check if an expression is a literal value.
256
+ */
257
+ const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
258
+ function isLiteral(exp) {
259
+ return literalValueRE.test(exp);
260
+ }
261
+ /**
262
+ * Strip quotes from a string
263
+ */
264
+ function stripQuotes(str) {
265
+ const a = str.charCodeAt(0);
266
+ const b = str.charCodeAt(str.length - 1);
267
+ return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
268
+ }
269
+ /**
270
+ * Determine the type of a character in a keypath.
271
+ */
272
+ function getPathCharType(ch) {
273
+ if (ch === undefined || ch === null) {
274
+ return "o" /* PathCharTypes.END_OF_FAIL */;
275
+ }
276
+ const code = ch.charCodeAt(0);
277
+ switch (code) {
278
+ case 0x5b: // [
279
+ case 0x5d: // ]
280
+ case 0x2e: // .
281
+ case 0x22: // "
282
+ case 0x27: // '
283
+ return ch;
284
+ case 0x5f: // _
285
+ case 0x24: // $
286
+ case 0x2d: // -
287
+ return "i" /* PathCharTypes.IDENT */;
288
+ case 0x09: // Tab (HT)
289
+ case 0x0a: // Newline (LF)
290
+ case 0x0d: // Return (CR)
291
+ case 0xa0: // No-break space (NBSP)
292
+ case 0xfeff: // Byte Order Mark (BOM)
293
+ case 0x2028: // Line Separator (LS)
294
+ case 0x2029: // Paragraph Separator (PS)
295
+ return "w" /* PathCharTypes.WORKSPACE */;
296
+ }
297
+ return "i" /* PathCharTypes.IDENT */;
298
+ }
299
+ /**
300
+ * Format a subPath, return its plain form if it is
301
+ * a literal string or number. Otherwise prepend the
302
+ * dynamic indicator (*).
303
+ */
304
+ function formatSubPath(path) {
305
+ const trimmed = path.trim();
306
+ // invalid leading 0
307
+ if (path.charAt(0) === '0' && isNaN(parseInt(path))) {
308
+ return false;
309
+ }
310
+ return isLiteral(trimmed)
311
+ ? stripQuotes(trimmed)
312
+ : "*" /* PathCharTypes.ASTARISK */ + trimmed;
313
+ }
314
+ /**
315
+ * Parse a string path into an array of segments
316
+ */
317
+ function parse(path) {
318
+ const keys = [];
319
+ let index = -1;
320
+ let mode = 0 /* States.BEFORE_PATH */;
321
+ let subPathDepth = 0;
322
+ let c;
323
+ let key; // eslint-disable-line
324
+ let newChar;
325
+ let type;
326
+ let transition;
327
+ let action;
328
+ let typeMap;
329
+ const actions = [];
330
+ actions[0 /* Actions.APPEND */] = () => {
331
+ if (key === undefined) {
332
+ key = newChar;
333
+ }
334
+ else {
335
+ key += newChar;
336
+ }
337
+ };
338
+ actions[1 /* Actions.PUSH */] = () => {
339
+ if (key !== undefined) {
340
+ keys.push(key);
341
+ key = undefined;
342
+ }
343
+ };
344
+ actions[2 /* Actions.INC_SUB_PATH_DEPTH */] = () => {
345
+ actions[0 /* Actions.APPEND */]();
346
+ subPathDepth++;
347
+ };
348
+ actions[3 /* Actions.PUSH_SUB_PATH */] = () => {
349
+ if (subPathDepth > 0) {
350
+ subPathDepth--;
351
+ mode = 4 /* States.IN_SUB_PATH */;
352
+ actions[0 /* Actions.APPEND */]();
353
+ }
354
+ else {
355
+ subPathDepth = 0;
356
+ if (key === undefined) {
357
+ return false;
358
+ }
359
+ key = formatSubPath(key);
360
+ if (key === false) {
361
+ return false;
362
+ }
363
+ else {
364
+ actions[1 /* Actions.PUSH */]();
365
+ }
366
+ }
367
+ };
368
+ function maybeUnescapeQuote() {
369
+ const nextChar = path[index + 1];
370
+ if ((mode === 5 /* States.IN_SINGLE_QUOTE */ &&
371
+ nextChar === "'" /* PathCharTypes.SINGLE_QUOTE */) ||
372
+ (mode === 6 /* States.IN_DOUBLE_QUOTE */ &&
373
+ nextChar === "\"" /* PathCharTypes.DOUBLE_QUOTE */)) {
374
+ index++;
375
+ newChar = '\\' + nextChar;
376
+ actions[0 /* Actions.APPEND */]();
377
+ return true;
378
+ }
379
+ }
380
+ while (mode !== null) {
381
+ index++;
382
+ c = path[index];
383
+ if (c === '\\' && maybeUnescapeQuote()) {
384
+ continue;
385
+ }
386
+ type = getPathCharType(c);
387
+ typeMap = pathStateMachine[mode];
388
+ transition = typeMap[type] || typeMap["l" /* PathCharTypes.ELSE */] || 8 /* States.ERROR */;
389
+ // check parse error
390
+ if (transition === 8 /* States.ERROR */) {
391
+ return;
392
+ }
393
+ mode = transition[0];
394
+ if (transition[1] !== undefined) {
395
+ action = actions[transition[1]];
396
+ if (action) {
397
+ newChar = c;
398
+ if (action() === false) {
399
+ return;
400
+ }
401
+ }
402
+ }
403
+ // check parse finish
404
+ if (mode === 7 /* States.AFTER_PATH */) {
405
+ return keys;
406
+ }
407
+ }
408
+ }
409
+ // path token cache
410
+ const cache = new Map();
411
+ /**
412
+ * key-value message resolver
413
+ *
414
+ * @remarks
415
+ * Resolves messages with the key-value structure. Note that messages with a hierarchical structure such as objects cannot be resolved
416
+ *
417
+ * @param obj - A target object to be resolved with path
418
+ * @param path - A {@link Path | path} to resolve the value of message
419
+ *
420
+ * @returns A resolved {@link PathValue | path value}
421
+ *
422
+ * @VueI18nGeneral
423
+ */
424
+ function resolveWithKeyValue(obj, path) {
425
+ return isObject(obj) ? obj[path] : null;
426
+ }
427
+ /**
428
+ * message resolver
429
+ *
430
+ * @remarks
431
+ * Resolves messages. messages with a hierarchical structure such as objects can be resolved. This resolver is used in VueI18n as default.
432
+ *
433
+ * @param obj - A target object to be resolved with path
434
+ * @param path - A {@link Path | path} to resolve the value of message
435
+ *
436
+ * @returns A resolved {@link PathValue | path value}
437
+ *
438
+ * @VueI18nGeneral
439
+ */
440
+ function resolveValue(obj, path) {
441
+ // check object
442
+ if (!isObject(obj)) {
443
+ return null;
444
+ }
445
+ // parse path
446
+ let hit = cache.get(path);
447
+ if (!hit) {
448
+ hit = parse(path);
449
+ if (hit) {
450
+ cache.set(path, hit);
451
+ }
452
+ }
453
+ // check hit
454
+ if (!hit) {
455
+ return null;
456
+ }
457
+ // resolve path value
458
+ const len = hit.length;
459
+ let last = obj;
460
+ let i = 0;
461
+ while (i < len) {
462
+ const val = last[hit[i]];
463
+ if (val === undefined) {
464
+ return null;
465
+ }
466
+ last = val;
467
+ i++;
468
+ }
469
+ return last;
470
+ }
471
+
472
+ const DEFAULT_MODIFIER = (str) => str;
473
+ const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
474
+ const DEFAULT_MESSAGE_DATA_TYPE = 'text';
475
+ const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : join(values);
476
+ const DEFAULT_INTERPOLATE = toDisplayString;
477
+ function pluralDefault(choice, choicesLength) {
478
+ choice = Math.abs(choice);
479
+ if (choicesLength === 2) {
480
+ // prettier-ignore
481
+ return choice
482
+ ? choice > 1
483
+ ? 1
484
+ : 0
485
+ : 1;
486
+ }
487
+ return choice ? Math.min(choice, 2) : 0;
488
+ }
489
+ function getPluralIndex(options) {
490
+ // prettier-ignore
491
+ const index = isNumber(options.pluralIndex)
492
+ ? options.pluralIndex
493
+ : -1;
494
+ // prettier-ignore
495
+ return options.named && (isNumber(options.named.count) || isNumber(options.named.n))
496
+ ? isNumber(options.named.count)
497
+ ? options.named.count
498
+ : isNumber(options.named.n)
499
+ ? options.named.n
500
+ : index
501
+ : index;
502
+ }
503
+ function normalizeNamed(pluralIndex, props) {
504
+ if (!props.count) {
505
+ props.count = pluralIndex;
506
+ }
507
+ if (!props.n) {
508
+ props.n = pluralIndex;
509
+ }
510
+ }
511
+ function createMessageContext(options = {}) {
512
+ const locale = options.locale;
513
+ const pluralIndex = getPluralIndex(options);
514
+ const pluralRule = isObject(options.pluralRules) &&
515
+ isString(locale) &&
516
+ isFunction(options.pluralRules[locale])
517
+ ? options.pluralRules[locale]
518
+ : pluralDefault;
519
+ const orgPluralRule = isObject(options.pluralRules) &&
520
+ isString(locale) &&
521
+ isFunction(options.pluralRules[locale])
522
+ ? pluralDefault
523
+ : undefined;
524
+ const plural = (messages) => {
525
+ return messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
526
+ };
527
+ const _list = options.list || [];
528
+ const list = (index) => _list[index];
529
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
530
+ const _named = options.named || {};
531
+ isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
532
+ const named = (key) => _named[key];
533
+ function message(key) {
534
+ // prettier-ignore
535
+ const msg = isFunction(options.messages)
536
+ ? options.messages(key)
537
+ : isObject(options.messages)
538
+ ? options.messages[key]
539
+ : false;
540
+ return !msg
541
+ ? options.parent
542
+ ? options.parent.message(key) // resolve from parent messages
543
+ : DEFAULT_MESSAGE
544
+ : msg;
545
+ }
546
+ const _modifier = (name) => options.modifiers
547
+ ? options.modifiers[name]
548
+ : DEFAULT_MODIFIER;
549
+ const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize)
550
+ ? options.processor.normalize
551
+ : DEFAULT_NORMALIZE;
552
+ const interpolate = isPlainObject(options.processor) &&
553
+ isFunction(options.processor.interpolate)
554
+ ? options.processor.interpolate
555
+ : DEFAULT_INTERPOLATE;
556
+ const type = isPlainObject(options.processor) && isString(options.processor.type)
557
+ ? options.processor.type
558
+ : DEFAULT_MESSAGE_DATA_TYPE;
559
+ const linked = (key, ...args) => {
560
+ const [arg1, arg2] = args;
561
+ let type = 'text';
562
+ let modifier = '';
563
+ if (args.length === 1) {
564
+ if (isObject(arg1)) {
565
+ modifier = arg1.modifier || modifier;
566
+ type = arg1.type || type;
567
+ }
568
+ else if (isString(arg1)) {
569
+ modifier = arg1 || modifier;
570
+ }
571
+ }
572
+ else if (args.length === 2) {
573
+ if (isString(arg1)) {
574
+ modifier = arg1 || modifier;
575
+ }
576
+ if (isString(arg2)) {
577
+ type = arg2 || type;
578
+ }
579
+ }
580
+ const ret = message(key)(ctx);
581
+ const msg =
582
+ // The message in vnode resolved with linked are returned as an array by processor.nomalize
583
+ type === 'vnode' && isArray(ret) && modifier
584
+ ? ret[0]
585
+ : ret;
586
+ return modifier ? _modifier(modifier)(msg, type) : msg;
587
+ };
588
+ const ctx = {
589
+ ["list" /* HelperNameMap.LIST */]: list,
590
+ ["named" /* HelperNameMap.NAMED */]: named,
591
+ ["plural" /* HelperNameMap.PLURAL */]: plural,
592
+ ["linked" /* HelperNameMap.LINKED */]: linked,
593
+ ["message" /* HelperNameMap.MESSAGE */]: message,
594
+ ["type" /* HelperNameMap.TYPE */]: type,
595
+ ["interpolate" /* HelperNameMap.INTERPOLATE */]: interpolate,
596
+ ["normalize" /* HelperNameMap.NORMALIZE */]: normalize,
597
+ ["values" /* HelperNameMap.VALUES */]: assign({}, _list, _named)
598
+ };
599
+ return ctx;
574
600
  }
575
601
 
576
- const IntlifyDevToolsHooks = {
577
- I18nInit: 'i18n:init',
578
- FunctionTranslate: 'function:translate'
602
+ const IntlifyDevToolsHooks = {
603
+ I18nInit: 'i18n:init',
604
+ FunctionTranslate: 'function:translate'
579
605
  };
580
606
 
581
- let devtools = null;
582
- function setDevToolsHook(hook) {
583
- devtools = hook;
584
- }
585
- function getDevToolsHook() {
586
- return devtools;
587
- }
588
- function initI18nDevTools(i18n, version, meta) {
589
- // TODO: queue if devtools is undefined
590
- devtools &&
591
- devtools.emit(IntlifyDevToolsHooks.I18nInit, {
592
- timestamp: Date.now(),
593
- i18n,
594
- version,
595
- meta
596
- });
597
- }
598
- const translateDevTools = /* #__PURE__*/ createDevToolsHook(IntlifyDevToolsHooks.FunctionTranslate);
599
- function createDevToolsHook(hook) {
600
- return (payloads) => devtools && devtools.emit(hook, payloads);
607
+ let devtools = null;
608
+ function setDevToolsHook(hook) {
609
+ devtools = hook;
610
+ }
611
+ function getDevToolsHook() {
612
+ return devtools;
613
+ }
614
+ function initI18nDevTools(i18n, version, meta) {
615
+ // TODO: queue if devtools is undefined
616
+ devtools &&
617
+ devtools.emit(IntlifyDevToolsHooks.I18nInit, {
618
+ timestamp: Date.now(),
619
+ i18n,
620
+ version,
621
+ meta
622
+ });
623
+ }
624
+ const translateDevTools = /* #__PURE__*/ createDevToolsHook(IntlifyDevToolsHooks.FunctionTranslate);
625
+ function createDevToolsHook(hook) {
626
+ return (payloads) => devtools && devtools.emit(hook, payloads);
601
627
  }
602
628
 
603
- const CoreWarnCodes = {
604
- NOT_FOUND_KEY: 1,
605
- FALLBACK_TO_TRANSLATE: 2,
606
- CANNOT_FORMAT_NUMBER: 3,
607
- FALLBACK_TO_NUMBER_FORMAT: 4,
608
- CANNOT_FORMAT_DATE: 5,
609
- FALLBACK_TO_DATE_FORMAT: 6,
610
- __EXTEND_POINT__: 7
611
- };
612
- /** @internal */
613
- const warnMessages = {
614
- [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
615
- [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
616
- [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
617
- [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
618
- [CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
619
- [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`
620
- };
621
- function getWarnMessage(code, ...args) {
622
- return format(warnMessages[code], ...args);
629
+ const CoreWarnCodes = {
630
+ NOT_FOUND_KEY: 1,
631
+ FALLBACK_TO_TRANSLATE: 2,
632
+ CANNOT_FORMAT_NUMBER: 3,
633
+ FALLBACK_TO_NUMBER_FORMAT: 4,
634
+ CANNOT_FORMAT_DATE: 5,
635
+ FALLBACK_TO_DATE_FORMAT: 6,
636
+ EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER: 7,
637
+ __EXTEND_POINT__: 8
638
+ };
639
+ /** @internal */
640
+ const warnMessages = {
641
+ [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
642
+ [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
643
+ [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
644
+ [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
645
+ [CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
646
+ [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`,
647
+ [CoreWarnCodes.EXPERIMENTAL_CUSTOM_MESSAGE_COMPILER]: `This project is using Custom Message Compiler, which is an experimental feature. It may receive breaking changes or be removed in the future.`
648
+ };
649
+ function getWarnMessage(code, ...args) {
650
+ return format$1(warnMessages[code], ...args);
623
651
  }
624
652
 
625
- /**
626
- * Fallback with simple implemenation
627
- *
628
- * @remarks
629
- * A fallback locale function implemented with a simple fallback algorithm.
630
- *
631
- * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
632
- *
633
- * @param ctx - A {@link CoreContext | context}
634
- * @param fallback - A {@link FallbackLocale | fallback locale}
635
- * @param start - A starting {@link Locale | locale}
636
- *
637
- * @returns Fallback locales
638
- *
639
- * @VueI18nGeneral
640
- */
641
- function fallbackWithSimple(ctx, fallback, start // eslint-disable-line @typescript-eslint/no-unused-vars
642
- ) {
643
- // prettier-ignore
644
- return [...new Set([
645
- start,
646
- ...(isArray(fallback)
647
- ? fallback
648
- : isObject(fallback)
649
- ? Object.keys(fallback)
650
- : isString(fallback)
651
- ? [fallback]
652
- : [start])
653
- ])];
654
- }
655
- /**
656
- * Fallback with locale chain
657
- *
658
- * @remarks
659
- * A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
660
- *
661
- * @param ctx - A {@link CoreContext | context}
662
- * @param fallback - A {@link FallbackLocale | fallback locale}
663
- * @param start - A starting {@link Locale | locale}
664
- *
665
- * @returns Fallback locales
666
- *
667
- * @VueI18nSee [Fallbacking](../guide/essentials/fallback)
668
- *
669
- * @VueI18nGeneral
670
- */
671
- function fallbackWithLocaleChain(ctx, fallback, start) {
672
- const startLocale = isString(start) ? start : DEFAULT_LOCALE;
673
- const context = ctx;
674
- if (!context.__localeChainCache) {
675
- context.__localeChainCache = new Map();
676
- }
677
- let chain = context.__localeChainCache.get(startLocale);
678
- if (!chain) {
679
- chain = [];
680
- // first block defined by start
681
- let block = [start];
682
- // while any intervening block found
683
- while (isArray(block)) {
684
- block = appendBlockToChain(chain, block, fallback);
685
- }
686
- // prettier-ignore
687
- // last block defined by default
688
- const defaults = isArray(fallback) || !isPlainObject(fallback)
689
- ? fallback
690
- : fallback['default']
691
- ? fallback['default']
692
- : null;
693
- // convert defaults to array
694
- block = isString(defaults) ? [defaults] : defaults;
695
- if (isArray(block)) {
696
- appendBlockToChain(chain, block, false);
697
- }
698
- context.__localeChainCache.set(startLocale, chain);
699
- }
700
- return chain;
701
- }
702
- function appendBlockToChain(chain, block, blocks) {
703
- let follow = true;
704
- for (let i = 0; i < block.length && isBoolean(follow); i++) {
705
- const locale = block[i];
706
- if (isString(locale)) {
707
- follow = appendLocaleToChain(chain, block[i], blocks);
708
- }
709
- }
710
- return follow;
711
- }
712
- function appendLocaleToChain(chain, locale, blocks) {
713
- let follow;
714
- const tokens = locale.split('-');
715
- do {
716
- const target = tokens.join('-');
717
- follow = appendItemToChain(chain, target, blocks);
718
- tokens.splice(-1, 1);
719
- } while (tokens.length && follow === true);
720
- return follow;
721
- }
722
- function appendItemToChain(chain, target, blocks) {
723
- let follow = false;
724
- if (!chain.includes(target)) {
725
- follow = true;
726
- if (target) {
727
- follow = target[target.length - 1] !== '!';
728
- const locale = target.replace(/!/g, '');
729
- chain.push(locale);
730
- if ((isArray(blocks) || isPlainObject(blocks)) &&
731
- blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
732
- ) {
733
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
734
- follow = blocks[locale];
735
- }
736
- }
737
- }
738
- return follow;
653
+ /**
654
+ * Fallback with simple implemenation
655
+ *
656
+ * @remarks
657
+ * A fallback locale function implemented with a simple fallback algorithm.
658
+ *
659
+ * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
660
+ *
661
+ * @param ctx - A {@link CoreContext | context}
662
+ * @param fallback - A {@link FallbackLocale | fallback locale}
663
+ * @param start - A starting {@link Locale | locale}
664
+ *
665
+ * @returns Fallback locales
666
+ *
667
+ * @VueI18nGeneral
668
+ */
669
+ function fallbackWithSimple(ctx, fallback, start // eslint-disable-line @typescript-eslint/no-unused-vars
670
+ ) {
671
+ // prettier-ignore
672
+ return [...new Set([
673
+ start,
674
+ ...(isArray(fallback)
675
+ ? fallback
676
+ : isObject(fallback)
677
+ ? Object.keys(fallback)
678
+ : isString(fallback)
679
+ ? [fallback]
680
+ : [start])
681
+ ])];
682
+ }
683
+ /**
684
+ * Fallback with locale chain
685
+ *
686
+ * @remarks
687
+ * A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
688
+ *
689
+ * @param ctx - A {@link CoreContext | context}
690
+ * @param fallback - A {@link FallbackLocale | fallback locale}
691
+ * @param start - A starting {@link Locale | locale}
692
+ *
693
+ * @returns Fallback locales
694
+ *
695
+ * @VueI18nSee [Fallbacking](../guide/essentials/fallback)
696
+ *
697
+ * @VueI18nGeneral
698
+ */
699
+ function fallbackWithLocaleChain(ctx, fallback, start) {
700
+ const startLocale = isString(start) ? start : DEFAULT_LOCALE;
701
+ const context = ctx;
702
+ if (!context.__localeChainCache) {
703
+ context.__localeChainCache = new Map();
704
+ }
705
+ let chain = context.__localeChainCache.get(startLocale);
706
+ if (!chain) {
707
+ chain = [];
708
+ // first block defined by start
709
+ let block = [start];
710
+ // while any intervening block found
711
+ while (isArray(block)) {
712
+ block = appendBlockToChain(chain, block, fallback);
713
+ }
714
+ // prettier-ignore
715
+ // last block defined by default
716
+ const defaults = isArray(fallback) || !isPlainObject(fallback)
717
+ ? fallback
718
+ : fallback['default']
719
+ ? fallback['default']
720
+ : null;
721
+ // convert defaults to array
722
+ block = isString(defaults) ? [defaults] : defaults;
723
+ if (isArray(block)) {
724
+ appendBlockToChain(chain, block, false);
725
+ }
726
+ context.__localeChainCache.set(startLocale, chain);
727
+ }
728
+ return chain;
729
+ }
730
+ function appendBlockToChain(chain, block, blocks) {
731
+ let follow = true;
732
+ for (let i = 0; i < block.length && isBoolean(follow); i++) {
733
+ const locale = block[i];
734
+ if (isString(locale)) {
735
+ follow = appendLocaleToChain(chain, block[i], blocks);
736
+ }
737
+ }
738
+ return follow;
739
+ }
740
+ function appendLocaleToChain(chain, locale, blocks) {
741
+ let follow;
742
+ const tokens = locale.split('-');
743
+ do {
744
+ const target = tokens.join('-');
745
+ follow = appendItemToChain(chain, target, blocks);
746
+ tokens.splice(-1, 1);
747
+ } while (tokens.length && follow === true);
748
+ return follow;
749
+ }
750
+ function appendItemToChain(chain, target, blocks) {
751
+ let follow = false;
752
+ if (!chain.includes(target)) {
753
+ follow = true;
754
+ if (target) {
755
+ follow = target[target.length - 1] !== '!';
756
+ const locale = target.replace(/!/g, '');
757
+ chain.push(locale);
758
+ if ((isArray(blocks) || isPlainObject(blocks)) &&
759
+ blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
760
+ ) {
761
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
762
+ follow = blocks[locale];
763
+ }
764
+ }
765
+ }
766
+ return follow;
739
767
  }
740
768
 
741
- /* eslint-disable @typescript-eslint/no-explicit-any */
742
- /**
743
- * Intlify core-base version
744
- * @internal
745
- */
746
- const VERSION = '9.3.0-beta.9';
747
- const NOT_REOSLVED = -1;
748
- const DEFAULT_LOCALE = 'en-US';
749
- const MISSING_RESOLVE_VALUE = '';
750
- const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
751
- function getDefaultLinkedModifiers() {
752
- return {
753
- upper: (val, type) => {
754
- // prettier-ignore
755
- return type === 'text' && isString(val)
756
- ? val.toUpperCase()
757
- : type === 'vnode' && isObject(val) && '__v_isVNode' in val
758
- ? val.children.toUpperCase()
759
- : val;
760
- },
761
- lower: (val, type) => {
762
- // prettier-ignore
763
- return type === 'text' && isString(val)
764
- ? val.toLowerCase()
765
- : type === 'vnode' && isObject(val) && '__v_isVNode' in val
766
- ? val.children.toLowerCase()
767
- : val;
768
- },
769
- capitalize: (val, type) => {
770
- // prettier-ignore
771
- return (type === 'text' && isString(val)
772
- ? capitalize(val)
773
- : type === 'vnode' && isObject(val) && '__v_isVNode' in val
774
- ? capitalize(val.children)
775
- : val);
776
- }
777
- };
778
- }
779
- let _compiler;
780
- function registerMessageCompiler(compiler) {
781
- _compiler = compiler;
782
- }
783
- let _resolver;
784
- /**
785
- * Register the message resolver
786
- *
787
- * @param resolver - A {@link MessageResolver} function
788
- *
789
- * @VueI18nGeneral
790
- */
791
- function registerMessageResolver(resolver) {
792
- _resolver = resolver;
793
- }
794
- let _fallbacker;
795
- /**
796
- * Register the locale fallbacker
797
- *
798
- * @param fallbacker - A {@link LocaleFallbacker} function
799
- *
800
- * @VueI18nGeneral
801
- */
802
- function registerLocaleFallbacker(fallbacker) {
803
- _fallbacker = fallbacker;
804
- }
805
- // Additional Meta for Intlify DevTools
806
- let _additionalMeta = null;
807
- const setAdditionalMeta = (meta) => {
808
- _additionalMeta = meta;
809
- };
810
- const getAdditionalMeta = () => _additionalMeta;
811
- let _fallbackContext = null;
812
- const setFallbackContext = (context) => {
813
- _fallbackContext = context;
814
- };
815
- const getFallbackContext = () => _fallbackContext;
816
- // ID for CoreContext
817
- let _cid = 0;
818
- function createCoreContext(options = {}) {
819
- // setup options
820
- const version = isString(options.version) ? options.version : VERSION;
821
- const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
822
- const fallbackLocale = isArray(options.fallbackLocale) ||
823
- isPlainObject(options.fallbackLocale) ||
824
- isString(options.fallbackLocale) ||
825
- options.fallbackLocale === false
826
- ? options.fallbackLocale
827
- : locale;
828
- const messages = isPlainObject(options.messages)
829
- ? options.messages
830
- : { [locale]: {} };
831
- const datetimeFormats = isPlainObject(options.datetimeFormats)
832
- ? options.datetimeFormats
833
- : { [locale]: {} }
834
- ;
835
- const numberFormats = isPlainObject(options.numberFormats)
836
- ? options.numberFormats
837
- : { [locale]: {} }
838
- ;
839
- const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
840
- const pluralRules = options.pluralRules || {};
841
- const missing = isFunction(options.missing) ? options.missing : null;
842
- const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
843
- ? options.missingWarn
844
- : true;
845
- const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
846
- ? options.fallbackWarn
847
- : true;
848
- const fallbackFormat = !!options.fallbackFormat;
849
- const unresolving = !!options.unresolving;
850
- const postTranslation = isFunction(options.postTranslation)
851
- ? options.postTranslation
852
- : null;
853
- const processor = isPlainObject(options.processor) ? options.processor : null;
854
- const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
855
- ? options.warnHtmlMessage
856
- : true;
857
- const escapeParameter = !!options.escapeParameter;
858
- const messageCompiler = isFunction(options.messageCompiler)
859
- ? options.messageCompiler
860
- : _compiler;
861
- const messageResolver = isFunction(options.messageResolver)
862
- ? options.messageResolver
863
- : _resolver || resolveWithKeyValue;
864
- const localeFallbacker = isFunction(options.localeFallbacker)
865
- ? options.localeFallbacker
866
- : _fallbacker || fallbackWithSimple;
867
- const fallbackContext = isObject(options.fallbackContext)
868
- ? options.fallbackContext
869
- : undefined;
870
- const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
871
- // setup internal options
872
- const internalOptions = options;
873
- const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters)
874
- ? internalOptions.__datetimeFormatters
875
- : new Map()
876
- ;
877
- const __numberFormatters = isObject(internalOptions.__numberFormatters)
878
- ? internalOptions.__numberFormatters
879
- : new Map()
880
- ;
881
- const __meta = isObject(internalOptions.__meta) ? internalOptions.__meta : {};
882
- _cid++;
883
- const context = {
884
- version,
885
- cid: _cid,
886
- locale,
887
- fallbackLocale,
888
- messages,
889
- modifiers,
890
- pluralRules,
891
- missing,
892
- missingWarn,
893
- fallbackWarn,
894
- fallbackFormat,
895
- unresolving,
896
- postTranslation,
897
- processor,
898
- warnHtmlMessage,
899
- escapeParameter,
900
- messageCompiler,
901
- messageResolver,
902
- localeFallbacker,
903
- fallbackContext,
904
- onWarn,
905
- __meta
906
- };
907
- {
908
- context.datetimeFormats = datetimeFormats;
909
- context.numberFormats = numberFormats;
910
- context.__datetimeFormatters = __datetimeFormatters;
911
- context.__numberFormatters = __numberFormatters;
912
- }
913
- // for vue-devtools timeline event
914
- {
915
- context.__v_emitter =
916
- internalOptions.__v_emitter != null
917
- ? internalOptions.__v_emitter
918
- : undefined;
919
- }
920
- // NOTE: experimental !!
921
- {
922
- initI18nDevTools(context, version, __meta);
923
- }
924
- return context;
925
- }
926
- /** @internal */
927
- function isTranslateFallbackWarn(fallback, key) {
928
- return fallback instanceof RegExp ? fallback.test(key) : fallback;
929
- }
930
- /** @internal */
931
- function isTranslateMissingWarn(missing, key) {
932
- return missing instanceof RegExp ? missing.test(key) : missing;
933
- }
934
- /** @internal */
935
- function handleMissing(context, key, locale, missingWarn, type) {
936
- const { missing, onWarn } = context;
937
- // for vue-devtools timeline event
938
- {
939
- const emitter = context.__v_emitter;
940
- if (emitter) {
941
- emitter.emit("missing" /* MISSING */, {
942
- locale,
943
- key,
944
- type,
945
- groupId: `${type}:${key}`
946
- });
947
- }
948
- }
949
- if (missing !== null) {
950
- const ret = missing(context, locale, key, type);
951
- return isString(ret) ? ret : key;
952
- }
953
- else {
954
- if (isTranslateMissingWarn(missingWarn, key)) {
955
- onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
956
- }
957
- return key;
958
- }
959
- }
960
- /** @internal */
961
- function updateFallbackLocale(ctx, locale, fallback) {
962
- const context = ctx;
963
- context.__localeChainCache = new Map();
964
- ctx.localeFallbacker(ctx, fallback, locale);
965
- }
769
+ /* eslint-disable @typescript-eslint/no-explicit-any */
770
+ /**
771
+ * Intlify core-base version
772
+ * @internal
773
+ */
774
+ const VERSION = '9.3.0';
775
+ const NOT_REOSLVED = -1;
776
+ const DEFAULT_LOCALE = 'en-US';
777
+ const MISSING_RESOLVE_VALUE = '';
778
+ const capitalize = (str) => `${str.charAt(0).toLocaleUpperCase()}${str.substr(1)}`;
779
+ function getDefaultLinkedModifiers() {
780
+ return {
781
+ upper: (val, type) => {
782
+ // prettier-ignore
783
+ return type === 'text' && isString(val)
784
+ ? val.toUpperCase()
785
+ : type === 'vnode' && isObject(val) && '__v_isVNode' in val
786
+ ? val.children.toUpperCase()
787
+ : val;
788
+ },
789
+ lower: (val, type) => {
790
+ // prettier-ignore
791
+ return type === 'text' && isString(val)
792
+ ? val.toLowerCase()
793
+ : type === 'vnode' && isObject(val) && '__v_isVNode' in val
794
+ ? val.children.toLowerCase()
795
+ : val;
796
+ },
797
+ capitalize: (val, type) => {
798
+ // prettier-ignore
799
+ return (type === 'text' && isString(val)
800
+ ? capitalize(val)
801
+ : type === 'vnode' && isObject(val) && '__v_isVNode' in val
802
+ ? capitalize(val.children)
803
+ : val);
804
+ }
805
+ };
806
+ }
807
+ let _compiler;
808
+ function registerMessageCompiler(compiler) {
809
+ _compiler = compiler;
810
+ }
811
+ let _resolver;
812
+ /**
813
+ * Register the message resolver
814
+ *
815
+ * @param resolver - A {@link MessageResolver} function
816
+ *
817
+ * @VueI18nGeneral
818
+ */
819
+ function registerMessageResolver(resolver) {
820
+ _resolver = resolver;
821
+ }
822
+ let _fallbacker;
823
+ /**
824
+ * Register the locale fallbacker
825
+ *
826
+ * @param fallbacker - A {@link LocaleFallbacker} function
827
+ *
828
+ * @VueI18nGeneral
829
+ */
830
+ function registerLocaleFallbacker(fallbacker) {
831
+ _fallbacker = fallbacker;
832
+ }
833
+ // Additional Meta for Intlify DevTools
834
+ let _additionalMeta = null;
835
+ const setAdditionalMeta = /* #__PURE__*/ (meta) => {
836
+ _additionalMeta = meta;
837
+ };
838
+ const getAdditionalMeta = /* #__PURE__*/ () => _additionalMeta;
839
+ let _fallbackContext = null;
840
+ const setFallbackContext = (context) => {
841
+ _fallbackContext = context;
842
+ };
843
+ const getFallbackContext = () => _fallbackContext;
844
+ // ID for CoreContext
845
+ let _cid = 0;
846
+ function createCoreContext(options = {}) {
847
+ // setup options
848
+ const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
849
+ const version = isString(options.version) ? options.version : VERSION;
850
+ const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
851
+ const fallbackLocale = isArray(options.fallbackLocale) ||
852
+ isPlainObject(options.fallbackLocale) ||
853
+ isString(options.fallbackLocale) ||
854
+ options.fallbackLocale === false
855
+ ? options.fallbackLocale
856
+ : locale;
857
+ const messages = isPlainObject(options.messages)
858
+ ? options.messages
859
+ : { [locale]: {} };
860
+ const datetimeFormats = isPlainObject(options.datetimeFormats)
861
+ ? options.datetimeFormats
862
+ : { [locale]: {} }
863
+ ;
864
+ const numberFormats = isPlainObject(options.numberFormats)
865
+ ? options.numberFormats
866
+ : { [locale]: {} }
867
+ ;
868
+ const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
869
+ const pluralRules = options.pluralRules || {};
870
+ const missing = isFunction(options.missing) ? options.missing : null;
871
+ const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
872
+ ? options.missingWarn
873
+ : true;
874
+ const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
875
+ ? options.fallbackWarn
876
+ : true;
877
+ const fallbackFormat = !!options.fallbackFormat;
878
+ const unresolving = !!options.unresolving;
879
+ const postTranslation = isFunction(options.postTranslation)
880
+ ? options.postTranslation
881
+ : null;
882
+ const processor = isPlainObject(options.processor) ? options.processor : null;
883
+ const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
884
+ ? options.warnHtmlMessage
885
+ : true;
886
+ const escapeParameter = !!options.escapeParameter;
887
+ const messageCompiler = isFunction(options.messageCompiler)
888
+ ? options.messageCompiler
889
+ : _compiler;
890
+ const messageResolver = isFunction(options.messageResolver)
891
+ ? options.messageResolver
892
+ : _resolver || resolveWithKeyValue;
893
+ const localeFallbacker = isFunction(options.localeFallbacker)
894
+ ? options.localeFallbacker
895
+ : _fallbacker || fallbackWithSimple;
896
+ const fallbackContext = isObject(options.fallbackContext)
897
+ ? options.fallbackContext
898
+ : undefined;
899
+ // setup internal options
900
+ const internalOptions = options;
901
+ const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters)
902
+ ? internalOptions.__datetimeFormatters
903
+ : new Map()
904
+ ;
905
+ const __numberFormatters = isObject(internalOptions.__numberFormatters)
906
+ ? internalOptions.__numberFormatters
907
+ : new Map()
908
+ ;
909
+ const __meta = isObject(internalOptions.__meta) ? internalOptions.__meta : {};
910
+ _cid++;
911
+ const context = {
912
+ version,
913
+ cid: _cid,
914
+ locale,
915
+ fallbackLocale,
916
+ messages,
917
+ modifiers,
918
+ pluralRules,
919
+ missing,
920
+ missingWarn,
921
+ fallbackWarn,
922
+ fallbackFormat,
923
+ unresolving,
924
+ postTranslation,
925
+ processor,
926
+ warnHtmlMessage,
927
+ escapeParameter,
928
+ messageCompiler,
929
+ messageResolver,
930
+ localeFallbacker,
931
+ fallbackContext,
932
+ onWarn,
933
+ __meta
934
+ };
935
+ {
936
+ context.datetimeFormats = datetimeFormats;
937
+ context.numberFormats = numberFormats;
938
+ context.__datetimeFormatters = __datetimeFormatters;
939
+ context.__numberFormatters = __numberFormatters;
940
+ }
941
+ // for vue-devtools timeline event
942
+ {
943
+ context.__v_emitter =
944
+ internalOptions.__v_emitter != null
945
+ ? internalOptions.__v_emitter
946
+ : undefined;
947
+ }
948
+ // NOTE: experimental !!
949
+ {
950
+ initI18nDevTools(context, version, __meta);
951
+ }
952
+ return context;
953
+ }
954
+ /** @internal */
955
+ function isTranslateFallbackWarn(fallback, key) {
956
+ return fallback instanceof RegExp ? fallback.test(key) : fallback;
957
+ }
958
+ /** @internal */
959
+ function isTranslateMissingWarn(missing, key) {
960
+ return missing instanceof RegExp ? missing.test(key) : missing;
961
+ }
962
+ /** @internal */
963
+ function handleMissing(context, key, locale, missingWarn, type) {
964
+ const { missing, onWarn } = context;
965
+ // for vue-devtools timeline event
966
+ {
967
+ const emitter = context.__v_emitter;
968
+ if (emitter) {
969
+ emitter.emit("missing" /* VueDevToolsTimelineEvents.MISSING */, {
970
+ locale,
971
+ key,
972
+ type,
973
+ groupId: `${type}:${key}`
974
+ });
975
+ }
976
+ }
977
+ if (missing !== null) {
978
+ const ret = missing(context, locale, key, type);
979
+ return isString(ret) ? ret : key;
980
+ }
981
+ else {
982
+ if (isTranslateMissingWarn(missingWarn, key)) {
983
+ onWarn(getWarnMessage(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
984
+ }
985
+ return key;
986
+ }
987
+ }
988
+ /** @internal */
989
+ function updateFallbackLocale(ctx, locale, fallback) {
990
+ const context = ctx;
991
+ context.__localeChainCache = new Map();
992
+ ctx.localeFallbacker(ctx, fallback, locale);
993
+ }
966
994
  /* eslint-enable @typescript-eslint/no-explicit-any */
967
995
 
968
- function clearCompileCache() {
969
- }
970
- function compileToFunction(source, options = {}) {
971
- {
972
- warn(`Runtime compilation is not supported in ${'core.runtime.global.js' }.`);
973
- return (() => source);
974
- }
996
+ function format(ast) {
997
+ const msg = (ctx) => formatParts(ctx, ast);
998
+ return msg;
999
+ }
1000
+ function formatParts(ctx, ast) {
1001
+ const body = ast.b || ast.body;
1002
+ if ((body.t || body.type) === 1 /* NodeTypes.Plural */) {
1003
+ const plural = body;
1004
+ const cases = plural.c || plural.cases;
1005
+ return ctx.plural(cases.reduce((messages, c) => [
1006
+ ...messages,
1007
+ formatMessageParts(ctx, c)
1008
+ ], []));
1009
+ }
1010
+ else {
1011
+ return formatMessageParts(ctx, body);
1012
+ }
1013
+ }
1014
+ function formatMessageParts(ctx, node) {
1015
+ const _static = node.s || node.static;
1016
+ if (_static) {
1017
+ return ctx.type === 'text'
1018
+ ? _static
1019
+ : ctx.normalize([_static]);
1020
+ }
1021
+ else {
1022
+ const messages = (node.i || node.items).reduce((acm, c) => [...acm, formatMessagePart(ctx, c)], []);
1023
+ return ctx.normalize(messages);
1024
+ }
1025
+ }
1026
+ function formatMessagePart(ctx, node) {
1027
+ const type = node.t || node.type;
1028
+ switch (type) {
1029
+ case 3 /* NodeTypes.Text */:
1030
+ const text = node;
1031
+ return (text.v || text.value);
1032
+ case 9 /* NodeTypes.Literal */:
1033
+ const literal = node;
1034
+ return (literal.v || literal.value);
1035
+ case 4 /* NodeTypes.Named */:
1036
+ const named = node;
1037
+ return ctx.interpolate(ctx.named(named.k || named.key));
1038
+ case 5 /* NodeTypes.List */:
1039
+ const list = node;
1040
+ return ctx.interpolate(ctx.list(list.i || list.index));
1041
+ case 6 /* NodeTypes.Linked */:
1042
+ const linked = node;
1043
+ const modifier = linked.m || linked.modifier;
1044
+ return ctx.linked(formatMessagePart(ctx, linked.k || linked.key), modifier ? formatMessagePart(ctx, modifier) : undefined, ctx.type);
1045
+ case 7 /* NodeTypes.LinkedKey */:
1046
+ const linkedKey = node;
1047
+ return (linkedKey.v || linkedKey.value);
1048
+ case 8 /* NodeTypes.LinkedModifier */:
1049
+ const linkedModifier = node;
1050
+ return (linkedModifier.v || linkedModifier.value);
1051
+ default:
1052
+ throw new Error(`unhandled node type on format message part: ${type}`);
1053
+ }
975
1054
  }
976
1055
 
977
- let code = CompileErrorCodes.__EXTEND_POINT__;
978
- const inc = () => ++code;
979
- const CoreErrorCodes = {
980
- INVALID_ARGUMENT: code,
981
- INVALID_DATE_ARGUMENT: inc(),
982
- INVALID_ISO_DATE_ARGUMENT: inc(),
983
- __EXTEND_POINT__: inc() // 18
984
- };
985
- function createCoreError(code) {
986
- return createCompileError(code, null, { messages: errorMessages } );
987
- }
988
- /** @internal */
989
- const errorMessages = {
990
- [CoreErrorCodes.INVALID_ARGUMENT]: 'Invalid arguments',
991
- [CoreErrorCodes.INVALID_DATE_ARGUMENT]: 'The date provided is an invalid Date object.' +
992
- 'Make sure your Date represents a valid date.',
993
- [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: 'The argument provided is not a valid ISO date string'
1056
+ const code = CompileErrorCodes.__EXTEND_POINT__;
1057
+ const inc = incrementer(code);
1058
+ const CoreErrorCodes = {
1059
+ INVALID_ARGUMENT: code,
1060
+ INVALID_DATE_ARGUMENT: inc(),
1061
+ INVALID_ISO_DATE_ARGUMENT: inc(),
1062
+ NOT_SUPPORT_NON_STRING_MESSAGE: inc(),
1063
+ __EXTEND_POINT__: inc() // 22
1064
+ };
1065
+ function createCoreError(code) {
1066
+ return createCompileError(code, null, { messages: errorMessages } );
1067
+ }
1068
+ /** @internal */
1069
+ const errorMessages = {
1070
+ [CoreErrorCodes.INVALID_ARGUMENT]: 'Invalid arguments',
1071
+ [CoreErrorCodes.INVALID_DATE_ARGUMENT]: 'The date provided is an invalid Date object.' +
1072
+ 'Make sure your Date represents a valid date.',
1073
+ [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: 'The argument provided is not a valid ISO date string',
1074
+ [CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE]: 'Not support non-string message'
994
1075
  };
995
1076
 
996
- const NOOP_MESSAGE_FUNCTION = () => '';
997
- const isMessageFunction = (val) => isFunction(val);
998
- // implementation of `translate` function
999
- function translate(context, ...args) {
1000
- const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
1001
- const [key, options] = parseTranslateArgs(...args);
1002
- const missingWarn = isBoolean(options.missingWarn)
1003
- ? options.missingWarn
1004
- : context.missingWarn;
1005
- const fallbackWarn = isBoolean(options.fallbackWarn)
1006
- ? options.fallbackWarn
1007
- : context.fallbackWarn;
1008
- const escapeParameter = isBoolean(options.escapeParameter)
1009
- ? options.escapeParameter
1010
- : context.escapeParameter;
1011
- const resolvedMessage = !!options.resolvedMessage;
1012
- // prettier-ignore
1013
- const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
1014
- ? !isBoolean(options.default)
1015
- ? options.default
1016
- : (!messageCompiler ? () => key : key)
1017
- : fallbackFormat // default by `fallbackFormat` option
1018
- ? (!messageCompiler ? () => key : key)
1019
- : '';
1020
- const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
1021
- const locale = isString(options.locale) ? options.locale : context.locale;
1022
- // escape params
1023
- escapeParameter && escapeParams(options);
1024
- // resolve message format
1025
- // eslint-disable-next-line prefer-const
1026
- let [formatScope, targetLocale, message] = !resolvedMessage
1027
- ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
1028
- : [
1029
- key,
1030
- locale,
1031
- messages[locale] || {}
1032
- ];
1033
- // NOTE:
1034
- // Fix to work around `ssrTransfrom` bug in Vite.
1035
- // https://github.com/vitejs/vite/issues/4306
1036
- // To get around this, use temporary variables.
1037
- // https://github.com/nuxt/framework/issues/1461#issuecomment-954606243
1038
- let format = formatScope;
1039
- // if you use default message, set it as message format!
1040
- let cacheBaseKey = key;
1041
- if (!resolvedMessage &&
1042
- !(isString(format) || isMessageFunction(format))) {
1043
- if (enableDefaultMsg) {
1044
- format = defaultMsgOrKey;
1045
- cacheBaseKey = format;
1046
- }
1047
- }
1048
- // checking message format and target locale
1049
- if (!resolvedMessage &&
1050
- (!(isString(format) || isMessageFunction(format)) ||
1051
- !isString(targetLocale))) {
1052
- return unresolving ? NOT_REOSLVED : key;
1053
- }
1054
- if (isString(format) && context.messageCompiler == null) {
1055
- warn(`The message format compilation is not supported in this build. ` +
1056
- `Because message compiler isn't included. ` +
1057
- `You need to pre-compilation all message format. ` +
1058
- `So translate function return '${key}'.`);
1059
- return key;
1060
- }
1061
- // setup compile error detecting
1062
- let occurred = false;
1063
- const errorDetector = () => {
1064
- occurred = true;
1065
- };
1066
- // compile message format
1067
- const msg = !isMessageFunction(format)
1068
- ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector)
1069
- : format;
1070
- // if occurred compile error, return the message format
1071
- if (occurred) {
1072
- return format;
1073
- }
1074
- // evaluate message with context
1075
- const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
1076
- const msgContext = createMessageContext(ctxOptions);
1077
- const messaged = evaluateMessage(context, msg, msgContext);
1078
- // if use post translation option, proceed it with handler
1079
- const ret = postTranslation
1080
- ? postTranslation(messaged, key)
1081
- : messaged;
1082
- // NOTE: experimental !!
1083
- {
1084
- // prettier-ignore
1085
- const payloads = {
1086
- timestamp: Date.now(),
1087
- key: isString(key)
1088
- ? key
1089
- : isMessageFunction(format)
1090
- ? format.key
1091
- : '',
1092
- locale: targetLocale || (isMessageFunction(format)
1093
- ? format.locale
1094
- : ''),
1095
- format: isString(format)
1096
- ? format
1097
- : isMessageFunction(format)
1098
- ? format.source
1099
- : '',
1100
- message: ret
1101
- };
1102
- payloads.meta = assign({}, context.__meta, getAdditionalMeta() || {});
1103
- translateDevTools(payloads);
1104
- }
1105
- return ret;
1106
- }
1107
- function escapeParams(options) {
1108
- if (isArray(options.list)) {
1109
- options.list = options.list.map(item => isString(item) ? escapeHtml(item) : item);
1110
- }
1111
- else if (isObject(options.named)) {
1112
- Object.keys(options.named).forEach(key => {
1113
- if (isString(options.named[key])) {
1114
- options.named[key] = escapeHtml(options.named[key]);
1115
- }
1116
- });
1117
- }
1118
- }
1119
- function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
1120
- const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
1121
- const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
1122
- let message = {};
1123
- let targetLocale;
1124
- let format = null;
1125
- let from = locale;
1126
- let to = null;
1127
- const type = 'translate';
1128
- for (let i = 0; i < locales.length; i++) {
1129
- targetLocale = to = locales[i];
1130
- if (locale !== targetLocale &&
1131
- isTranslateFallbackWarn(fallbackWarn, key)) {
1132
- onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
1133
- key,
1134
- target: targetLocale
1135
- }));
1136
- }
1137
- // for vue-devtools timeline event
1138
- if (locale !== targetLocale) {
1139
- const emitter = context.__v_emitter;
1140
- if (emitter) {
1141
- emitter.emit("fallback" /* FALBACK */, {
1142
- type,
1143
- key,
1144
- from,
1145
- to,
1146
- groupId: `${type}:${key}`
1147
- });
1148
- }
1149
- }
1150
- message =
1151
- messages[targetLocale] || {};
1152
- // for vue-devtools timeline event
1153
- let start = null;
1154
- let startTag;
1155
- let endTag;
1156
- if (inBrowser) {
1157
- start = window.performance.now();
1158
- startTag = 'intlify-message-resolve-start';
1159
- endTag = 'intlify-message-resolve-end';
1160
- mark && mark(startTag);
1161
- }
1162
- if ((format = resolveValue(message, key)) === null) {
1163
- // if null, resolve with object key path
1164
- format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
1165
- }
1166
- // for vue-devtools timeline event
1167
- if (inBrowser) {
1168
- const end = window.performance.now();
1169
- const emitter = context.__v_emitter;
1170
- if (emitter && start && format) {
1171
- emitter.emit("message-resolve" /* MESSAGE_RESOLVE */, {
1172
- type: "message-resolve" /* MESSAGE_RESOLVE */,
1173
- key,
1174
- message: format,
1175
- time: end - start,
1176
- groupId: `${type}:${key}`
1177
- });
1178
- }
1179
- if (startTag && endTag && mark && measure) {
1180
- mark(endTag);
1181
- measure('intlify message resolve', startTag, endTag);
1182
- }
1183
- }
1184
- if (isString(format) || isFunction(format))
1185
- break;
1186
- const missingRet = handleMissing(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1187
- key, targetLocale, missingWarn, type);
1188
- if (missingRet !== key) {
1189
- format = missingRet;
1190
- }
1191
- from = to;
1192
- }
1193
- return [format, targetLocale, message];
1194
- }
1195
- function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector) {
1196
- const { messageCompiler, warnHtmlMessage } = context;
1197
- if (isMessageFunction(format)) {
1198
- const msg = format;
1199
- msg.locale = msg.locale || targetLocale;
1200
- msg.key = msg.key || key;
1201
- return msg;
1202
- }
1203
- if (messageCompiler == null) {
1204
- const msg = (() => format);
1205
- msg.locale = targetLocale;
1206
- msg.key = key;
1207
- return msg;
1208
- }
1209
- // for vue-devtools timeline event
1210
- let start = null;
1211
- let startTag;
1212
- let endTag;
1213
- if (inBrowser) {
1214
- start = window.performance.now();
1215
- startTag = 'intlify-message-compilation-start';
1216
- endTag = 'intlify-message-compilation-end';
1217
- mark && mark(startTag);
1218
- }
1219
- const msg = messageCompiler(format, getCompileOptions(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, errorDetector));
1220
- // for vue-devtools timeline event
1221
- if (inBrowser) {
1222
- const end = window.performance.now();
1223
- const emitter = context.__v_emitter;
1224
- if (emitter && start) {
1225
- emitter.emit("message-compilation" /* MESSAGE_COMPILATION */, {
1226
- type: "message-compilation" /* MESSAGE_COMPILATION */,
1227
- message: format,
1228
- time: end - start,
1229
- groupId: `${'translate'}:${key}`
1230
- });
1231
- }
1232
- if (startTag && endTag && mark && measure) {
1233
- mark(endTag);
1234
- measure('intlify message compilation', startTag, endTag);
1235
- }
1236
- }
1237
- msg.locale = targetLocale;
1238
- msg.key = key;
1239
- msg.source = format;
1240
- return msg;
1241
- }
1242
- function evaluateMessage(context, msg, msgCtx) {
1243
- // for vue-devtools timeline event
1244
- let start = null;
1245
- let startTag;
1246
- let endTag;
1247
- if (inBrowser) {
1248
- start = window.performance.now();
1249
- startTag = 'intlify-message-evaluation-start';
1250
- endTag = 'intlify-message-evaluation-end';
1251
- mark && mark(startTag);
1252
- }
1253
- const messaged = msg(msgCtx);
1254
- // for vue-devtools timeline event
1255
- if (inBrowser) {
1256
- const end = window.performance.now();
1257
- const emitter = context.__v_emitter;
1258
- if (emitter && start) {
1259
- emitter.emit("message-evaluation" /* MESSAGE_EVALUATION */, {
1260
- type: "message-evaluation" /* MESSAGE_EVALUATION */,
1261
- value: messaged,
1262
- time: end - start,
1263
- groupId: `${'translate'}:${msg.key}`
1264
- });
1265
- }
1266
- if (startTag && endTag && mark && measure) {
1267
- mark(endTag);
1268
- measure('intlify message evaluation', startTag, endTag);
1269
- }
1270
- }
1271
- return messaged;
1272
- }
1273
- /** @internal */
1274
- function parseTranslateArgs(...args) {
1275
- const [arg1, arg2, arg3] = args;
1276
- const options = {};
1277
- if (!isString(arg1) && !isNumber(arg1) && !isMessageFunction(arg1)) {
1278
- throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1279
- }
1280
- // prettier-ignore
1281
- const key = isNumber(arg1)
1282
- ? String(arg1)
1283
- : isMessageFunction(arg1)
1284
- ? arg1
1285
- : arg1;
1286
- if (isNumber(arg2)) {
1287
- options.plural = arg2;
1288
- }
1289
- else if (isString(arg2)) {
1290
- options.default = arg2;
1291
- }
1292
- else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
1293
- options.named = arg2;
1294
- }
1295
- else if (isArray(arg2)) {
1296
- options.list = arg2;
1297
- }
1298
- if (isNumber(arg3)) {
1299
- options.plural = arg3;
1300
- }
1301
- else if (isString(arg3)) {
1302
- options.default = arg3;
1303
- }
1304
- else if (isPlainObject(arg3)) {
1305
- assign(options, arg3);
1306
- }
1307
- return [key, options];
1308
- }
1309
- function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorDetector) {
1310
- return {
1311
- warnHtmlMessage,
1312
- onError: (err) => {
1313
- errorDetector && errorDetector(err);
1314
- {
1315
- const message = `Message compilation error: ${err.message}`;
1316
- const codeFrame = err.location &&
1317
- generateCodeFrame(source, err.location.start.offset, err.location.end.offset);
1318
- const emitter = context.__v_emitter;
1319
- if (emitter) {
1320
- emitter.emit("compile-error" /* COMPILE_ERROR */, {
1321
- message: source,
1322
- error: err.message,
1323
- start: err.location && err.location.start.offset,
1324
- end: err.location && err.location.end.offset,
1325
- groupId: `${'translate'}:${key}`
1326
- });
1327
- }
1328
- console.error(codeFrame ? `${message}\n${codeFrame}` : message);
1329
- }
1330
- },
1331
- onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
1332
- };
1333
- }
1334
- function getMessageContextOptions(context, locale, message, options) {
1335
- const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
1336
- const resolveMessage = (key) => {
1337
- let val = resolveValue(message, key);
1338
- // fallback to root context
1339
- if (val == null && fallbackContext) {
1340
- const [, , message] = resolveMessageFormat(fallbackContext, key, locale, fallbackLocale, fallbackWarn, missingWarn);
1341
- val = resolveValue(message, key);
1342
- }
1343
- if (isString(val)) {
1344
- let occurred = false;
1345
- const errorDetector = () => {
1346
- occurred = true;
1347
- };
1348
- const msg = compileMessageFormat(context, key, locale, val, key, errorDetector);
1349
- return !occurred
1350
- ? msg
1351
- : NOOP_MESSAGE_FUNCTION;
1352
- }
1353
- else if (isMessageFunction(val)) {
1354
- return val;
1355
- }
1356
- else {
1357
- // TODO: should be implemented warning message
1358
- return NOOP_MESSAGE_FUNCTION;
1359
- }
1360
- };
1361
- const ctxOptions = {
1362
- locale,
1363
- modifiers,
1364
- pluralRules,
1365
- messages: resolveMessage
1366
- };
1367
- if (context.processor) {
1368
- ctxOptions.processor = context.processor;
1369
- }
1370
- if (options.list) {
1371
- ctxOptions.list = options.list;
1372
- }
1373
- if (options.named) {
1374
- ctxOptions.named = options.named;
1375
- }
1376
- if (isNumber(options.plural)) {
1377
- ctxOptions.pluralIndex = options.plural;
1378
- }
1379
- return ctxOptions;
1077
+ let compileCache = Object.create(null);
1078
+ function clearCompileCache() {
1079
+ compileCache = Object.create(null);
1080
+ }
1081
+ const isMessageAST = (val) => isObject(val) &&
1082
+ (val.t === 0 || val.type === 0) &&
1083
+ ('b' in val || 'body' in val);
1084
+ function compileToFunction(message, context) {
1085
+ if (!isString(message)) {
1086
+ throw createCoreError(CoreErrorCodes.NOT_SUPPORT_NON_STRING_MESSAGE);
1087
+ }
1088
+ {
1089
+ warn(`Runtime compilation is not supported in ${'core.runtime.global.js' }.`);
1090
+ return (() => message);
1091
+ }
1092
+ }
1093
+ function compile(message, context) {
1094
+ {
1095
+ if (!isMessageAST(message)) {
1096
+ warn(`the message that is resolve with key '${context.key}' is not supported for jit compilation`);
1097
+ return (() => message);
1098
+ }
1099
+ // AST case (passed from bundler)
1100
+ const cacheKey = message.cacheKey;
1101
+ if (cacheKey) {
1102
+ const cached = compileCache[cacheKey];
1103
+ if (cached) {
1104
+ return cached;
1105
+ }
1106
+ // compose message function from message (AST)
1107
+ return (compileCache[cacheKey] =
1108
+ format(message));
1109
+ }
1110
+ else {
1111
+ return format(message);
1112
+ }
1113
+ }
1380
1114
  }
1381
1115
 
1382
- const intlDefined = typeof Intl !== 'undefined';
1383
- const Availabilities = {
1384
- dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
1385
- numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
1116
+ const NOOP_MESSAGE_FUNCTION = () => '';
1117
+ const isMessageFunction = (val) => isFunction(val);
1118
+ // implementation of `translate` function
1119
+ function translate(context, ...args) {
1120
+ const { fallbackFormat, postTranslation, unresolving, messageCompiler, fallbackLocale, messages } = context;
1121
+ const [key, options] = parseTranslateArgs(...args);
1122
+ const missingWarn = isBoolean(options.missingWarn)
1123
+ ? options.missingWarn
1124
+ : context.missingWarn;
1125
+ const fallbackWarn = isBoolean(options.fallbackWarn)
1126
+ ? options.fallbackWarn
1127
+ : context.fallbackWarn;
1128
+ const escapeParameter = isBoolean(options.escapeParameter)
1129
+ ? options.escapeParameter
1130
+ : context.escapeParameter;
1131
+ const resolvedMessage = !!options.resolvedMessage;
1132
+ // prettier-ignore
1133
+ const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
1134
+ ? !isBoolean(options.default)
1135
+ ? options.default
1136
+ : (!messageCompiler ? () => key : key)
1137
+ : fallbackFormat // default by `fallbackFormat` option
1138
+ ? (!messageCompiler ? () => key : key)
1139
+ : '';
1140
+ const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
1141
+ const locale = isString(options.locale) ? options.locale : context.locale;
1142
+ // escape params
1143
+ escapeParameter && escapeParams(options);
1144
+ // resolve message format
1145
+ // eslint-disable-next-line prefer-const
1146
+ let [formatScope, targetLocale, message] = !resolvedMessage
1147
+ ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
1148
+ : [
1149
+ key,
1150
+ locale,
1151
+ messages[locale] || {}
1152
+ ];
1153
+ // NOTE:
1154
+ // Fix to work around `ssrTransfrom` bug in Vite.
1155
+ // https://github.com/vitejs/vite/issues/4306
1156
+ // To get around this, use temporary variables.
1157
+ // https://github.com/nuxt/framework/issues/1461#issuecomment-954606243
1158
+ let format = formatScope;
1159
+ // if you use default message, set it as message format!
1160
+ let cacheBaseKey = key;
1161
+ if (!resolvedMessage &&
1162
+ !(isString(format) ||
1163
+ isMessageAST(format) ||
1164
+ isMessageFunction(format))) {
1165
+ if (enableDefaultMsg) {
1166
+ format = defaultMsgOrKey;
1167
+ cacheBaseKey = format;
1168
+ }
1169
+ }
1170
+ // checking message format and target locale
1171
+ if (!resolvedMessage &&
1172
+ (!(isString(format) ||
1173
+ isMessageAST(format) ||
1174
+ isMessageFunction(format)) ||
1175
+ !isString(targetLocale))) {
1176
+ return unresolving ? NOT_REOSLVED : key;
1177
+ }
1178
+ // TODO: refactor
1179
+ if (isString(format) && context.messageCompiler == null) {
1180
+ warn(`The message format compilation is not supported in this build. ` +
1181
+ `Because message compiler isn't included. ` +
1182
+ `You need to pre-compilation all message format. ` +
1183
+ `So translate function return '${key}'.`);
1184
+ return key;
1185
+ }
1186
+ // setup compile error detecting
1187
+ let occurred = false;
1188
+ const onError = () => {
1189
+ occurred = true;
1190
+ };
1191
+ // compile message format
1192
+ const msg = !isMessageFunction(format)
1193
+ ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError)
1194
+ : format;
1195
+ // if occurred compile error, return the message format
1196
+ if (occurred) {
1197
+ return format;
1198
+ }
1199
+ // evaluate message with context
1200
+ const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
1201
+ const msgContext = createMessageContext(ctxOptions);
1202
+ const messaged = evaluateMessage(context, msg, msgContext);
1203
+ // if use post translation option, proceed it with handler
1204
+ const ret = postTranslation
1205
+ ? postTranslation(messaged, key)
1206
+ : messaged;
1207
+ // NOTE: experimental !!
1208
+ {
1209
+ // prettier-ignore
1210
+ const payloads = {
1211
+ timestamp: Date.now(),
1212
+ key: isString(key)
1213
+ ? key
1214
+ : isMessageFunction(format)
1215
+ ? format.key
1216
+ : '',
1217
+ locale: targetLocale || (isMessageFunction(format)
1218
+ ? format.locale
1219
+ : ''),
1220
+ format: isString(format)
1221
+ ? format
1222
+ : isMessageFunction(format)
1223
+ ? format.source
1224
+ : '',
1225
+ message: ret
1226
+ };
1227
+ payloads.meta = assign({}, context.__meta, getAdditionalMeta() || {});
1228
+ translateDevTools(payloads);
1229
+ }
1230
+ return ret;
1231
+ }
1232
+ function escapeParams(options) {
1233
+ if (isArray(options.list)) {
1234
+ options.list = options.list.map(item => isString(item) ? escapeHtml(item) : item);
1235
+ }
1236
+ else if (isObject(options.named)) {
1237
+ Object.keys(options.named).forEach(key => {
1238
+ if (isString(options.named[key])) {
1239
+ options.named[key] = escapeHtml(options.named[key]);
1240
+ }
1241
+ });
1242
+ }
1243
+ }
1244
+ function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
1245
+ const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
1246
+ const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
1247
+ let message = {};
1248
+ let targetLocale;
1249
+ let format = null;
1250
+ let from = locale;
1251
+ let to = null;
1252
+ const type = 'translate';
1253
+ for (let i = 0; i < locales.length; i++) {
1254
+ targetLocale = to = locales[i];
1255
+ if (locale !== targetLocale &&
1256
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1257
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
1258
+ key,
1259
+ target: targetLocale
1260
+ }));
1261
+ }
1262
+ // for vue-devtools timeline event
1263
+ if (locale !== targetLocale) {
1264
+ const emitter = context.__v_emitter;
1265
+ if (emitter) {
1266
+ emitter.emit("fallback" /* VueDevToolsTimelineEvents.FALBACK */, {
1267
+ type,
1268
+ key,
1269
+ from,
1270
+ to,
1271
+ groupId: `${type}:${key}`
1272
+ });
1273
+ }
1274
+ }
1275
+ message =
1276
+ messages[targetLocale] || {};
1277
+ // for vue-devtools timeline event
1278
+ let start = null;
1279
+ let startTag;
1280
+ let endTag;
1281
+ if (inBrowser) {
1282
+ start = window.performance.now();
1283
+ startTag = 'intlify-message-resolve-start';
1284
+ endTag = 'intlify-message-resolve-end';
1285
+ mark && mark(startTag);
1286
+ }
1287
+ if ((format = resolveValue(message, key)) === null) {
1288
+ // if null, resolve with object key path
1289
+ format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
1290
+ }
1291
+ // for vue-devtools timeline event
1292
+ if (inBrowser) {
1293
+ const end = window.performance.now();
1294
+ const emitter = context.__v_emitter;
1295
+ if (emitter && start && format) {
1296
+ emitter.emit("message-resolve" /* VueDevToolsTimelineEvents.MESSAGE_RESOLVE */, {
1297
+ type: "message-resolve" /* VueDevToolsTimelineEvents.MESSAGE_RESOLVE */,
1298
+ key,
1299
+ message: format,
1300
+ time: end - start,
1301
+ groupId: `${type}:${key}`
1302
+ });
1303
+ }
1304
+ if (startTag && endTag && mark && measure) {
1305
+ mark(endTag);
1306
+ measure('intlify message resolve', startTag, endTag);
1307
+ }
1308
+ }
1309
+ if (isString(format) || isMessageAST(format) || isMessageFunction(format)) {
1310
+ break;
1311
+ }
1312
+ const missingRet = handleMissing(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1313
+ key, targetLocale, missingWarn, type);
1314
+ if (missingRet !== key) {
1315
+ format = missingRet;
1316
+ }
1317
+ from = to;
1318
+ }
1319
+ return [format, targetLocale, message];
1320
+ }
1321
+ function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, onError) {
1322
+ const { messageCompiler, warnHtmlMessage } = context;
1323
+ if (isMessageFunction(format)) {
1324
+ const msg = format;
1325
+ msg.locale = msg.locale || targetLocale;
1326
+ msg.key = msg.key || key;
1327
+ return msg;
1328
+ }
1329
+ if (messageCompiler == null) {
1330
+ const msg = (() => format);
1331
+ msg.locale = targetLocale;
1332
+ msg.key = key;
1333
+ return msg;
1334
+ }
1335
+ // for vue-devtools timeline event
1336
+ let start = null;
1337
+ let startTag;
1338
+ let endTag;
1339
+ if (inBrowser) {
1340
+ start = window.performance.now();
1341
+ startTag = 'intlify-message-compilation-start';
1342
+ endTag = 'intlify-message-compilation-end';
1343
+ mark && mark(startTag);
1344
+ }
1345
+ const msg = messageCompiler(format, getCompileContext(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, onError));
1346
+ // for vue-devtools timeline event
1347
+ if (inBrowser) {
1348
+ const end = window.performance.now();
1349
+ const emitter = context.__v_emitter;
1350
+ if (emitter && start) {
1351
+ emitter.emit("message-compilation" /* VueDevToolsTimelineEvents.MESSAGE_COMPILATION */, {
1352
+ type: "message-compilation" /* VueDevToolsTimelineEvents.MESSAGE_COMPILATION */,
1353
+ message: format,
1354
+ time: end - start,
1355
+ groupId: `${'translate'}:${key}`
1356
+ });
1357
+ }
1358
+ if (startTag && endTag && mark && measure) {
1359
+ mark(endTag);
1360
+ measure('intlify message compilation', startTag, endTag);
1361
+ }
1362
+ }
1363
+ msg.locale = targetLocale;
1364
+ msg.key = key;
1365
+ msg.source = format;
1366
+ return msg;
1367
+ }
1368
+ function evaluateMessage(context, msg, msgCtx) {
1369
+ // for vue-devtools timeline event
1370
+ let start = null;
1371
+ let startTag;
1372
+ let endTag;
1373
+ if (inBrowser) {
1374
+ start = window.performance.now();
1375
+ startTag = 'intlify-message-evaluation-start';
1376
+ endTag = 'intlify-message-evaluation-end';
1377
+ mark && mark(startTag);
1378
+ }
1379
+ const messaged = msg(msgCtx);
1380
+ // for vue-devtools timeline event
1381
+ if (inBrowser) {
1382
+ const end = window.performance.now();
1383
+ const emitter = context.__v_emitter;
1384
+ if (emitter && start) {
1385
+ emitter.emit("message-evaluation" /* VueDevToolsTimelineEvents.MESSAGE_EVALUATION */, {
1386
+ type: "message-evaluation" /* VueDevToolsTimelineEvents.MESSAGE_EVALUATION */,
1387
+ value: messaged,
1388
+ time: end - start,
1389
+ groupId: `${'translate'}:${msg.key}`
1390
+ });
1391
+ }
1392
+ if (startTag && endTag && mark && measure) {
1393
+ mark(endTag);
1394
+ measure('intlify message evaluation', startTag, endTag);
1395
+ }
1396
+ }
1397
+ return messaged;
1398
+ }
1399
+ /** @internal */
1400
+ function parseTranslateArgs(...args) {
1401
+ const [arg1, arg2, arg3] = args;
1402
+ const options = {};
1403
+ if (!isString(arg1) &&
1404
+ !isNumber(arg1) &&
1405
+ !isMessageFunction(arg1) &&
1406
+ !isMessageAST(arg1)) {
1407
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1408
+ }
1409
+ // prettier-ignore
1410
+ const key = isNumber(arg1)
1411
+ ? String(arg1)
1412
+ : isMessageFunction(arg1)
1413
+ ? arg1
1414
+ : arg1;
1415
+ if (isNumber(arg2)) {
1416
+ options.plural = arg2;
1417
+ }
1418
+ else if (isString(arg2)) {
1419
+ options.default = arg2;
1420
+ }
1421
+ else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
1422
+ options.named = arg2;
1423
+ }
1424
+ else if (isArray(arg2)) {
1425
+ options.list = arg2;
1426
+ }
1427
+ if (isNumber(arg3)) {
1428
+ options.plural = arg3;
1429
+ }
1430
+ else if (isString(arg3)) {
1431
+ options.default = arg3;
1432
+ }
1433
+ else if (isPlainObject(arg3)) {
1434
+ assign(options, arg3);
1435
+ }
1436
+ return [key, options];
1437
+ }
1438
+ function getCompileContext(context, locale, key, source, warnHtmlMessage, onError) {
1439
+ return {
1440
+ locale,
1441
+ key,
1442
+ warnHtmlMessage,
1443
+ onError: (err) => {
1444
+ onError && onError(err);
1445
+ {
1446
+ const _source = getSourceForCodeFrame(source);
1447
+ const message = `Message compilation error: ${err.message}`;
1448
+ const codeFrame = err.location &&
1449
+ _source &&
1450
+ generateCodeFrame(_source, err.location.start.offset, err.location.end.offset);
1451
+ const emitter = context.__v_emitter;
1452
+ if (emitter && _source) {
1453
+ emitter.emit("compile-error" /* VueDevToolsTimelineEvents.COMPILE_ERROR */, {
1454
+ message: _source,
1455
+ error: err.message,
1456
+ start: err.location && err.location.start.offset,
1457
+ end: err.location && err.location.end.offset,
1458
+ groupId: `${'translate'}:${key}`
1459
+ });
1460
+ }
1461
+ console.error(codeFrame ? `${message}\n${codeFrame}` : message);
1462
+ }
1463
+ },
1464
+ onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
1465
+ };
1466
+ }
1467
+ function getSourceForCodeFrame(source) {
1468
+ if (isString(source)) ;
1469
+ else {
1470
+ if (source.loc?.source) {
1471
+ return source.loc.source;
1472
+ }
1473
+ }
1474
+ }
1475
+ function getMessageContextOptions(context, locale, message, options) {
1476
+ const { modifiers, pluralRules, messageResolver: resolveValue, fallbackLocale, fallbackWarn, missingWarn, fallbackContext } = context;
1477
+ const resolveMessage = (key) => {
1478
+ let val = resolveValue(message, key);
1479
+ // fallback to root context
1480
+ if (val == null && fallbackContext) {
1481
+ const [, , message] = resolveMessageFormat(fallbackContext, key, locale, fallbackLocale, fallbackWarn, missingWarn);
1482
+ val = resolveValue(message, key);
1483
+ }
1484
+ if (isString(val) || isMessageAST(val)) {
1485
+ let occurred = false;
1486
+ const onError = () => {
1487
+ occurred = true;
1488
+ };
1489
+ const msg = compileMessageFormat(context, key, locale, val, key, onError);
1490
+ return !occurred
1491
+ ? msg
1492
+ : NOOP_MESSAGE_FUNCTION;
1493
+ }
1494
+ else if (isMessageFunction(val)) {
1495
+ return val;
1496
+ }
1497
+ else {
1498
+ // TODO: should be implemented warning message
1499
+ return NOOP_MESSAGE_FUNCTION;
1500
+ }
1501
+ };
1502
+ const ctxOptions = {
1503
+ locale,
1504
+ modifiers,
1505
+ pluralRules,
1506
+ messages: resolveMessage
1507
+ };
1508
+ if (context.processor) {
1509
+ ctxOptions.processor = context.processor;
1510
+ }
1511
+ if (options.list) {
1512
+ ctxOptions.list = options.list;
1513
+ }
1514
+ if (options.named) {
1515
+ ctxOptions.named = options.named;
1516
+ }
1517
+ if (isNumber(options.plural)) {
1518
+ ctxOptions.pluralIndex = options.plural;
1519
+ }
1520
+ return ctxOptions;
1521
+ }
1522
+
1523
+ const intlDefined = typeof Intl !== 'undefined';
1524
+ const Availabilities = {
1525
+ dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
1526
+ numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
1386
1527
  };
1387
1528
 
1388
- // implementation of `datetime` function
1389
- function datetime(context, ...args) {
1390
- const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1391
- const { __datetimeFormatters } = context;
1392
- if (!Availabilities.dateTimeFormat) {
1393
- onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
1394
- return MISSING_RESOLVE_VALUE;
1395
- }
1396
- const [key, value, options, overrides] = parseDateTimeArgs(...args);
1397
- const missingWarn = isBoolean(options.missingWarn)
1398
- ? options.missingWarn
1399
- : context.missingWarn;
1400
- const fallbackWarn = isBoolean(options.fallbackWarn)
1401
- ? options.fallbackWarn
1402
- : context.fallbackWarn;
1403
- const part = !!options.part;
1404
- const locale = isString(options.locale) ? options.locale : context.locale;
1405
- const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1406
- fallbackLocale, locale);
1407
- if (!isString(key) || key === '') {
1408
- return new Intl.DateTimeFormat(locale, overrides).format(value);
1409
- }
1410
- // resolve format
1411
- let datetimeFormat = {};
1412
- let targetLocale;
1413
- let format = null;
1414
- let from = locale;
1415
- let to = null;
1416
- const type = 'datetime format';
1417
- for (let i = 0; i < locales.length; i++) {
1418
- targetLocale = to = locales[i];
1419
- if (locale !== targetLocale &&
1420
- isTranslateFallbackWarn(fallbackWarn, key)) {
1421
- onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
1422
- key,
1423
- target: targetLocale
1424
- }));
1425
- }
1426
- // for vue-devtools timeline event
1427
- if (locale !== targetLocale) {
1428
- const emitter = context.__v_emitter;
1429
- if (emitter) {
1430
- emitter.emit("fallback" /* FALBACK */, {
1431
- type,
1432
- key,
1433
- from,
1434
- to,
1435
- groupId: `${type}:${key}`
1436
- });
1437
- }
1438
- }
1439
- datetimeFormat =
1440
- datetimeFormats[targetLocale] || {};
1441
- format = datetimeFormat[key];
1442
- if (isPlainObject(format))
1443
- break;
1444
- handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1445
- from = to;
1446
- }
1447
- // checking format and target locale
1448
- if (!isPlainObject(format) || !isString(targetLocale)) {
1449
- return unresolving ? NOT_REOSLVED : key;
1450
- }
1451
- let id = `${targetLocale}__${key}`;
1452
- if (!isEmptyObject(overrides)) {
1453
- id = `${id}__${JSON.stringify(overrides)}`;
1454
- }
1455
- let formatter = __datetimeFormatters.get(id);
1456
- if (!formatter) {
1457
- formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
1458
- __datetimeFormatters.set(id, formatter);
1459
- }
1460
- return !part ? formatter.format(value) : formatter.formatToParts(value);
1461
- }
1462
- /** @internal */
1463
- const DATETIME_FORMAT_OPTIONS_KEYS = [
1464
- 'localeMatcher',
1465
- 'weekday',
1466
- 'era',
1467
- 'year',
1468
- 'month',
1469
- 'day',
1470
- 'hour',
1471
- 'minute',
1472
- 'second',
1473
- 'timeZoneName',
1474
- 'formatMatcher',
1475
- 'hour12',
1476
- 'timeZone',
1477
- 'dateStyle',
1478
- 'timeStyle',
1479
- 'calendar',
1480
- 'dayPeriod',
1481
- 'numberingSystem',
1482
- 'hourCycle',
1483
- 'fractionalSecondDigits'
1484
- ];
1485
- /** @internal */
1486
- function parseDateTimeArgs(...args) {
1487
- const [arg1, arg2, arg3, arg4] = args;
1488
- const options = {};
1489
- let overrides = {};
1490
- let value;
1491
- if (isString(arg1)) {
1492
- // Only allow ISO strings - other date formats are often supported,
1493
- // but may cause different results in different browsers.
1494
- const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
1495
- if (!matches) {
1496
- throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1497
- }
1498
- // Some browsers can not parse the iso datetime separated by space,
1499
- // this is a compromise solution by replace the 'T'/' ' with 'T'
1500
- const dateTime = matches[3]
1501
- ? matches[3].trim().startsWith('T')
1502
- ? `${matches[1].trim()}${matches[3].trim()}`
1503
- : `${matches[1].trim()}T${matches[3].trim()}`
1504
- : matches[1].trim();
1505
- value = new Date(dateTime);
1506
- try {
1507
- // This will fail if the date is not valid
1508
- value.toISOString();
1509
- }
1510
- catch (e) {
1511
- throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1512
- }
1513
- }
1514
- else if (isDate(arg1)) {
1515
- if (isNaN(arg1.getTime())) {
1516
- throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
1517
- }
1518
- value = arg1;
1519
- }
1520
- else if (isNumber(arg1)) {
1521
- value = arg1;
1522
- }
1523
- else {
1524
- throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1525
- }
1526
- if (isString(arg2)) {
1527
- options.key = arg2;
1528
- }
1529
- else if (isPlainObject(arg2)) {
1530
- Object.keys(arg2).forEach(key => {
1531
- if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
1532
- overrides[key] = arg2[key];
1533
- }
1534
- else {
1535
- options[key] = arg2[key];
1536
- }
1537
- });
1538
- }
1539
- if (isString(arg3)) {
1540
- options.locale = arg3;
1541
- }
1542
- else if (isPlainObject(arg3)) {
1543
- overrides = arg3;
1544
- }
1545
- if (isPlainObject(arg4)) {
1546
- overrides = arg4;
1547
- }
1548
- return [options.key || '', value, options, overrides];
1549
- }
1550
- /** @internal */
1551
- function clearDateTimeFormat(ctx, locale, format) {
1552
- const context = ctx;
1553
- for (const key in format) {
1554
- const id = `${locale}__${key}`;
1555
- if (!context.__datetimeFormatters.has(id)) {
1556
- continue;
1557
- }
1558
- context.__datetimeFormatters.delete(id);
1559
- }
1529
+ // implementation of `datetime` function
1530
+ function datetime(context, ...args) {
1531
+ const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1532
+ const { __datetimeFormatters } = context;
1533
+ if (!Availabilities.dateTimeFormat) {
1534
+ onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_DATE));
1535
+ return MISSING_RESOLVE_VALUE;
1536
+ }
1537
+ const [key, value, options, overrides] = parseDateTimeArgs(...args);
1538
+ const missingWarn = isBoolean(options.missingWarn)
1539
+ ? options.missingWarn
1540
+ : context.missingWarn;
1541
+ const fallbackWarn = isBoolean(options.fallbackWarn)
1542
+ ? options.fallbackWarn
1543
+ : context.fallbackWarn;
1544
+ const part = !!options.part;
1545
+ const locale = isString(options.locale) ? options.locale : context.locale;
1546
+ const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1547
+ fallbackLocale, locale);
1548
+ if (!isString(key) || key === '') {
1549
+ return new Intl.DateTimeFormat(locale, overrides).format(value);
1550
+ }
1551
+ // resolve format
1552
+ let datetimeFormat = {};
1553
+ let targetLocale;
1554
+ let format = null;
1555
+ let from = locale;
1556
+ let to = null;
1557
+ const type = 'datetime format';
1558
+ for (let i = 0; i < locales.length; i++) {
1559
+ targetLocale = to = locales[i];
1560
+ if (locale !== targetLocale &&
1561
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1562
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
1563
+ key,
1564
+ target: targetLocale
1565
+ }));
1566
+ }
1567
+ // for vue-devtools timeline event
1568
+ if (locale !== targetLocale) {
1569
+ const emitter = context.__v_emitter;
1570
+ if (emitter) {
1571
+ emitter.emit("fallback" /* VueDevToolsTimelineEvents.FALBACK */, {
1572
+ type,
1573
+ key,
1574
+ from,
1575
+ to,
1576
+ groupId: `${type}:${key}`
1577
+ });
1578
+ }
1579
+ }
1580
+ datetimeFormat =
1581
+ datetimeFormats[targetLocale] || {};
1582
+ format = datetimeFormat[key];
1583
+ if (isPlainObject(format))
1584
+ break;
1585
+ handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1586
+ from = to;
1587
+ }
1588
+ // checking format and target locale
1589
+ if (!isPlainObject(format) || !isString(targetLocale)) {
1590
+ return unresolving ? NOT_REOSLVED : key;
1591
+ }
1592
+ let id = `${targetLocale}__${key}`;
1593
+ if (!isEmptyObject(overrides)) {
1594
+ id = `${id}__${JSON.stringify(overrides)}`;
1595
+ }
1596
+ let formatter = __datetimeFormatters.get(id);
1597
+ if (!formatter) {
1598
+ formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
1599
+ __datetimeFormatters.set(id, formatter);
1600
+ }
1601
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1602
+ }
1603
+ /** @internal */
1604
+ const DATETIME_FORMAT_OPTIONS_KEYS = [
1605
+ 'localeMatcher',
1606
+ 'weekday',
1607
+ 'era',
1608
+ 'year',
1609
+ 'month',
1610
+ 'day',
1611
+ 'hour',
1612
+ 'minute',
1613
+ 'second',
1614
+ 'timeZoneName',
1615
+ 'formatMatcher',
1616
+ 'hour12',
1617
+ 'timeZone',
1618
+ 'dateStyle',
1619
+ 'timeStyle',
1620
+ 'calendar',
1621
+ 'dayPeriod',
1622
+ 'numberingSystem',
1623
+ 'hourCycle',
1624
+ 'fractionalSecondDigits'
1625
+ ];
1626
+ /** @internal */
1627
+ function parseDateTimeArgs(...args) {
1628
+ const [arg1, arg2, arg3, arg4] = args;
1629
+ const options = {};
1630
+ let overrides = {};
1631
+ let value;
1632
+ if (isString(arg1)) {
1633
+ // Only allow ISO strings - other date formats are often supported,
1634
+ // but may cause different results in different browsers.
1635
+ const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
1636
+ if (!matches) {
1637
+ throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1638
+ }
1639
+ // Some browsers can not parse the iso datetime separated by space,
1640
+ // this is a compromise solution by replace the 'T'/' ' with 'T'
1641
+ const dateTime = matches[3]
1642
+ ? matches[3].trim().startsWith('T')
1643
+ ? `${matches[1].trim()}${matches[3].trim()}`
1644
+ : `${matches[1].trim()}T${matches[3].trim()}`
1645
+ : matches[1].trim();
1646
+ value = new Date(dateTime);
1647
+ try {
1648
+ // This will fail if the date is not valid
1649
+ value.toISOString();
1650
+ }
1651
+ catch (e) {
1652
+ throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1653
+ }
1654
+ }
1655
+ else if (isDate(arg1)) {
1656
+ if (isNaN(arg1.getTime())) {
1657
+ throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
1658
+ }
1659
+ value = arg1;
1660
+ }
1661
+ else if (isNumber(arg1)) {
1662
+ value = arg1;
1663
+ }
1664
+ else {
1665
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1666
+ }
1667
+ if (isString(arg2)) {
1668
+ options.key = arg2;
1669
+ }
1670
+ else if (isPlainObject(arg2)) {
1671
+ Object.keys(arg2).forEach(key => {
1672
+ if (DATETIME_FORMAT_OPTIONS_KEYS.includes(key)) {
1673
+ overrides[key] = arg2[key];
1674
+ }
1675
+ else {
1676
+ options[key] = arg2[key];
1677
+ }
1678
+ });
1679
+ }
1680
+ if (isString(arg3)) {
1681
+ options.locale = arg3;
1682
+ }
1683
+ else if (isPlainObject(arg3)) {
1684
+ overrides = arg3;
1685
+ }
1686
+ if (isPlainObject(arg4)) {
1687
+ overrides = arg4;
1688
+ }
1689
+ return [options.key || '', value, options, overrides];
1690
+ }
1691
+ /** @internal */
1692
+ function clearDateTimeFormat(ctx, locale, format) {
1693
+ const context = ctx;
1694
+ for (const key in format) {
1695
+ const id = `${locale}__${key}`;
1696
+ if (!context.__datetimeFormatters.has(id)) {
1697
+ continue;
1698
+ }
1699
+ context.__datetimeFormatters.delete(id);
1700
+ }
1560
1701
  }
1561
1702
 
1562
- // implementation of `number` function
1563
- function number(context, ...args) {
1564
- const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1565
- const { __numberFormatters } = context;
1566
- if (!Availabilities.numberFormat) {
1567
- onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
1568
- return MISSING_RESOLVE_VALUE;
1569
- }
1570
- const [key, value, options, overrides] = parseNumberArgs(...args);
1571
- const missingWarn = isBoolean(options.missingWarn)
1572
- ? options.missingWarn
1573
- : context.missingWarn;
1574
- const fallbackWarn = isBoolean(options.fallbackWarn)
1575
- ? options.fallbackWarn
1576
- : context.fallbackWarn;
1577
- const part = !!options.part;
1578
- const locale = isString(options.locale) ? options.locale : context.locale;
1579
- const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1580
- fallbackLocale, locale);
1581
- if (!isString(key) || key === '') {
1582
- return new Intl.NumberFormat(locale, overrides).format(value);
1583
- }
1584
- // resolve format
1585
- let numberFormat = {};
1586
- let targetLocale;
1587
- let format = null;
1588
- let from = locale;
1589
- let to = null;
1590
- const type = 'number format';
1591
- for (let i = 0; i < locales.length; i++) {
1592
- targetLocale = to = locales[i];
1593
- if (locale !== targetLocale &&
1594
- isTranslateFallbackWarn(fallbackWarn, key)) {
1595
- onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
1596
- key,
1597
- target: targetLocale
1598
- }));
1599
- }
1600
- // for vue-devtools timeline event
1601
- if (locale !== targetLocale) {
1602
- const emitter = context.__v_emitter;
1603
- if (emitter) {
1604
- emitter.emit("fallback" /* FALBACK */, {
1605
- type,
1606
- key,
1607
- from,
1608
- to,
1609
- groupId: `${type}:${key}`
1610
- });
1611
- }
1612
- }
1613
- numberFormat =
1614
- numberFormats[targetLocale] || {};
1615
- format = numberFormat[key];
1616
- if (isPlainObject(format))
1617
- break;
1618
- handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1619
- from = to;
1620
- }
1621
- // checking format and target locale
1622
- if (!isPlainObject(format) || !isString(targetLocale)) {
1623
- return unresolving ? NOT_REOSLVED : key;
1624
- }
1625
- let id = `${targetLocale}__${key}`;
1626
- if (!isEmptyObject(overrides)) {
1627
- id = `${id}__${JSON.stringify(overrides)}`;
1628
- }
1629
- let formatter = __numberFormatters.get(id);
1630
- if (!formatter) {
1631
- formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
1632
- __numberFormatters.set(id, formatter);
1633
- }
1634
- return !part ? formatter.format(value) : formatter.formatToParts(value);
1635
- }
1636
- /** @internal */
1637
- const NUMBER_FORMAT_OPTIONS_KEYS = [
1638
- 'localeMatcher',
1639
- 'style',
1640
- 'currency',
1641
- 'currencyDisplay',
1642
- 'currencySign',
1643
- 'useGrouping',
1644
- 'minimumIntegerDigits',
1645
- 'minimumFractionDigits',
1646
- 'maximumFractionDigits',
1647
- 'minimumSignificantDigits',
1648
- 'maximumSignificantDigits',
1649
- 'compactDisplay',
1650
- 'notation',
1651
- 'signDisplay',
1652
- 'unit',
1653
- 'unitDisplay',
1654
- 'roundingMode',
1655
- 'roundingPriority',
1656
- 'roundingIncrement',
1657
- 'trailingZeroDisplay'
1658
- ];
1659
- /** @internal */
1660
- function parseNumberArgs(...args) {
1661
- const [arg1, arg2, arg3, arg4] = args;
1662
- const options = {};
1663
- let overrides = {};
1664
- if (!isNumber(arg1)) {
1665
- throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1666
- }
1667
- const value = arg1;
1668
- if (isString(arg2)) {
1669
- options.key = arg2;
1670
- }
1671
- else if (isPlainObject(arg2)) {
1672
- Object.keys(arg2).forEach(key => {
1673
- if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
1674
- overrides[key] = arg2[key];
1675
- }
1676
- else {
1677
- options[key] = arg2[key];
1678
- }
1679
- });
1680
- }
1681
- if (isString(arg3)) {
1682
- options.locale = arg3;
1683
- }
1684
- else if (isPlainObject(arg3)) {
1685
- overrides = arg3;
1686
- }
1687
- if (isPlainObject(arg4)) {
1688
- overrides = arg4;
1689
- }
1690
- return [options.key || '', value, options, overrides];
1691
- }
1692
- /** @internal */
1693
- function clearNumberFormat(ctx, locale, format) {
1694
- const context = ctx;
1695
- for (const key in format) {
1696
- const id = `${locale}__${key}`;
1697
- if (!context.__numberFormatters.has(id)) {
1698
- continue;
1699
- }
1700
- context.__numberFormatters.delete(id);
1701
- }
1703
+ // implementation of `number` function
1704
+ function number(context, ...args) {
1705
+ const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1706
+ const { __numberFormatters } = context;
1707
+ if (!Availabilities.numberFormat) {
1708
+ onWarn(getWarnMessage(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
1709
+ return MISSING_RESOLVE_VALUE;
1710
+ }
1711
+ const [key, value, options, overrides] = parseNumberArgs(...args);
1712
+ const missingWarn = isBoolean(options.missingWarn)
1713
+ ? options.missingWarn
1714
+ : context.missingWarn;
1715
+ const fallbackWarn = isBoolean(options.fallbackWarn)
1716
+ ? options.fallbackWarn
1717
+ : context.fallbackWarn;
1718
+ const part = !!options.part;
1719
+ const locale = isString(options.locale) ? options.locale : context.locale;
1720
+ const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1721
+ fallbackLocale, locale);
1722
+ if (!isString(key) || key === '') {
1723
+ return new Intl.NumberFormat(locale, overrides).format(value);
1724
+ }
1725
+ // resolve format
1726
+ let numberFormat = {};
1727
+ let targetLocale;
1728
+ let format = null;
1729
+ let from = locale;
1730
+ let to = null;
1731
+ const type = 'number format';
1732
+ for (let i = 0; i < locales.length; i++) {
1733
+ targetLocale = to = locales[i];
1734
+ if (locale !== targetLocale &&
1735
+ isTranslateFallbackWarn(fallbackWarn, key)) {
1736
+ onWarn(getWarnMessage(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
1737
+ key,
1738
+ target: targetLocale
1739
+ }));
1740
+ }
1741
+ // for vue-devtools timeline event
1742
+ if (locale !== targetLocale) {
1743
+ const emitter = context.__v_emitter;
1744
+ if (emitter) {
1745
+ emitter.emit("fallback" /* VueDevToolsTimelineEvents.FALBACK */, {
1746
+ type,
1747
+ key,
1748
+ from,
1749
+ to,
1750
+ groupId: `${type}:${key}`
1751
+ });
1752
+ }
1753
+ }
1754
+ numberFormat =
1755
+ numberFormats[targetLocale] || {};
1756
+ format = numberFormat[key];
1757
+ if (isPlainObject(format))
1758
+ break;
1759
+ handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1760
+ from = to;
1761
+ }
1762
+ // checking format and target locale
1763
+ if (!isPlainObject(format) || !isString(targetLocale)) {
1764
+ return unresolving ? NOT_REOSLVED : key;
1765
+ }
1766
+ let id = `${targetLocale}__${key}`;
1767
+ if (!isEmptyObject(overrides)) {
1768
+ id = `${id}__${JSON.stringify(overrides)}`;
1769
+ }
1770
+ let formatter = __numberFormatters.get(id);
1771
+ if (!formatter) {
1772
+ formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
1773
+ __numberFormatters.set(id, formatter);
1774
+ }
1775
+ return !part ? formatter.format(value) : formatter.formatToParts(value);
1776
+ }
1777
+ /** @internal */
1778
+ const NUMBER_FORMAT_OPTIONS_KEYS = [
1779
+ 'localeMatcher',
1780
+ 'style',
1781
+ 'currency',
1782
+ 'currencyDisplay',
1783
+ 'currencySign',
1784
+ 'useGrouping',
1785
+ 'minimumIntegerDigits',
1786
+ 'minimumFractionDigits',
1787
+ 'maximumFractionDigits',
1788
+ 'minimumSignificantDigits',
1789
+ 'maximumSignificantDigits',
1790
+ 'compactDisplay',
1791
+ 'notation',
1792
+ 'signDisplay',
1793
+ 'unit',
1794
+ 'unitDisplay',
1795
+ 'roundingMode',
1796
+ 'roundingPriority',
1797
+ 'roundingIncrement',
1798
+ 'trailingZeroDisplay'
1799
+ ];
1800
+ /** @internal */
1801
+ function parseNumberArgs(...args) {
1802
+ const [arg1, arg2, arg3, arg4] = args;
1803
+ const options = {};
1804
+ let overrides = {};
1805
+ if (!isNumber(arg1)) {
1806
+ throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1807
+ }
1808
+ const value = arg1;
1809
+ if (isString(arg2)) {
1810
+ options.key = arg2;
1811
+ }
1812
+ else if (isPlainObject(arg2)) {
1813
+ Object.keys(arg2).forEach(key => {
1814
+ if (NUMBER_FORMAT_OPTIONS_KEYS.includes(key)) {
1815
+ overrides[key] = arg2[key];
1816
+ }
1817
+ else {
1818
+ options[key] = arg2[key];
1819
+ }
1820
+ });
1821
+ }
1822
+ if (isString(arg3)) {
1823
+ options.locale = arg3;
1824
+ }
1825
+ else if (isPlainObject(arg3)) {
1826
+ overrides = arg3;
1827
+ }
1828
+ if (isPlainObject(arg4)) {
1829
+ overrides = arg4;
1830
+ }
1831
+ return [options.key || '', value, options, overrides];
1832
+ }
1833
+ /** @internal */
1834
+ function clearNumberFormat(ctx, locale, format) {
1835
+ const context = ctx;
1836
+ for (const key in format) {
1837
+ const id = `${locale}__${key}`;
1838
+ if (!context.__numberFormatters.has(id)) {
1839
+ continue;
1840
+ }
1841
+ context.__numberFormatters.delete(id);
1842
+ }
1702
1843
  }
1703
1844
 
1704
- // register message resolver at @intlify/core
1705
- registerMessageResolver(resolveValue);
1706
- // register fallback locale at @intlify/core
1845
+ // register message resolver at @intlify/core
1846
+ registerMessageResolver(resolveValue);
1847
+ // register fallback locale at @intlify/core
1707
1848
  registerLocaleFallbacker(fallbackWithLocaleChain);
1708
1849
 
1709
1850
  exports.CompileErrorCodes = CompileErrorCodes;
@@ -1719,6 +1860,7 @@ var IntlifyCore = (function (exports) {
1719
1860
  exports.clearCompileCache = clearCompileCache;
1720
1861
  exports.clearDateTimeFormat = clearDateTimeFormat;
1721
1862
  exports.clearNumberFormat = clearNumberFormat;
1863
+ exports.compile = compile;
1722
1864
  exports.compileToFunction = compileToFunction;
1723
1865
  exports.createCompileError = createCompileError;
1724
1866
  exports.createCoreContext = createCoreContext;
@@ -1733,6 +1875,7 @@ var IntlifyCore = (function (exports) {
1733
1875
  exports.getWarnMessage = getWarnMessage;
1734
1876
  exports.handleMissing = handleMissing;
1735
1877
  exports.initI18nDevTools = initI18nDevTools;
1878
+ exports.isMessageAST = isMessageAST;
1736
1879
  exports.isMessageFunction = isMessageFunction;
1737
1880
  exports.isTranslateFallbackWarn = isTranslateFallbackWarn;
1738
1881
  exports.isTranslateMissingWarn = isTranslateMissingWarn;
@@ -1753,8 +1896,6 @@ var IntlifyCore = (function (exports) {
1753
1896
  exports.translateDevTools = translateDevTools;
1754
1897
  exports.updateFallbackLocale = updateFallbackLocale;
1755
1898
 
1756
- Object.defineProperty(exports, '__esModule', { value: true });
1757
-
1758
1899
  return exports;
1759
1900
 
1760
1901
  })({});