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