@intlify/core-base 11.1.2 → 12.0.0-alpha.2

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