UNPKG

99.2 kBJavaScriptView Raw
1/*!
2 * vue-i18n-bridge v9.2.0-beta.6
3 * (c) 2021 kazuya kawaguchi
4 * Released under the MIT License.
5 */
6var VueI18nBridge = (function (exports, compositionApi) {
7 'use strict';
8
9 /**
10 * Original Utilities
11 * written by kazuya kawaguchi
12 */
13 const inBrowser = typeof window !== 'undefined';
14 let mark;
15 {
16 const perf = inBrowser && window.performance;
17 if (perf &&
18 perf.mark &&
19 perf.measure &&
20 perf.clearMarks &&
21 perf.clearMeasures) {
22 mark = (tag) => perf.mark(tag);
23 }
24 }
25 const RE_ARGS = /\{([0-9a-zA-Z]+)\}/g;
26 /* eslint-disable */
27 function format(message, ...args) {
28 if (args.length === 1 && isObject(args[0])) {
29 args = args[0];
30 }
31 if (!args || !args.hasOwnProperty) {
32 args = {};
33 }
34 return message.replace(RE_ARGS, (match, identifier) => {
35 return args.hasOwnProperty(identifier) ? args[identifier] : '';
36 });
37 }
38 const hasSymbol = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
39 const makeSymbol = (name) => hasSymbol ? Symbol(name) : name;
40 const generateFormatCacheKey = (locale, key, source) => friendlyJSONstringify({ l: locale, k: key, s: source });
41 const friendlyJSONstringify = (json) => JSON.stringify(json)
42 .replace(/\u2028/g, '\\u2028')
43 .replace(/\u2029/g, '\\u2029')
44 .replace(/\u0027/g, '\\u0027');
45 const isNumber = (val) => typeof val === 'number' && isFinite(val);
46 const isDate = (val) => toTypeString(val) === '[object Date]';
47 const isRegExp = (val) => toTypeString(val) === '[object RegExp]';
48 const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
49 function warn(msg, err) {
50 if (typeof console !== 'undefined') {
51 console.warn(`[intlify] ` + msg);
52 /* istanbul ignore if */
53 if (err) {
54 console.warn(err.stack);
55 }
56 }
57 }
58 const assign = Object.assign;
59 let _globalThis;
60 const getGlobalThis = () => {
61 // prettier-ignore
62 return (_globalThis ||
63 (_globalThis =
64 typeof globalThis !== 'undefined'
65 ? globalThis
66 : typeof self !== 'undefined'
67 ? self
68 : typeof window !== 'undefined'
69 ? window
70 : typeof global !== 'undefined'
71 ? global
72 : {}));
73 };
74 function escapeHtml(rawText) {
75 return rawText
76 .replace(/</g, '&lt;')
77 .replace(/>/g, '&gt;')
78 .replace(/"/g, '&quot;')
79 .replace(/'/g, '&apos;');
80 }
81 const hasOwnProperty = Object.prototype.hasOwnProperty;
82 function hasOwn(obj, key) {
83 return hasOwnProperty.call(obj, key);
84 }
85 /* eslint-enable */
86 /**
87 * Useful Utilities By Evan you
88 * Modified by kazuya kawaguchi
89 * MIT License
90 * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/index.ts
91 * https://github.com/vuejs/vue-next/blob/master/packages/shared/src/codeframe.ts
92 */
93 const isArray = Array.isArray;
94 const isFunction = (val) => typeof val === 'function';
95 const isString = (val) => typeof val === 'string';
96 const isBoolean = (val) => typeof val === 'boolean';
97 const isObject = (val) => // eslint-disable-line
98 val !== null && typeof val === 'object';
99 const objectToString = Object.prototype.toString;
100 const toTypeString = (value) => objectToString.call(value);
101 const isPlainObject = (val) => toTypeString(val) === '[object Object]';
102 // for converting list and named values to displayed strings.
103 const toDisplayString = (val) => {
104 return val == null
105 ? ''
106 : isArray(val) || (isPlainObject(val) && val.toString === objectToString)
107 ? JSON.stringify(val, null, 2)
108 : String(val);
109 };
110
111 const CompileErrorCodes = {
112 // tokenizer error codes
113 EXPECTED_TOKEN: 1,
114 INVALID_TOKEN_IN_PLACEHOLDER: 2,
115 UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
116 UNKNOWN_ESCAPE_SEQUENCE: 4,
117 INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
118 UNBALANCED_CLOSING_BRACE: 6,
119 UNTERMINATED_CLOSING_BRACE: 7,
120 EMPTY_PLACEHOLDER: 8,
121 NOT_ALLOW_NEST_PLACEHOLDER: 9,
122 INVALID_LINKED_FORMAT: 10,
123 // parser error codes
124 MUST_HAVE_MESSAGES_IN_PLURAL: 11,
125 UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
126 UNEXPECTED_EMPTY_LINKED_KEY: 13,
127 UNEXPECTED_LEXICAL_ANALYSIS: 14,
128 // Special value for higher-order compilers to pick up the last code
129 // to avoid collision of error codes. This should always be kept as the last
130 // item.
131 __EXTEND_POINT__: 15
132 };
133 /** @internal */
134 const errorMessages$2 = {
135 // tokenizer error messages
136 [CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
137 [CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
138 [CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
139 [CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
140 [CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
141 [CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
142 [CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
143 [CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
144 [CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
145 [CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
146 // parser error messages
147 [CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
148 [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
149 [CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
150 [CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`
151 };
152 function createCompileError(code, loc, options = {}) {
153 const { domain, messages, args } = options;
154 const msg = format((messages || errorMessages$2)[code] || '', ...(args || []))
155 ;
156 const error = new SyntaxError(String(msg));
157 error.code = code;
158 if (loc) {
159 error.location = loc;
160 }
161 error.domain = domain;
162 return error;
163 }
164
165 const pathStateMachine = [];
166 pathStateMachine[0 /* BEFORE_PATH */] = {
167 ["w" /* WORKSPACE */]: [0 /* BEFORE_PATH */],
168 ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
169 ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
170 ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
171 };
172 pathStateMachine[1 /* IN_PATH */] = {
173 ["w" /* WORKSPACE */]: [1 /* IN_PATH */],
174 ["." /* DOT */]: [2 /* BEFORE_IDENT */],
175 ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */],
176 ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */]
177 };
178 pathStateMachine[2 /* BEFORE_IDENT */] = {
179 ["w" /* WORKSPACE */]: [2 /* BEFORE_IDENT */],
180 ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
181 ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */]
182 };
183 pathStateMachine[3 /* IN_IDENT */] = {
184 ["i" /* IDENT */]: [3 /* IN_IDENT */, 0 /* APPEND */],
185 ["0" /* ZERO */]: [3 /* IN_IDENT */, 0 /* APPEND */],
186 ["w" /* WORKSPACE */]: [1 /* IN_PATH */, 1 /* PUSH */],
187 ["." /* DOT */]: [2 /* BEFORE_IDENT */, 1 /* PUSH */],
188 ["[" /* LEFT_BRACKET */]: [4 /* IN_SUB_PATH */, 1 /* PUSH */],
189 ["o" /* END_OF_FAIL */]: [7 /* AFTER_PATH */, 1 /* PUSH */]
190 };
191 pathStateMachine[4 /* IN_SUB_PATH */] = {
192 ["'" /* SINGLE_QUOTE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */],
193 ["\"" /* DOUBLE_QUOTE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */],
194 ["[" /* LEFT_BRACKET */]: [
195 4 /* IN_SUB_PATH */,
196 2 /* INC_SUB_PATH_DEPTH */
197 ],
198 ["]" /* RIGHT_BRACKET */]: [1 /* IN_PATH */, 3 /* PUSH_SUB_PATH */],
199 ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
200 ["l" /* ELSE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */]
201 };
202 pathStateMachine[5 /* IN_SINGLE_QUOTE */] = {
203 ["'" /* SINGLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
204 ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
205 ["l" /* ELSE */]: [5 /* IN_SINGLE_QUOTE */, 0 /* APPEND */]
206 };
207 pathStateMachine[6 /* IN_DOUBLE_QUOTE */] = {
208 ["\"" /* DOUBLE_QUOTE */]: [4 /* IN_SUB_PATH */, 0 /* APPEND */],
209 ["o" /* END_OF_FAIL */]: 8 /* ERROR */,
210 ["l" /* ELSE */]: [6 /* IN_DOUBLE_QUOTE */, 0 /* APPEND */]
211 };
212 /**
213 * Check if an expression is a literal value.
214 */
215 const literalValueRE = /^\s?(?:true|false|-?[\d.]+|'[^']*'|"[^"]*")\s?$/;
216 function isLiteral(exp) {
217 return literalValueRE.test(exp);
218 }
219 /**
220 * Strip quotes from a string
221 */
222 function stripQuotes(str) {
223 const a = str.charCodeAt(0);
224 const b = str.charCodeAt(str.length - 1);
225 return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
226 }
227 /**
228 * Determine the type of a character in a keypath.
229 */
230 function getPathCharType(ch) {
231 if (ch === undefined || ch === null) {
232 return "o" /* END_OF_FAIL */;
233 }
234 const code = ch.charCodeAt(0);
235 switch (code) {
236 case 0x5b: // [
237 case 0x5d: // ]
238 case 0x2e: // .
239 case 0x22: // "
240 case 0x27: // '
241 return ch;
242 case 0x5f: // _
243 case 0x24: // $
244 case 0x2d: // -
245 return "i" /* IDENT */;
246 case 0x09: // Tab (HT)
247 case 0x0a: // Newline (LF)
248 case 0x0d: // Return (CR)
249 case 0xa0: // No-break space (NBSP)
250 case 0xfeff: // Byte Order Mark (BOM)
251 case 0x2028: // Line Separator (LS)
252 case 0x2029: // Paragraph Separator (PS)
253 return "w" /* WORKSPACE */;
254 }
255 return "i" /* IDENT */;
256 }
257 /**
258 * Format a subPath, return its plain form if it is
259 * a literal string or number. Otherwise prepend the
260 * dynamic indicator (*).
261 */
262 function formatSubPath(path) {
263 const trimmed = path.trim();
264 // invalid leading 0
265 if (path.charAt(0) === '0' && isNaN(parseInt(path))) {
266 return false;
267 }
268 return isLiteral(trimmed)
269 ? stripQuotes(trimmed)
270 : "*" /* ASTARISK */ + trimmed;
271 }
272 /**
273 * Parse a string path into an array of segments
274 */
275 function parse(path) {
276 const keys = [];
277 let index = -1;
278 let mode = 0 /* BEFORE_PATH */;
279 let subPathDepth = 0;
280 let c;
281 let key; // eslint-disable-line
282 let newChar;
283 let type;
284 let transition;
285 let action;
286 let typeMap;
287 const actions = [];
288 actions[0 /* APPEND */] = () => {
289 if (key === undefined) {
290 key = newChar;
291 }
292 else {
293 key += newChar;
294 }
295 };
296 actions[1 /* PUSH */] = () => {
297 if (key !== undefined) {
298 keys.push(key);
299 key = undefined;
300 }
301 };
302 actions[2 /* INC_SUB_PATH_DEPTH */] = () => {
303 actions[0 /* APPEND */]();
304 subPathDepth++;
305 };
306 actions[3 /* PUSH_SUB_PATH */] = () => {
307 if (subPathDepth > 0) {
308 subPathDepth--;
309 mode = 4 /* IN_SUB_PATH */;
310 actions[0 /* APPEND */]();
311 }
312 else {
313 subPathDepth = 0;
314 if (key === undefined) {
315 return false;
316 }
317 key = formatSubPath(key);
318 if (key === false) {
319 return false;
320 }
321 else {
322 actions[1 /* PUSH */]();
323 }
324 }
325 };
326 function maybeUnescapeQuote() {
327 const nextChar = path[index + 1];
328 if ((mode === 5 /* IN_SINGLE_QUOTE */ &&
329 nextChar === "'" /* SINGLE_QUOTE */) ||
330 (mode === 6 /* IN_DOUBLE_QUOTE */ &&
331 nextChar === "\"" /* DOUBLE_QUOTE */)) {
332 index++;
333 newChar = '\\' + nextChar;
334 actions[0 /* APPEND */]();
335 return true;
336 }
337 }
338 while (mode !== null) {
339 index++;
340 c = path[index];
341 if (c === '\\' && maybeUnescapeQuote()) {
342 continue;
343 }
344 type = getPathCharType(c);
345 typeMap = pathStateMachine[mode];
346 transition = typeMap[type] || typeMap["l" /* ELSE */] || 8 /* ERROR */;
347 // check parse error
348 if (transition === 8 /* ERROR */) {
349 return;
350 }
351 mode = transition[0];
352 if (transition[1] !== undefined) {
353 action = actions[transition[1]];
354 if (action) {
355 newChar = c;
356 if (action() === false) {
357 return;
358 }
359 }
360 }
361 // check parse finish
362 if (mode === 7 /* AFTER_PATH */) {
363 return keys;
364 }
365 }
366 }
367 // path token cache
368 const cache = new Map();
369 /**
370 * key-value message resolver
371 *
372 * @remarks
373 * Resolves messages with the key-value structure. Note that messages with a hierarchical structure such as objects cannot be resolved
374 *
375 * @param obj - A target object to be resolved with path
376 * @param path - A {@link Path | path} to resolve the value of message
377 *
378 * @returns A resolved {@link PathValue | path value}
379 *
380 * @VueI18nGeneral
381 */
382 function resolveWithKeyValue(obj, path) {
383 return isObject(obj) ? obj[path] : null;
384 }
385 /**
386 * message resolver
387 *
388 * @remarks
389 * Resolves messages. messages with a hierarchical structure such as objects can be resolved. This resolver is used in VueI18n as default.
390 *
391 * @param obj - A target object to be resolved with path
392 * @param path - A {@link Path | path} to resolve the value of message
393 *
394 * @returns A resolved {@link PathValue | path value}
395 *
396 * @VueI18nGeneral
397 */
398 function resolveValue(obj, path) {
399 // check object
400 if (!isObject(obj)) {
401 return null;
402 }
403 // parse path
404 let hit = cache.get(path);
405 if (!hit) {
406 hit = parse(path);
407 if (hit) {
408 cache.set(path, hit);
409 }
410 }
411 // check hit
412 if (!hit) {
413 return null;
414 }
415 // resolve path value
416 const len = hit.length;
417 let last = obj;
418 let i = 0;
419 while (i < len) {
420 const val = last[hit[i]];
421 if (val === undefined) {
422 return null;
423 }
424 last = val;
425 i++;
426 }
427 return last;
428 }
429
430 const DEFAULT_MODIFIER = (str) => str;
431 const DEFAULT_MESSAGE = (ctx) => ''; // eslint-disable-line
432 const DEFAULT_MESSAGE_DATA_TYPE = 'text';
433 const DEFAULT_NORMALIZE = (values) => values.length === 0 ? '' : values.join('');
434 const DEFAULT_INTERPOLATE = toDisplayString;
435 function pluralDefault(choice, choicesLength) {
436 choice = Math.abs(choice);
437 if (choicesLength === 2) {
438 // prettier-ignore
439 return choice
440 ? choice > 1
441 ? 1
442 : 0
443 : 1;
444 }
445 return choice ? Math.min(choice, 2) : 0;
446 }
447 function getPluralIndex(options) {
448 // prettier-ignore
449 const index = isNumber(options.pluralIndex)
450 ? options.pluralIndex
451 : -1;
452 // prettier-ignore
453 return options.named && (isNumber(options.named.count) || isNumber(options.named.n))
454 ? isNumber(options.named.count)
455 ? options.named.count
456 : isNumber(options.named.n)
457 ? options.named.n
458 : index
459 : index;
460 }
461 function normalizeNamed(pluralIndex, props) {
462 if (!props.count) {
463 props.count = pluralIndex;
464 }
465 if (!props.n) {
466 props.n = pluralIndex;
467 }
468 }
469 function createMessageContext(options = {}) {
470 const locale = options.locale;
471 const pluralIndex = getPluralIndex(options);
472 const pluralRule = isObject(options.pluralRules) &&
473 isString(locale) &&
474 isFunction(options.pluralRules[locale])
475 ? options.pluralRules[locale]
476 : pluralDefault;
477 const orgPluralRule = isObject(options.pluralRules) &&
478 isString(locale) &&
479 isFunction(options.pluralRules[locale])
480 ? pluralDefault
481 : undefined;
482 const plural = (messages) => messages[pluralRule(pluralIndex, messages.length, orgPluralRule)];
483 const _list = options.list || [];
484 const list = (index) => _list[index];
485 // eslint-disable-next-line @typescript-eslint/no-explicit-any
486 const _named = options.named || {};
487 isNumber(options.pluralIndex) && normalizeNamed(pluralIndex, _named);
488 const named = (key) => _named[key];
489 // TODO: need to design resolve message function?
490 function message(key) {
491 // prettier-ignore
492 const msg = isFunction(options.messages)
493 ? options.messages(key)
494 : isObject(options.messages)
495 ? options.messages[key]
496 : false;
497 return !msg
498 ? options.parent
499 ? options.parent.message(key) // resolve from parent messages
500 : DEFAULT_MESSAGE
501 : msg;
502 }
503 const _modifier = (name) => options.modifiers
504 ? options.modifiers[name]
505 : DEFAULT_MODIFIER;
506 const normalize = isPlainObject(options.processor) && isFunction(options.processor.normalize)
507 ? options.processor.normalize
508 : DEFAULT_NORMALIZE;
509 const interpolate = isPlainObject(options.processor) &&
510 isFunction(options.processor.interpolate)
511 ? options.processor.interpolate
512 : DEFAULT_INTERPOLATE;
513 const type = isPlainObject(options.processor) && isString(options.processor.type)
514 ? options.processor.type
515 : DEFAULT_MESSAGE_DATA_TYPE;
516 const ctx = {
517 ["list" /* LIST */]: list,
518 ["named" /* NAMED */]: named,
519 ["plural" /* PLURAL */]: plural,
520 ["linked" /* LINKED */]: (key, modifier) => {
521 // TODO: should check `key`
522 const msg = message(key)(ctx);
523 return isString(modifier) ? _modifier(modifier)(msg) : msg;
524 },
525 ["message" /* MESSAGE */]: message,
526 ["type" /* TYPE */]: type,
527 ["interpolate" /* INTERPOLATE */]: interpolate,
528 ["normalize" /* NORMALIZE */]: normalize
529 };
530 return ctx;
531 }
532
533 const IntlifyDevToolsHooks = {
534 I18nInit: 'i18n:init',
535 FunctionTranslate: 'function:translate'
536 };
537
538 let devtools = null;
539 function setDevToolsHook(hook) {
540 devtools = hook;
541 }
542 function initI18nDevTools(i18n, version, meta) {
543 // TODO: queue if devtools is undefined
544 devtools &&
545 devtools.emit(IntlifyDevToolsHooks.I18nInit, {
546 timestamp: Date.now(),
547 i18n,
548 version,
549 meta
550 });
551 }
552 const translateDevTools = /* #__PURE__*/ createDevToolsHook(IntlifyDevToolsHooks.FunctionTranslate);
553 function createDevToolsHook(hook) {
554 return (payloads) => devtools && devtools.emit(hook, payloads);
555 }
556
557 const CoreWarnCodes = {
558 NOT_FOUND_KEY: 1,
559 FALLBACK_TO_TRANSLATE: 2,
560 CANNOT_FORMAT_NUMBER: 3,
561 FALLBACK_TO_NUMBER_FORMAT: 4,
562 CANNOT_FORMAT_DATE: 5,
563 FALLBACK_TO_DATE_FORMAT: 6,
564 __EXTEND_POINT__: 7
565 };
566 /** @internal */
567 const warnMessages$1 = {
568 [CoreWarnCodes.NOT_FOUND_KEY]: `Not found '{key}' key in '{locale}' locale messages.`,
569 [CoreWarnCodes.FALLBACK_TO_TRANSLATE]: `Fall back to translate '{key}' key with '{target}' locale.`,
570 [CoreWarnCodes.CANNOT_FORMAT_NUMBER]: `Cannot format a number value due to not supported Intl.NumberFormat.`,
571 [CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT]: `Fall back to number format '{key}' key with '{target}' locale.`,
572 [CoreWarnCodes.CANNOT_FORMAT_DATE]: `Cannot format a date value due to not supported Intl.DateTimeFormat.`,
573 [CoreWarnCodes.FALLBACK_TO_DATE_FORMAT]: `Fall back to datetime format '{key}' key with '{target}' locale.`
574 };
575 function getWarnMessage$1(code, ...args) {
576 return format(warnMessages$1[code], ...args);
577 }
578
579 /**
580 * Fallback with simple implemenation
581 *
582 * @remarks
583 * A fallback locale function implemented with a simple fallback algorithm.
584 *
585 * Basically, it returns the value as specified in the `fallbackLocale` props, and is processed with the fallback inside intlify.
586 *
587 * @param ctx - A {@link CoreContext | context}
588 * @param fallback - A {@link FallbackLocale | fallback locale}
589 * @param start - A starting {@link Locale | locale}
590 *
591 * @returns Fallback locales
592 *
593 * @VueI18nGeneral
594 */
595 function fallbackWithSimple(ctx, fallback, start // eslint-disable-line @typescript-eslint/no-unused-vars
596 ) {
597 // prettier-ignore
598 return [...new Set([
599 start,
600 ...(isArray(fallback)
601 ? fallback
602 : isObject(fallback)
603 ? Object.keys(fallback)
604 : isString(fallback)
605 ? [fallback]
606 : [start])
607 ])];
608 }
609 /**
610 * Fallback with locale chain
611 *
612 * @remarks
613 * A fallback locale function implemented with a fallback chain algorithm. It's used in VueI18n as default.
614 *
615 * @param ctx - A {@link CoreContext | context}
616 * @param fallback - A {@link FallbackLocale | fallback locale}
617 * @param start - A starting {@link Locale | locale}
618 *
619 * @returns Fallback locales
620 *
621 * @VueI18nSee [Fallbacking](../guide/essentials/fallback)
622 *
623 * @VueI18nGeneral
624 */
625 function fallbackWithLocaleChain(ctx, fallback, start) {
626 const startLocale = isString(start) ? start : DEFAULT_LOCALE;
627 const context = ctx;
628 if (!context.__localeChainCache) {
629 context.__localeChainCache = new Map();
630 }
631 let chain = context.__localeChainCache.get(startLocale);
632 if (!chain) {
633 chain = [];
634 // first block defined by start
635 let block = [start];
636 // while any intervening block found
637 while (isArray(block)) {
638 block = appendBlockToChain(chain, block, fallback);
639 }
640 // prettier-ignore
641 // last block defined by default
642 const defaults = isArray(fallback) || !isPlainObject(fallback)
643 ? fallback
644 : fallback['default']
645 ? fallback['default']
646 : null;
647 // convert defaults to array
648 block = isString(defaults) ? [defaults] : defaults;
649 if (isArray(block)) {
650 appendBlockToChain(chain, block, false);
651 }
652 context.__localeChainCache.set(startLocale, chain);
653 }
654 return chain;
655 }
656 function appendBlockToChain(chain, block, blocks) {
657 let follow = true;
658 for (let i = 0; i < block.length && isBoolean(follow); i++) {
659 const locale = block[i];
660 if (isString(locale)) {
661 follow = appendLocaleToChain(chain, block[i], blocks);
662 }
663 }
664 return follow;
665 }
666 function appendLocaleToChain(chain, locale, blocks) {
667 let follow;
668 const tokens = locale.split('-');
669 do {
670 const target = tokens.join('-');
671 follow = appendItemToChain(chain, target, blocks);
672 tokens.splice(-1, 1);
673 } while (tokens.length && follow === true);
674 return follow;
675 }
676 function appendItemToChain(chain, target, blocks) {
677 let follow = false;
678 if (!chain.includes(target)) {
679 follow = true;
680 if (target) {
681 follow = target[target.length - 1] !== '!';
682 const locale = target.replace(/!/g, '');
683 chain.push(locale);
684 if ((isArray(blocks) || isPlainObject(blocks)) &&
685 blocks[locale] // eslint-disable-line @typescript-eslint/no-explicit-any
686 ) {
687 // eslint-disable-next-line @typescript-eslint/no-explicit-any
688 follow = blocks[locale];
689 }
690 }
691 }
692 return follow;
693 }
694
695 /* eslint-disable @typescript-eslint/no-explicit-any */
696 /**
697 * Intlify core-base version
698 * @internal
699 */
700 const VERSION$1 = '9.2.0-beta.6';
701 const NOT_REOSLVED = -1;
702 const DEFAULT_LOCALE = 'en-US';
703 const MISSING_RESOLVE_VALUE = '';
704 function getDefaultLinkedModifiers() {
705 return {
706 upper: (val) => (isString(val) ? val.toUpperCase() : val),
707 lower: (val) => (isString(val) ? val.toLowerCase() : val),
708 // prettier-ignore
709 capitalize: (val) => (isString(val)
710 ? `${val.charAt(0).toLocaleUpperCase()}${val.substr(1)}`
711 : val)
712 };
713 }
714 let _compiler;
715 let _resolver;
716 /**
717 * Register the message resolver
718 *
719 * @param resolver - A {@link MessageResolver} function
720 *
721 * @VueI18nGeneral
722 */
723 function registerMessageResolver(resolver) {
724 _resolver = resolver;
725 }
726 let _fallbacker;
727 /**
728 * Register the locale fallbacker
729 *
730 * @param fallbacker - A {@link LocaleFallbacker} function
731 *
732 * @VueI18nGeneral
733 */
734 function registerLocaleFallbacker(fallbacker) {
735 _fallbacker = fallbacker;
736 }
737 // Additional Meta for Intlify DevTools
738 let _additionalMeta = null;
739 const setAdditionalMeta = (meta) => {
740 _additionalMeta = meta;
741 };
742 const getAdditionalMeta = () => _additionalMeta;
743 // ID for CoreContext
744 let _cid = 0;
745 function createCoreContext(options = {}) {
746 // setup options
747 const version = isString(options.version) ? options.version : VERSION$1;
748 const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
749 const fallbackLocale = isArray(options.fallbackLocale) ||
750 isPlainObject(options.fallbackLocale) ||
751 isString(options.fallbackLocale) ||
752 options.fallbackLocale === false
753 ? options.fallbackLocale
754 : locale;
755 const messages = isPlainObject(options.messages)
756 ? options.messages
757 : { [locale]: {} };
758 const datetimeFormats = isPlainObject(options.datetimeFormats)
759 ? options.datetimeFormats
760 : { [locale]: {} }
761 ;
762 const numberFormats = isPlainObject(options.numberFormats)
763 ? options.numberFormats
764 : { [locale]: {} }
765 ;
766 const modifiers = assign({}, options.modifiers || {}, getDefaultLinkedModifiers());
767 const pluralRules = options.pluralRules || {};
768 const missing = isFunction(options.missing) ? options.missing : null;
769 const missingWarn = isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
770 ? options.missingWarn
771 : true;
772 const fallbackWarn = isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
773 ? options.fallbackWarn
774 : true;
775 const fallbackFormat = !!options.fallbackFormat;
776 const unresolving = !!options.unresolving;
777 const postTranslation = isFunction(options.postTranslation)
778 ? options.postTranslation
779 : null;
780 const processor = isPlainObject(options.processor) ? options.processor : null;
781 const warnHtmlMessage = isBoolean(options.warnHtmlMessage)
782 ? options.warnHtmlMessage
783 : true;
784 const escapeParameter = !!options.escapeParameter;
785 const messageCompiler = isFunction(options.messageCompiler)
786 ? options.messageCompiler
787 : _compiler;
788 const messageResolver = isFunction(options.messageResolver)
789 ? options.messageResolver
790 : _resolver || resolveWithKeyValue;
791 const localeFallbacker = isFunction(options.localeFallbacker)
792 ? options.localeFallbacker
793 : _fallbacker || fallbackWithSimple;
794 const onWarn = isFunction(options.onWarn) ? options.onWarn : warn;
795 // setup internal options
796 const internalOptions = options;
797 const __datetimeFormatters = isObject(internalOptions.__datetimeFormatters)
798 ? internalOptions.__datetimeFormatters
799 : new Map()
800 ;
801 const __numberFormatters = isObject(internalOptions.__numberFormatters)
802 ? internalOptions.__numberFormatters
803 : new Map()
804 ;
805 const __meta = isObject(internalOptions.__meta) ? internalOptions.__meta : {};
806 _cid++;
807 const context = {
808 version,
809 cid: _cid,
810 locale,
811 fallbackLocale,
812 messages,
813 modifiers,
814 pluralRules,
815 missing,
816 missingWarn,
817 fallbackWarn,
818 fallbackFormat,
819 unresolving,
820 postTranslation,
821 processor,
822 warnHtmlMessage,
823 escapeParameter,
824 messageCompiler,
825 messageResolver,
826 localeFallbacker,
827 onWarn,
828 __meta
829 };
830 {
831 context.datetimeFormats = datetimeFormats;
832 context.numberFormats = numberFormats;
833 context.__datetimeFormatters = __datetimeFormatters;
834 context.__numberFormatters = __numberFormatters;
835 }
836 // NOTE: experimental !!
837 {
838 initI18nDevTools(context, version, __meta);
839 }
840 return context;
841 }
842 /** @internal */
843 function isTranslateFallbackWarn(fallback, key) {
844 return fallback instanceof RegExp ? fallback.test(key) : fallback;
845 }
846 /** @internal */
847 function isTranslateMissingWarn(missing, key) {
848 return missing instanceof RegExp ? missing.test(key) : missing;
849 }
850 /** @internal */
851 function handleMissing(context, key, locale, missingWarn, type) {
852 const { missing, onWarn } = context;
853 if (missing !== null) {
854 const ret = missing(context, locale, key, type);
855 return isString(ret) ? ret : key;
856 }
857 else {
858 if (isTranslateMissingWarn(missingWarn, key)) {
859 onWarn(getWarnMessage$1(CoreWarnCodes.NOT_FOUND_KEY, { key, locale }));
860 }
861 return key;
862 }
863 }
864 /** @internal */
865 function updateFallbackLocale(ctx, locale, fallback) {
866 const context = ctx;
867 context.__localeChainCache = new Map();
868 ctx.localeFallbacker(ctx, fallback, locale);
869 }
870 /* eslint-enable @typescript-eslint/no-explicit-any */
871
872 let code$2 = CompileErrorCodes.__EXTEND_POINT__;
873 const inc$2 = () => code$2++;
874 const CoreErrorCodes = {
875 INVALID_ARGUMENT: code$2,
876 INVALID_DATE_ARGUMENT: inc$2(),
877 INVALID_ISO_DATE_ARGUMENT: inc$2(),
878 __EXTEND_POINT__: inc$2() // 18
879 };
880 function createCoreError(code) {
881 return createCompileError(code, null, { messages: errorMessages$1 } );
882 }
883 /** @internal */
884 const errorMessages$1 = {
885 [CoreErrorCodes.INVALID_ARGUMENT]: 'Invalid arguments',
886 [CoreErrorCodes.INVALID_DATE_ARGUMENT]: 'The date provided is an invalid Date object.' +
887 'Make sure your Date represents a valid date.',
888 [CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT]: 'The argument provided is not a valid ISO date string'
889 };
890
891 const NOOP_MESSAGE_FUNCTION = () => '';
892 const isMessageFunction = (val) => isFunction(val);
893 // implementation of `translate` function
894 function translate(context, ...args) {
895 const { fallbackFormat, postTranslation, unresolving, fallbackLocale, messages } = context;
896 const [key, options] = parseTranslateArgs(...args);
897 const missingWarn = isBoolean(options.missingWarn)
898 ? options.missingWarn
899 : context.missingWarn;
900 const fallbackWarn = isBoolean(options.fallbackWarn)
901 ? options.fallbackWarn
902 : context.fallbackWarn;
903 const escapeParameter = isBoolean(options.escapeParameter)
904 ? options.escapeParameter
905 : context.escapeParameter;
906 const resolvedMessage = !!options.resolvedMessage;
907 // prettier-ignore
908 const defaultMsgOrKey = isString(options.default) || isBoolean(options.default) // default by function option
909 ? !isBoolean(options.default)
910 ? options.default
911 : key
912 : fallbackFormat // default by `fallbackFormat` option
913 ? key
914 : '';
915 const enableDefaultMsg = fallbackFormat || defaultMsgOrKey !== '';
916 const locale = isString(options.locale) ? options.locale : context.locale;
917 // escape params
918 escapeParameter && escapeParams(options);
919 // resolve message format
920 // eslint-disable-next-line prefer-const
921 let [format, targetLocale, message] = !resolvedMessage
922 ? resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn)
923 : [
924 key,
925 locale,
926 messages[locale] || {}
927 ];
928 // if you use default message, set it as message format!
929 let cacheBaseKey = key;
930 if (!resolvedMessage &&
931 !(isString(format) || isMessageFunction(format))) {
932 if (enableDefaultMsg) {
933 format = defaultMsgOrKey;
934 cacheBaseKey = format;
935 }
936 }
937 // checking message format and target locale
938 if (!resolvedMessage &&
939 (!(isString(format) || isMessageFunction(format)) ||
940 !isString(targetLocale))) {
941 return unresolving ? NOT_REOSLVED : key;
942 }
943 if (isString(format) && context.messageCompiler == null) {
944 warn(`The message format compilation is not supported in this build. ` +
945 `Because message compiler isn't included. ` +
946 `You need to pre-compilation all message format. ` +
947 `So translate function return '${key}'.`);
948 return key;
949 }
950 // setup compile error detecting
951 let occurred = false;
952 const errorDetector = () => {
953 occurred = true;
954 };
955 // compile message format
956 const msg = !isMessageFunction(format)
957 ? compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector)
958 : format;
959 // if occurred compile error, return the message format
960 if (occurred) {
961 return format;
962 }
963 // evaluate message with context
964 const ctxOptions = getMessageContextOptions(context, targetLocale, message, options);
965 const msgContext = createMessageContext(ctxOptions);
966 const messaged = evaluateMessage(context, msg, msgContext);
967 // if use post translation option, proceed it with handler
968 const ret = postTranslation ? postTranslation(messaged) : messaged;
969 // NOTE: experimental !!
970 {
971 // prettier-ignore
972 const payloads = {
973 timestamp: Date.now(),
974 key: isString(key)
975 ? key
976 : isMessageFunction(format)
977 ? format.key
978 : '',
979 locale: targetLocale || (isMessageFunction(format)
980 ? format.locale
981 : ''),
982 format: isString(format)
983 ? format
984 : isMessageFunction(format)
985 ? format.source
986 : '',
987 message: ret
988 };
989 payloads.meta = assign({}, context.__meta, getAdditionalMeta() || {});
990 translateDevTools(payloads);
991 }
992 return ret;
993 }
994 function escapeParams(options) {
995 if (isArray(options.list)) {
996 options.list = options.list.map(item => isString(item) ? escapeHtml(item) : item);
997 }
998 else if (isObject(options.named)) {
999 Object.keys(options.named).forEach(key => {
1000 if (isString(options.named[key])) {
1001 options.named[key] = escapeHtml(options.named[key]);
1002 }
1003 });
1004 }
1005 }
1006 function resolveMessageFormat(context, key, locale, fallbackLocale, fallbackWarn, missingWarn) {
1007 const { messages, onWarn, messageResolver: resolveValue, localeFallbacker } = context;
1008 const locales = localeFallbacker(context, fallbackLocale, locale); // eslint-disable-line @typescript-eslint/no-explicit-any
1009 let message = {};
1010 let targetLocale;
1011 let format = null;
1012 const type = 'translate';
1013 for (let i = 0; i < locales.length; i++) {
1014 targetLocale = locales[i];
1015 if (locale !== targetLocale &&
1016 isTranslateFallbackWarn(fallbackWarn, key)) {
1017 onWarn(getWarnMessage$1(CoreWarnCodes.FALLBACK_TO_TRANSLATE, {
1018 key,
1019 target: targetLocale
1020 }));
1021 }
1022 message =
1023 messages[targetLocale] || {};
1024 let startTag;
1025 if (inBrowser) {
1026 window.performance.now();
1027 startTag = 'intlify-message-resolve-start';
1028 mark && mark(startTag);
1029 }
1030 if ((format = resolveValue(message, key)) === null) {
1031 // if null, resolve with object key path
1032 format = message[key]; // eslint-disable-line @typescript-eslint/no-explicit-any
1033 }
1034 if (isString(format) || isFunction(format))
1035 break;
1036 const missingRet = handleMissing(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1037 key, targetLocale, missingWarn, type);
1038 if (missingRet !== key) {
1039 format = missingRet;
1040 }
1041 }
1042 return [format, targetLocale, message];
1043 }
1044 function compileMessageFormat(context, key, targetLocale, format, cacheBaseKey, errorDetector) {
1045 const { messageCompiler, warnHtmlMessage } = context;
1046 if (isMessageFunction(format)) {
1047 const msg = format;
1048 msg.locale = msg.locale || targetLocale;
1049 msg.key = msg.key || key;
1050 return msg;
1051 }
1052 let startTag;
1053 if (inBrowser) {
1054 window.performance.now();
1055 startTag = 'intlify-message-compilation-start';
1056 mark && mark(startTag);
1057 }
1058 const msg = messageCompiler(format, getCompileOptions(context, targetLocale, cacheBaseKey, format, warnHtmlMessage, errorDetector));
1059 msg.locale = targetLocale;
1060 msg.key = key;
1061 msg.source = format;
1062 return msg;
1063 }
1064 function evaluateMessage(context, msg, msgCtx) {
1065 let startTag;
1066 if (inBrowser) {
1067 window.performance.now();
1068 startTag = 'intlify-message-evaluation-start';
1069 mark && mark(startTag);
1070 }
1071 const messaged = msg(msgCtx);
1072 return messaged;
1073 }
1074 /** @internal */
1075 function parseTranslateArgs(...args) {
1076 const [arg1, arg2, arg3] = args;
1077 const options = {};
1078 if (!isString(arg1) && !isNumber(arg1) && !isMessageFunction(arg1)) {
1079 throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1080 }
1081 // prettier-ignore
1082 const key = isNumber(arg1)
1083 ? String(arg1)
1084 : isMessageFunction(arg1)
1085 ? arg1
1086 : arg1;
1087 if (isNumber(arg2)) {
1088 options.plural = arg2;
1089 }
1090 else if (isString(arg2)) {
1091 options.default = arg2;
1092 }
1093 else if (isPlainObject(arg2) && !isEmptyObject(arg2)) {
1094 options.named = arg2;
1095 }
1096 else if (isArray(arg2)) {
1097 options.list = arg2;
1098 }
1099 if (isNumber(arg3)) {
1100 options.plural = arg3;
1101 }
1102 else if (isString(arg3)) {
1103 options.default = arg3;
1104 }
1105 else if (isPlainObject(arg3)) {
1106 assign(options, arg3);
1107 }
1108 return [key, options];
1109 }
1110 function getCompileOptions(context, locale, key, source, warnHtmlMessage, errorDetector) {
1111 return {
1112 warnHtmlMessage,
1113 onError: (err) => {
1114 errorDetector && errorDetector(err);
1115 {
1116 throw err;
1117 }
1118 },
1119 onCacheKey: (source) => generateFormatCacheKey(locale, key, source)
1120 };
1121 }
1122 function getMessageContextOptions(context, locale, message, options) {
1123 const { modifiers, pluralRules, messageResolver: resolveValue } = context;
1124 const resolveMessage = (key) => {
1125 const val = resolveValue(message, key);
1126 if (isString(val)) {
1127 let occurred = false;
1128 const errorDetector = () => {
1129 occurred = true;
1130 };
1131 const msg = compileMessageFormat(context, key, locale, val, key, errorDetector);
1132 return !occurred
1133 ? msg
1134 : NOOP_MESSAGE_FUNCTION;
1135 }
1136 else if (isMessageFunction(val)) {
1137 return val;
1138 }
1139 else {
1140 // TODO: should be implemented warning message
1141 return NOOP_MESSAGE_FUNCTION;
1142 }
1143 };
1144 const ctxOptions = {
1145 locale,
1146 modifiers,
1147 pluralRules,
1148 messages: resolveMessage
1149 };
1150 if (context.processor) {
1151 ctxOptions.processor = context.processor;
1152 }
1153 if (options.list) {
1154 ctxOptions.list = options.list;
1155 }
1156 if (options.named) {
1157 ctxOptions.named = options.named;
1158 }
1159 if (isNumber(options.plural)) {
1160 ctxOptions.pluralIndex = options.plural;
1161 }
1162 return ctxOptions;
1163 }
1164
1165 const intlDefined = typeof Intl !== 'undefined';
1166 const Availabilities = {
1167 dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
1168 numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
1169 };
1170
1171 // implementation of `datetime` function
1172 function datetime(context, ...args) {
1173 const { datetimeFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1174 const { __datetimeFormatters } = context;
1175 if (!Availabilities.dateTimeFormat) {
1176 onWarn(getWarnMessage$1(CoreWarnCodes.CANNOT_FORMAT_DATE));
1177 return MISSING_RESOLVE_VALUE;
1178 }
1179 const [key, value, options, overrides] = parseDateTimeArgs(...args);
1180 const missingWarn = isBoolean(options.missingWarn)
1181 ? options.missingWarn
1182 : context.missingWarn;
1183 const fallbackWarn = isBoolean(options.fallbackWarn)
1184 ? options.fallbackWarn
1185 : context.fallbackWarn;
1186 const part = !!options.part;
1187 const locale = isString(options.locale) ? options.locale : context.locale;
1188 const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1189 fallbackLocale, locale);
1190 if (!isString(key) || key === '') {
1191 return new Intl.DateTimeFormat(locale).format(value);
1192 }
1193 // resolve format
1194 let datetimeFormat = {};
1195 let targetLocale;
1196 let format = null;
1197 const type = 'datetime format';
1198 for (let i = 0; i < locales.length; i++) {
1199 targetLocale = locales[i];
1200 if (locale !== targetLocale &&
1201 isTranslateFallbackWarn(fallbackWarn, key)) {
1202 onWarn(getWarnMessage$1(CoreWarnCodes.FALLBACK_TO_DATE_FORMAT, {
1203 key,
1204 target: targetLocale
1205 }));
1206 }
1207 datetimeFormat =
1208 datetimeFormats[targetLocale] || {};
1209 format = datetimeFormat[key];
1210 if (isPlainObject(format))
1211 break;
1212 handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1213 }
1214 // checking format and target locale
1215 if (!isPlainObject(format) || !isString(targetLocale)) {
1216 return unresolving ? NOT_REOSLVED : key;
1217 }
1218 let id = `${targetLocale}__${key}`;
1219 if (!isEmptyObject(overrides)) {
1220 id = `${id}__${JSON.stringify(overrides)}`;
1221 }
1222 let formatter = __datetimeFormatters.get(id);
1223 if (!formatter) {
1224 formatter = new Intl.DateTimeFormat(targetLocale, assign({}, format, overrides));
1225 __datetimeFormatters.set(id, formatter);
1226 }
1227 return !part ? formatter.format(value) : formatter.formatToParts(value);
1228 }
1229 /** @internal */
1230 function parseDateTimeArgs(...args) {
1231 const [arg1, arg2, arg3, arg4] = args;
1232 let options = {};
1233 let overrides = {};
1234 let value;
1235 if (isString(arg1)) {
1236 // Only allow ISO strings - other date formats are often supported,
1237 // but may cause different results in different browsers.
1238 const matches = arg1.match(/(\d{4}-\d{2}-\d{2})(T|\s)?(.*)/);
1239 if (!matches) {
1240 throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1241 }
1242 // Some browsers can not parse the iso datetime separated by space,
1243 // this is a compromise solution by replace the 'T'/' ' with 'T'
1244 const dateTime = matches[3]
1245 ? matches[3].trim().startsWith('T')
1246 ? `${matches[1].trim()}${matches[3].trim()}`
1247 : `${matches[1].trim()}T${matches[3].trim()}`
1248 : matches[1].trim();
1249 value = new Date(dateTime);
1250 try {
1251 // This will fail if the date is not valid
1252 value.toISOString();
1253 }
1254 catch (e) {
1255 throw createCoreError(CoreErrorCodes.INVALID_ISO_DATE_ARGUMENT);
1256 }
1257 }
1258 else if (isDate(arg1)) {
1259 if (isNaN(arg1.getTime())) {
1260 throw createCoreError(CoreErrorCodes.INVALID_DATE_ARGUMENT);
1261 }
1262 value = arg1;
1263 }
1264 else if (isNumber(arg1)) {
1265 value = arg1;
1266 }
1267 else {
1268 throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1269 }
1270 if (isString(arg2)) {
1271 options.key = arg2;
1272 }
1273 else if (isPlainObject(arg2)) {
1274 options = arg2;
1275 }
1276 if (isString(arg3)) {
1277 options.locale = arg3;
1278 }
1279 else if (isPlainObject(arg3)) {
1280 overrides = arg3;
1281 }
1282 if (isPlainObject(arg4)) {
1283 overrides = arg4;
1284 }
1285 return [options.key || '', value, options, overrides];
1286 }
1287 /** @internal */
1288 function clearDateTimeFormat(ctx, locale, format) {
1289 const context = ctx;
1290 for (const key in format) {
1291 const id = `${locale}__${key}`;
1292 if (!context.__datetimeFormatters.has(id)) {
1293 continue;
1294 }
1295 context.__datetimeFormatters.delete(id);
1296 }
1297 }
1298
1299 // implementation of `number` function
1300 function number(context, ...args) {
1301 const { numberFormats, unresolving, fallbackLocale, onWarn, localeFallbacker } = context;
1302 const { __numberFormatters } = context;
1303 if (!Availabilities.numberFormat) {
1304 onWarn(getWarnMessage$1(CoreWarnCodes.CANNOT_FORMAT_NUMBER));
1305 return MISSING_RESOLVE_VALUE;
1306 }
1307 const [key, value, options, overrides] = parseNumberArgs(...args);
1308 const missingWarn = isBoolean(options.missingWarn)
1309 ? options.missingWarn
1310 : context.missingWarn;
1311 const fallbackWarn = isBoolean(options.fallbackWarn)
1312 ? options.fallbackWarn
1313 : context.fallbackWarn;
1314 const part = !!options.part;
1315 const locale = isString(options.locale) ? options.locale : context.locale;
1316 const locales = localeFallbacker(context, // eslint-disable-line @typescript-eslint/no-explicit-any
1317 fallbackLocale, locale);
1318 if (!isString(key) || key === '') {
1319 return new Intl.NumberFormat(locale).format(value);
1320 }
1321 // resolve format
1322 let numberFormat = {};
1323 let targetLocale;
1324 let format = null;
1325 const type = 'number format';
1326 for (let i = 0; i < locales.length; i++) {
1327 targetLocale = locales[i];
1328 if (locale !== targetLocale &&
1329 isTranslateFallbackWarn(fallbackWarn, key)) {
1330 onWarn(getWarnMessage$1(CoreWarnCodes.FALLBACK_TO_NUMBER_FORMAT, {
1331 key,
1332 target: targetLocale
1333 }));
1334 }
1335 numberFormat =
1336 numberFormats[targetLocale] || {};
1337 format = numberFormat[key];
1338 if (isPlainObject(format))
1339 break;
1340 handleMissing(context, key, targetLocale, missingWarn, type); // eslint-disable-line @typescript-eslint/no-explicit-any
1341 }
1342 // checking format and target locale
1343 if (!isPlainObject(format) || !isString(targetLocale)) {
1344 return unresolving ? NOT_REOSLVED : key;
1345 }
1346 let id = `${targetLocale}__${key}`;
1347 if (!isEmptyObject(overrides)) {
1348 id = `${id}__${JSON.stringify(overrides)}`;
1349 }
1350 let formatter = __numberFormatters.get(id);
1351 if (!formatter) {
1352 formatter = new Intl.NumberFormat(targetLocale, assign({}, format, overrides));
1353 __numberFormatters.set(id, formatter);
1354 }
1355 return !part ? formatter.format(value) : formatter.formatToParts(value);
1356 }
1357 /** @internal */
1358 function parseNumberArgs(...args) {
1359 const [arg1, arg2, arg3, arg4] = args;
1360 let options = {};
1361 let overrides = {};
1362 if (!isNumber(arg1)) {
1363 throw createCoreError(CoreErrorCodes.INVALID_ARGUMENT);
1364 }
1365 const value = arg1;
1366 if (isString(arg2)) {
1367 options.key = arg2;
1368 }
1369 else if (isPlainObject(arg2)) {
1370 options = arg2;
1371 }
1372 if (isString(arg3)) {
1373 options.locale = arg3;
1374 }
1375 else if (isPlainObject(arg3)) {
1376 overrides = arg3;
1377 }
1378 if (isPlainObject(arg4)) {
1379 overrides = arg4;
1380 }
1381 return [options.key || '', value, options, overrides];
1382 }
1383 /** @internal */
1384 function clearNumberFormat(ctx, locale, format) {
1385 const context = ctx;
1386 for (const key in format) {
1387 const id = `${locale}__${key}`;
1388 if (!context.__numberFormatters.has(id)) {
1389 continue;
1390 }
1391 context.__numberFormatters.delete(id);
1392 }
1393 }
1394
1395 /**
1396 * Vue I18n Version
1397 *
1398 * @remarks
1399 * Semver format. Same format as the package.json `version` field.
1400 *
1401 * @VueI18nGeneral
1402 */
1403 const VERSION = '9.2.0-beta.6';
1404 /**
1405 * This is only called development env
1406 * istanbul-ignore-next
1407 */
1408 function initDev() {
1409 {
1410 {
1411 console.info(`You are running a development build of vue-i18n.\n` +
1412 `Make sure to use the production build (*.prod.js) when deploying for production.`);
1413 }
1414 }
1415 }
1416
1417 let code$1 = CoreWarnCodes.__EXTEND_POINT__;
1418 const inc$1 = () => code$1++;
1419 const I18nWarnCodes = {
1420 FALLBACK_TO_ROOT: code$1,
1421 NOT_SUPPORTED_PRESERVE: inc$1(),
1422 NOT_SUPPORTED_FORMATTER: inc$1(),
1423 NOT_SUPPORTED_PRESERVE_DIRECTIVE: inc$1(),
1424 NOT_SUPPORTED_GET_CHOICE_INDEX: inc$1(),
1425 COMPONENT_NAME_LEGACY_COMPATIBLE: inc$1(),
1426 NOT_FOUND_PARENT_SCOPE: inc$1(),
1427 NOT_SUPPORT_MULTI_I18N_INSTANCE: inc$1() // 14
1428 };
1429 const warnMessages = {
1430 [I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
1431 [I18nWarnCodes.NOT_SUPPORTED_PRESERVE]: `Not supported 'preserve'.`,
1432 [I18nWarnCodes.NOT_SUPPORTED_FORMATTER]: `Not supported 'formatter'.`,
1433 [I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `Not supported 'preserveDirectiveContent'.`,
1434 [I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supported 'getChoiceIndex'.`,
1435 [I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`,
1436 [I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`,
1437 [I18nWarnCodes.NOT_SUPPORT_MULTI_I18N_INSTANCE]: `Not support multi i18n instance.`
1438 };
1439 function getWarnMessage(code, ...args) {
1440 return format(warnMessages[code], ...args);
1441 }
1442
1443 let code = CompileErrorCodes.__EXTEND_POINT__;
1444 const inc = () => code++;
1445 const I18nErrorCodes = {
1446 // composer module errors
1447 UNEXPECTED_RETURN_TYPE: code,
1448 // legacy module errors
1449 INVALID_ARGUMENT: inc(),
1450 // i18n module errors
1451 MUST_BE_CALL_SETUP_TOP: inc(),
1452 NOT_INSLALLED: inc(),
1453 NOT_AVAILABLE_IN_LEGACY_MODE: inc(),
1454 // directive module errors
1455 REQUIRED_VALUE: inc(),
1456 INVALID_VALUE: inc(),
1457 // vue-devtools errors
1458 CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: inc(),
1459 NOT_INSLALLED_WITH_PROVIDE: inc(),
1460 // unexpected error
1461 UNEXPECTED_ERROR: inc(),
1462 // not compatible legacy vue-i18n constructor
1463 NOT_COMPATIBLE_LEGACY_VUE_I18N: inc(),
1464 // bridge support vue 2.x only
1465 BRIDGE_SUPPORT_VUE_2_ONLY: inc(),
1466 // for enhancement
1467 __EXTEND_POINT__: inc() // 27
1468 };
1469 function createI18nError(code, ...args) {
1470 return createCompileError(code, null, { messages: errorMessages, args } );
1471 }
1472 const errorMessages = {
1473 [I18nErrorCodes.UNEXPECTED_RETURN_TYPE]: 'Unexpected return type in composer',
1474 [I18nErrorCodes.INVALID_ARGUMENT]: 'Invalid argument',
1475 [I18nErrorCodes.MUST_BE_CALL_SETUP_TOP]: 'Must be called at the top of a `setup` function',
1476 [I18nErrorCodes.NOT_INSLALLED]: 'Need to install with `app.use` function',
1477 [I18nErrorCodes.UNEXPECTED_ERROR]: 'Unexpected error',
1478 [I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE]: 'Not available in legacy mode',
1479 [I18nErrorCodes.REQUIRED_VALUE]: `Required in value: {0}`,
1480 [I18nErrorCodes.INVALID_VALUE]: `Invalid value`,
1481 [I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN]: `Cannot setup vue-devtools plugin`,
1482 [I18nErrorCodes.NOT_INSLALLED_WITH_PROVIDE]: 'Need to install with `provide` function',
1483 [I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N]: 'Not compatible legacy VueI18n.',
1484 [I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY]: 'vue-i18n-bridge support Vue 2.x only'
1485 };
1486
1487 const SetPluralRulesSymbol = makeSymbol('__setPluralRules');
1488 const LegacyInstanceSymbol = /* #__PURE__*/ makeSymbol('__legacyVueI18n');
1489
1490 /* eslint-disable @typescript-eslint/no-explicit-any */
1491 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1492 function isLegacyVueI18n(VueI18n) {
1493 if (VueI18n == null || VueI18n.version == null) {
1494 return false;
1495 }
1496 return (Number(VueI18n.version.split('.')[0]) || -1) >= 8;
1497 }
1498 /**
1499 * Transform flat json in obj to normal json in obj
1500 */
1501 function handleFlatJson(obj) {
1502 // check obj
1503 if (!isObject(obj)) {
1504 return obj;
1505 }
1506 for (const key in obj) {
1507 // check key
1508 if (!hasOwn(obj, key)) {
1509 continue;
1510 }
1511 // handle for normal json
1512 if (!key.includes('.')) {
1513 // recursive process value if value is also a object
1514 if (isObject(obj[key])) {
1515 handleFlatJson(obj[key]);
1516 }
1517 }
1518 // handle for flat json, transform to normal json
1519 else {
1520 // go to the last object
1521 const subKeys = key.split('.');
1522 const lastIndex = subKeys.length - 1;
1523 let currentObj = obj;
1524 for (let i = 0; i < lastIndex; i++) {
1525 if (!(subKeys[i] in currentObj)) {
1526 currentObj[subKeys[i]] = {};
1527 }
1528 currentObj = currentObj[subKeys[i]];
1529 }
1530 // update last object value, delete old property
1531 currentObj[subKeys[lastIndex]] = obj[key];
1532 delete obj[key];
1533 // recursive process value if value is also a object
1534 if (isObject(currentObj[subKeys[lastIndex]])) {
1535 handleFlatJson(currentObj[subKeys[lastIndex]]);
1536 }
1537 }
1538 }
1539 return obj;
1540 }
1541 function getLocaleMessages(locale, options) {
1542 const { messages, __i18n, messageResolver, flatJson } = options;
1543 // prettier-ignore
1544 const ret = isPlainObject(messages)
1545 ? messages
1546 : isArray(__i18n)
1547 ? {}
1548 : { [locale]: {} };
1549 // merge locale messages of i18n custom block
1550 if (isArray(__i18n)) {
1551 __i18n.forEach(({ locale, resource }) => {
1552 if (locale) {
1553 ret[locale] = ret[locale] || {};
1554 deepCopy(resource, ret[locale]);
1555 }
1556 else {
1557 deepCopy(resource, ret);
1558 }
1559 });
1560 }
1561 // handle messages for flat json
1562 if (messageResolver == null && flatJson) {
1563 for (const key in ret) {
1564 if (hasOwn(ret, key)) {
1565 handleFlatJson(ret[key]);
1566 }
1567 }
1568 }
1569 return ret;
1570 }
1571 const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val);
1572 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
1573 function deepCopy(src, des) {
1574 // src and des should both be objects, and non of then can be a array
1575 if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) {
1576 throw createI18nError(I18nErrorCodes.INVALID_VALUE);
1577 }
1578 for (const key in src) {
1579 if (hasOwn(src, key)) {
1580 if (isNotObjectOrIsArray(src[key]) || isNotObjectOrIsArray(des[key])) {
1581 // replace with src[key] when:
1582 // src[key] or des[key] is not a object, or
1583 // src[key] or des[key] is a array
1584 des[key] = src[key];
1585 }
1586 else {
1587 // src[key] and des[key] are both object, merge them
1588 deepCopy(src[key], des[key]);
1589 }
1590 }
1591 }
1592 }
1593 /* eslint-enable @typescript-eslint/no-explicit-any */
1594
1595 /* eslint-disable @typescript-eslint/no-explicit-any */
1596 const DEVTOOLS_META = '__INTLIFY_META__';
1597 let composerID = 0;
1598 function defineCoreMissingHandler(missing) {
1599 return ((ctx, locale, key, type) => {
1600 return missing(locale, key, compositionApi.getCurrentInstance() || undefined, type);
1601 });
1602 }
1603 // for Intlify DevTools
1604 const getMetaInfo = () => {
1605 const instance = compositionApi.getCurrentInstance();
1606 return instance && instance.type[DEVTOOLS_META] // eslint-disable-line @typescript-eslint/no-explicit-any
1607 ? { [DEVTOOLS_META]: instance.type[DEVTOOLS_META] } // eslint-disable-line @typescript-eslint/no-explicit-any
1608 : null;
1609 };
1610 /**
1611 * Create composer interface factory
1612 *
1613 * @internal
1614 */
1615 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1616 function createComposer(options = {}, VueI18nLegacy) {
1617 const { __root } = options;
1618 const _isGlobal = __root === undefined;
1619 let _inheritLocale = isBoolean(options.inheritLocale)
1620 ? options.inheritLocale
1621 : true;
1622 const _locale = compositionApi.ref(
1623 // prettier-ignore
1624 __root && _inheritLocale
1625 ? __root.locale.value
1626 : isString(options.locale)
1627 ? options.locale
1628 : DEFAULT_LOCALE);
1629 const _fallbackLocale = compositionApi.ref(
1630 // prettier-ignore
1631 __root && _inheritLocale
1632 ? __root.fallbackLocale.value
1633 : isString(options.fallbackLocale) ||
1634 isArray(options.fallbackLocale) ||
1635 isPlainObject(options.fallbackLocale) ||
1636 options.fallbackLocale === false
1637 ? options.fallbackLocale
1638 : _locale.value);
1639 const _messages = compositionApi.ref(getLocaleMessages(_locale.value, options));
1640 // prettier-ignore
1641 const _datetimeFormats = compositionApi.ref(isPlainObject(options.datetimeFormats)
1642 ? options.datetimeFormats
1643 : { [_locale.value]: {} })
1644 ;
1645 // prettier-ignore
1646 const _numberFormats = compositionApi.ref(isPlainObject(options.numberFormats)
1647 ? options.numberFormats
1648 : { [_locale.value]: {} })
1649 ;
1650 // warning suppress options
1651 // prettier-ignore
1652 let _missingWarn = __root
1653 ? __root.missingWarn
1654 : isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
1655 ? options.missingWarn
1656 : true;
1657 // prettier-ignore
1658 let _fallbackWarn = __root
1659 ? __root.fallbackWarn
1660 : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
1661 ? options.fallbackWarn
1662 : true;
1663 // prettier-ignore
1664 let _fallbackRoot = __root
1665 ? __root.fallbackRoot
1666 : isBoolean(options.fallbackRoot)
1667 ? options.fallbackRoot
1668 : true;
1669 // configure fall back to root
1670 let _fallbackFormat = !!options.fallbackFormat;
1671 // runtime missing
1672 let _missing = isFunction(options.missing) ? options.missing : null;
1673 let _runtimeMissing = isFunction(options.missing)
1674 ? defineCoreMissingHandler(options.missing)
1675 : null;
1676 // postTranslation handler
1677 let _postTranslation = isFunction(options.postTranslation)
1678 ? options.postTranslation
1679 : null;
1680 let _warnHtmlMessage = isBoolean(options.warnHtmlMessage)
1681 ? options.warnHtmlMessage
1682 : true;
1683 let _escapeParameter = !!options.escapeParameter;
1684 // custom linked modifiers
1685 // prettier-ignore
1686 const _modifiers = __root
1687 ? __root.modifiers
1688 : isPlainObject(options.modifiers)
1689 ? options.modifiers
1690 : {};
1691 // pluralRules
1692 let _pluralRules = options.pluralRules || (__root && __root.pluralRules);
1693 // for bridge
1694 let __legacy;
1695 {
1696 if (!isLegacyVueI18n(VueI18nLegacy)) {
1697 createI18nError(I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N);
1698 }
1699 const legacyOptions = {
1700 locale: _locale.value,
1701 fallbackLocale: _fallbackLocale.value,
1702 messages: _messages.value,
1703 dateTimeFormats: _datetimeFormats.value,
1704 numberFormats: _numberFormats.value,
1705 modifiers: _modifiers,
1706 missing: _missing,
1707 fallbackRoot: _fallbackRoot,
1708 postTranslation: _postTranslation,
1709 pluralizationRules: _pluralRules,
1710 escapeParameterHtml: _escapeParameter,
1711 sync: _inheritLocale,
1712 silentFallbackWarn: isBoolean(_fallbackWarn)
1713 ? !_fallbackWarn
1714 : _fallbackWarn,
1715 silentTranslationWarn: isBoolean(_missingWarn)
1716 ? !_missingWarn
1717 : _missingWarn,
1718 formatFallbackMessages: isBoolean(_fallbackFormat)
1719 ? !_fallbackFormat
1720 : _fallbackFormat,
1721 warnHtmlInMessage: isBoolean(_warnHtmlMessage)
1722 ? _warnHtmlMessage
1723 ? 'warn'
1724 : 'off'
1725 : 'off'
1726 };
1727 __legacy = new VueI18nLegacy(legacyOptions);
1728 }
1729 // runtime context
1730 // eslint-disable-next-line prefer-const
1731 let _context;
1732 function getCoreContext() {
1733 const ctxOptions = {
1734 version: VERSION,
1735 locale: _locale.value,
1736 fallbackLocale: _fallbackLocale.value,
1737 messages: _messages.value,
1738 modifiers: _modifiers,
1739 pluralRules: _pluralRules,
1740 missing: _runtimeMissing === null ? undefined : _runtimeMissing,
1741 missingWarn: _missingWarn,
1742 fallbackWarn: _fallbackWarn,
1743 fallbackFormat: _fallbackFormat,
1744 unresolving: true,
1745 postTranslation: _postTranslation === null ? undefined : _postTranslation,
1746 warnHtmlMessage: _warnHtmlMessage,
1747 escapeParameter: _escapeParameter,
1748 messageResolver: options.messageResolver,
1749 __meta: { framework: 'vue' }
1750 };
1751 {
1752 ctxOptions.datetimeFormats = _datetimeFormats.value;
1753 ctxOptions.numberFormats = _numberFormats.value;
1754 ctxOptions.__datetimeFormatters = isPlainObject(_context)
1755 ? _context.__datetimeFormatters
1756 : undefined;
1757 ctxOptions.__numberFormatters = isPlainObject(_context)
1758 ? _context.__numberFormatters
1759 : undefined;
1760 }
1761 return createCoreContext(ctxOptions);
1762 }
1763 _context = getCoreContext();
1764 updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
1765 // track reactivity
1766 function trackReactivityValues() {
1767 return [
1768 _locale.value,
1769 _fallbackLocale.value,
1770 _messages.value,
1771 _datetimeFormats.value,
1772 _numberFormats.value
1773 ]
1774 ;
1775 }
1776 // locale
1777 const locale = compositionApi.computed({
1778 get: () => _locale.value,
1779 set: val => {
1780 _locale.value = val;
1781 {
1782 if (__legacy) {
1783 __legacy.locale = val;
1784 }
1785 }
1786 _context.locale = _locale.value;
1787 }
1788 });
1789 // fallbackLocale
1790 const fallbackLocale = compositionApi.computed({
1791 get: () => _fallbackLocale.value,
1792 set: val => {
1793 _fallbackLocale.value = val;
1794 {
1795 if (__legacy) {
1796 __legacy.fallbackLocale = val;
1797 }
1798 }
1799 _context.fallbackLocale = _fallbackLocale.value;
1800 updateFallbackLocale(_context, _locale.value, val);
1801 }
1802 });
1803 // messages
1804 const messages = compositionApi.computed(() => _messages.value);
1805 // datetimeFormats
1806 const datetimeFormats = /* #__PURE__*/ compositionApi.computed(() => _datetimeFormats.value);
1807 // numberFormats
1808 const numberFormats = /* #__PURE__*/ compositionApi.computed(() => _numberFormats.value);
1809 // getPostTranslationHandler
1810 function getPostTranslationHandler() {
1811 return isFunction(_postTranslation) ? _postTranslation : null;
1812 }
1813 // setPostTranslationHandler
1814 function setPostTranslationHandler(handler) {
1815 _postTranslation = handler;
1816 _context.postTranslation = handler;
1817 }
1818 // getMissingHandler
1819 function getMissingHandler() {
1820 return _missing;
1821 }
1822 // setMissingHandler
1823 function setMissingHandler(handler) {
1824 if (handler !== null) {
1825 _runtimeMissing = defineCoreMissingHandler(handler);
1826 }
1827 _missing = handler;
1828 _context.missing = _runtimeMissing;
1829 }
1830 function isResolvedTranslateMessage(type, arg // eslint-disable-line @typescript-eslint/no-explicit-any
1831 ) {
1832 return type !== 'translate' || !arg.resolvedMessage;
1833 }
1834 function wrapWithDeps(fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) {
1835 trackReactivityValues(); // track reactive dependency
1836 // NOTE: experimental !!
1837 let ret;
1838 {
1839 try {
1840 setAdditionalMeta(getMetaInfo());
1841 ret = fn(_context);
1842 }
1843 finally {
1844 setAdditionalMeta(null);
1845 }
1846 }
1847 if (isNumber(ret) && ret === NOT_REOSLVED) {
1848 const [key, arg2] = argumentParser();
1849 if (__root &&
1850 isString(key) &&
1851 isResolvedTranslateMessage(warnType, arg2)) {
1852 if (_fallbackRoot &&
1853 (isTranslateFallbackWarn(_fallbackWarn, key) ||
1854 isTranslateMissingWarn(_missingWarn, key))) {
1855 warn(getWarnMessage(I18nWarnCodes.FALLBACK_TO_ROOT, {
1856 key,
1857 type: warnType
1858 }));
1859 }
1860 }
1861 return __root && _fallbackRoot
1862 ? fallbackSuccess(__root)
1863 : fallbackFail(key);
1864 }
1865 else if (successCondition(ret)) {
1866 return ret;
1867 }
1868 else {
1869 /* istanbul ignore next */
1870 throw createI18nError(I18nErrorCodes.UNEXPECTED_RETURN_TYPE);
1871 }
1872 }
1873 // t
1874 function t(...args) {
1875 return wrapWithDeps(context => Reflect.apply(translate, null, [context, ...args]), () => parseTranslateArgs(...args), 'translate', root => Reflect.apply(root.t, root, [...args]), key => key, val => isString(val));
1876 }
1877 // rt
1878 function rt(...args) {
1879 const [arg1, arg2, arg3] = args;
1880 if (arg3 && !isObject(arg3)) {
1881 throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
1882 }
1883 return t(...[arg1, arg2, assign({ resolvedMessage: true }, arg3 || {})]);
1884 }
1885 // d
1886 function d(...args) {
1887 return wrapWithDeps(context => Reflect.apply(datetime, null, [context, ...args]), () => parseDateTimeArgs(...args), 'datetime format', root => Reflect.apply(root.d, root, [...args]), () => MISSING_RESOLVE_VALUE, val => isString(val));
1888 }
1889 // n
1890 function n(...args) {
1891 return wrapWithDeps(context => Reflect.apply(number, null, [context, ...args]), () => parseNumberArgs(...args), 'number format', root => Reflect.apply(root.n, root, [...args]), () => MISSING_RESOLVE_VALUE, val => isString(val));
1892 }
1893 function setPluralRules(rules) {
1894 _pluralRules = rules;
1895 _context.pluralRules = _pluralRules;
1896 }
1897 // te
1898 function te(key, locale) {
1899 const targetLocale = isString(locale) ? locale : _locale.value;
1900 const message = getLocaleMessage(targetLocale);
1901 return _context.messageResolver(message, key) !== null;
1902 }
1903 function resolveMessages(key) {
1904 let messages = null;
1905 const locales = fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value);
1906 for (let i = 0; i < locales.length; i++) {
1907 const targetLocaleMessages = _messages.value[locales[i]] || {};
1908 const messageValue = _context.messageResolver(targetLocaleMessages, key);
1909 if (messageValue != null) {
1910 messages = messageValue;
1911 break;
1912 }
1913 }
1914 return messages;
1915 }
1916 // tm
1917 function tm(key) {
1918 const messages = resolveMessages(key);
1919 // prettier-ignore
1920 return messages != null
1921 ? messages
1922 : __root
1923 ? __root.tm(key) || {}
1924 : {};
1925 }
1926 // getLocaleMessage
1927 function getLocaleMessage(locale) {
1928 return (_messages.value[locale] || {});
1929 }
1930 // setLocaleMessage
1931 function setLocaleMessage(locale, message) {
1932 _messages.value[locale] = message;
1933 {
1934 __legacy && __legacy.setLocaleMessage(locale, message);
1935 }
1936 _context.messages = _messages.value;
1937 }
1938 // mergeLocaleMessage
1939 function mergeLocaleMessage(locale, message) {
1940 _messages.value[locale] = _messages.value[locale] || {};
1941 {
1942 __legacy && __legacy.mergeLocaleMessage(locale, message);
1943 }
1944 deepCopy(message, _messages.value[locale]);
1945 _context.messages = _messages.value;
1946 }
1947 // getDateTimeFormat
1948 function getDateTimeFormat(locale) {
1949 return _datetimeFormats.value[locale] || {};
1950 }
1951 // setDateTimeFormat
1952 function setDateTimeFormat(locale, format) {
1953 _datetimeFormats.value[locale] = format;
1954 {
1955 __legacy && __legacy.setDateTimeFormat(locale, format);
1956 }
1957 _context.datetimeFormats = _datetimeFormats.value;
1958 clearDateTimeFormat(_context, locale, format);
1959 }
1960 // mergeDateTimeFormat
1961 function mergeDateTimeFormat(locale, format) {
1962 _datetimeFormats.value[locale] = assign(_datetimeFormats.value[locale] || {}, format);
1963 {
1964 __legacy && __legacy.mergeDateTimeFormat(locale, format);
1965 }
1966 _context.datetimeFormats = _datetimeFormats.value;
1967 clearDateTimeFormat(_context, locale, format);
1968 }
1969 // getNumberFormat
1970 function getNumberFormat(locale) {
1971 return _numberFormats.value[locale] || {};
1972 }
1973 // setNumberFormat
1974 function setNumberFormat(locale, format) {
1975 _numberFormats.value[locale] = format;
1976 {
1977 __legacy && __legacy.setNumberFormat(locale, format);
1978 }
1979 _context.numberFormats = _numberFormats.value;
1980 clearNumberFormat(_context, locale, format);
1981 }
1982 // mergeNumberFormat
1983 function mergeNumberFormat(locale, format) {
1984 _numberFormats.value[locale] = assign(_numberFormats.value[locale] || {}, format);
1985 {
1986 __legacy && __legacy.mergeNumberFormat(locale, format);
1987 }
1988 _context.numberFormats = _numberFormats.value;
1989 clearNumberFormat(_context, locale, format);
1990 }
1991 // for debug
1992 composerID++;
1993 // watch root locale & fallbackLocale
1994 if (__root) {
1995 compositionApi.watch(__root.locale, (val) => {
1996 if (_inheritLocale) {
1997 _locale.value = val;
1998 {
1999 if (__legacy) {
2000 __legacy.locale = val;
2001 }
2002 }
2003 _context.locale = val;
2004 updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
2005 }
2006 });
2007 compositionApi.watch(__root.fallbackLocale, (val) => {
2008 if (_inheritLocale) {
2009 _fallbackLocale.value = val;
2010 {
2011 if (__legacy) {
2012 __legacy.fallbackLocale = val;
2013 }
2014 }
2015 _context.fallbackLocale = val;
2016 updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
2017 }
2018 });
2019 }
2020 // define basic composition API!
2021 const composer = {
2022 id: composerID,
2023 locale,
2024 fallbackLocale,
2025 get inheritLocale() {
2026 return _inheritLocale;
2027 },
2028 set inheritLocale(val) {
2029 _inheritLocale = val;
2030 {
2031 if (__legacy) {
2032 __legacy._sync = val;
2033 }
2034 }
2035 if (val && __root) {
2036 _locale.value = __root.locale.value;
2037 _fallbackLocale.value = __root.fallbackLocale.value;
2038 {
2039 if (__legacy) {
2040 __legacy.locale = __root.locale.value;
2041 __legacy.fallbackLocale = __root.fallbackLocale.value;
2042 }
2043 }
2044 updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
2045 }
2046 },
2047 get availableLocales() {
2048 return Object.keys(_messages.value).sort();
2049 },
2050 messages,
2051 get modifiers() {
2052 return _modifiers;
2053 },
2054 get pluralRules() {
2055 return _pluralRules || {};
2056 },
2057 get isGlobal() {
2058 return _isGlobal;
2059 },
2060 get missingWarn() {
2061 return _missingWarn;
2062 },
2063 set missingWarn(val) {
2064 _missingWarn = val;
2065 _context.missingWarn = _missingWarn;
2066 },
2067 get fallbackWarn() {
2068 return _fallbackWarn;
2069 },
2070 set fallbackWarn(val) {
2071 _fallbackWarn = val;
2072 _context.fallbackWarn = _fallbackWarn;
2073 },
2074 get fallbackRoot() {
2075 return _fallbackRoot;
2076 },
2077 set fallbackRoot(val) {
2078 _fallbackRoot = val;
2079 },
2080 get fallbackFormat() {
2081 return _fallbackFormat;
2082 },
2083 set fallbackFormat(val) {
2084 _fallbackFormat = val;
2085 _context.fallbackFormat = _fallbackFormat;
2086 },
2087 get warnHtmlMessage() {
2088 return _warnHtmlMessage;
2089 },
2090 set warnHtmlMessage(val) {
2091 _warnHtmlMessage = val;
2092 _context.warnHtmlMessage = val;
2093 },
2094 get escapeParameter() {
2095 return _escapeParameter;
2096 },
2097 set escapeParameter(val) {
2098 _escapeParameter = val;
2099 _context.escapeParameter = val;
2100 },
2101 t,
2102 getLocaleMessage,
2103 setLocaleMessage,
2104 mergeLocaleMessage,
2105 getPostTranslationHandler,
2106 setPostTranslationHandler,
2107 getMissingHandler,
2108 setMissingHandler,
2109 [SetPluralRulesSymbol]: setPluralRules
2110 };
2111 {
2112 composer.datetimeFormats = datetimeFormats;
2113 composer.numberFormats = numberFormats;
2114 composer.rt = rt;
2115 composer.te = te;
2116 composer.tm = tm;
2117 composer.d = d;
2118 composer.n = n;
2119 composer.getDateTimeFormat = getDateTimeFormat;
2120 composer.setDateTimeFormat = setDateTimeFormat;
2121 composer.mergeDateTimeFormat = mergeDateTimeFormat;
2122 composer.getNumberFormat = getNumberFormat;
2123 composer.setNumberFormat = setNumberFormat;
2124 composer.mergeNumberFormat = mergeNumberFormat;
2125 }
2126 {
2127 composer[LegacyInstanceSymbol] = __legacy;
2128 }
2129 return composer;
2130 }
2131 /* eslint-enable @typescript-eslint/no-explicit-any */
2132
2133 /**
2134 * Port from vue-i18n@v8.x
2135 * This mixin is used when we use vue-i18n-bridge
2136 */
2137 function defineMixin(i18n, VueI18n // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
2138 ) {
2139 return {
2140 beforeCreate() {
2141 const options = this.$options; // eslint-disable-line @typescript-eslint/no-explicit-any
2142 if (options.__VUE18N__INSTANCE__) {
2143 return;
2144 }
2145 options.i18n = options.i18n || (options.__i18n ? {} : null);
2146 this._i18nBridgeRoot = i18n;
2147 if (i18n.mode === 'composition') {
2148 this._i18n = i18n;
2149 return;
2150 }
2151 if (options.i18n) {
2152 if (options.i18n instanceof VueI18n) {
2153 // init locale messages via custom blocks
2154 if (options.__i18n) {
2155 try {
2156 const localeMessages = options.i18n && options.i18n.messages
2157 ? options.i18n.messages
2158 : {};
2159 options.__i18n.forEach(resource => deepCopy(localeMessages, JSON.parse(resource)));
2160 Object.keys(localeMessages).forEach((locale) => {
2161 options.i18n.mergeLocaleMessage(locale, localeMessages[locale]);
2162 });
2163 }
2164 catch (e) {
2165 {
2166 console.error(`Cannot parse locale messages via custom blocks.`, e);
2167 }
2168 }
2169 }
2170 this._i18n = options.i18n;
2171 this._i18nWatcher = this._i18n.watchI18nData();
2172 }
2173 else if (isPlainObject(options.i18n)) {
2174 const rootI18n = this.$root &&
2175 this.$root.$i18n &&
2176 this.$root.$i18n instanceof VueI18n
2177 ? this.$root.$i18n
2178 : null;
2179 // component local i18n
2180 if (rootI18n) {
2181 options.i18n.root = this.$root;
2182 options.i18n.formatter = rootI18n.formatter;
2183 options.i18n.fallbackLocale = rootI18n.fallbackLocale;
2184 options.i18n.formatFallbackMessages =
2185 rootI18n.formatFallbackMessages;
2186 options.i18n.silentTranslationWarn = rootI18n.silentTranslationWarn;
2187 options.i18n.silentFallbackWarn = rootI18n.silentFallbackWarn;
2188 options.i18n.pluralizationRules = rootI18n.pluralizationRules;
2189 options.i18n.preserveDirectiveContent =
2190 rootI18n.preserveDirectiveContent;
2191 }
2192 // init locale messages via custom blocks
2193 if (options.__i18n) {
2194 try {
2195 const localeMessages = options.i18n && options.i18n.messages
2196 ? options.i18n.messages
2197 : {};
2198 options.__i18n.forEach(resource => deepCopy(localeMessages, JSON.parse(resource)));
2199 options.i18n.messages = localeMessages;
2200 }
2201 catch (e) {
2202 {
2203 warn(`Cannot parse locale messages via custom blocks.`, e);
2204 }
2205 }
2206 }
2207 const { sharedMessages } = options.i18n;
2208 if (sharedMessages && isPlainObject(sharedMessages)) {
2209 deepCopy(options.i18n.messages, sharedMessages);
2210 }
2211 this._i18n = new VueI18n(options.i18n);
2212 this._i18nWatcher = this._i18n.watchI18nData();
2213 if (options.i18n.sync === undefined || !!options.i18n.sync) {
2214 this._localeWatcher = this.$i18n.watchLocale();
2215 }
2216 if (rootI18n) {
2217 rootI18n.onComponentInstanceCreated(this._i18n);
2218 }
2219 }
2220 else {
2221 {
2222 warn(`Cannot be interpreted 'i18n' option.`);
2223 }
2224 }
2225 }
2226 else if (this.$root &&
2227 this.$root.$i18n &&
2228 this.$root.$i18n instanceof VueI18n) {
2229 // root i18n
2230 this._i18n = this.$root.$i18n;
2231 }
2232 else if (options.parent &&
2233 options.parent.$i18n &&
2234 options.parent.$i18n instanceof VueI18n) {
2235 // parent i18n
2236 this._i18n = options.parent.$i18n;
2237 }
2238 },
2239 beforeMount() {
2240 const options = this.$options; // eslint-disable-line @typescript-eslint/no-explicit-any
2241 if (options.__VUE18N__INSTANCE__) {
2242 return;
2243 }
2244 options.i18n = options.i18n || (options.__i18n ? {} : null);
2245 if (options.i18n) {
2246 if (options.i18n instanceof VueI18n) {
2247 // init locale messages via custom blocks
2248 this._i18n.subscribeDataChanging(this);
2249 this._subscribing = true;
2250 }
2251 else if (isPlainObject(options.i18n)) {
2252 this._i18n.subscribeDataChanging(this);
2253 this._subscribing = true;
2254 }
2255 else {
2256 {
2257 warn(`Cannot be interpreted 'i18n' option.`);
2258 }
2259 }
2260 }
2261 else if (this.$root &&
2262 this.$root.$i18n &&
2263 this.$root.$i18n instanceof VueI18n) {
2264 this._i18n.subscribeDataChanging(this);
2265 this._subscribing = true;
2266 }
2267 else if (options.parent &&
2268 options.parent.$i18n &&
2269 options.parent.$i18n instanceof VueI18n) {
2270 this._i18n.subscribeDataChanging(this);
2271 this._subscribing = true;
2272 }
2273 },
2274 beforeDestroy() {
2275 const options = this.$options; // eslint-disable-line @typescript-eslint/no-explicit-any
2276 if (options.__VUE18N__INSTANCE__) {
2277 return;
2278 }
2279 if (this._i18nBridgeRoot) {
2280 delete this._i18nBridgeRoot;
2281 return;
2282 }
2283 if (i18n.mode === 'composition') {
2284 delete this._i18n;
2285 return;
2286 }
2287 if (!this._i18n) {
2288 return;
2289 }
2290 const self = this; // eslint-disable-line @typescript-eslint/no-explicit-any
2291 this.$nextTick(() => {
2292 if (self._subscribing) {
2293 self._i18n.unsubscribeDataChanging(self);
2294 delete self._subscribing;
2295 }
2296 if (self._i18nWatcher) {
2297 self._i18nWatcher();
2298 self._i18n.destroyVM();
2299 delete self._i18nWatcher;
2300 }
2301 if (self._localeWatcher) {
2302 self._localeWatcher();
2303 delete self._localeWatcher;
2304 }
2305 });
2306 }
2307 };
2308 }
2309
2310 // for bridge
2311 let _legacyVueI18n = null; // eslint-disable-line @typescript-eslint/no-explicit-any
2312 let _legacyI18n = null; // eslint-disable-line @typescript-eslint/no-explicit-any
2313 /**
2314 * Injection key for {@link useI18n}
2315 *
2316 * @remarks
2317 * The global injection key for I18n instances with `useI18n`. this injection key is used in Web Components.
2318 * Specify the i18n instance created by {@link createI18n} together with `provide` function.
2319 *
2320 * @VueI18nGeneral
2321 */
2322 const I18nInjectionKey =
2323 /* #__PURE__*/ makeSymbol('global-vue-i18n');
2324 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
2325 function createI18n(options = {}, VueI18nLegacy) {
2326 if (_legacyI18n) {
2327 warn(getWarnMessage(I18nWarnCodes.NOT_SUPPORT_MULTI_I18N_INSTANCE));
2328 return _legacyI18n;
2329 }
2330 {
2331 _legacyVueI18n = VueI18nLegacy;
2332 }
2333 // prettier-ignore
2334 const __legacyMode = isBoolean(options.legacy)
2335 ? options.legacy
2336 : true;
2337 !!options.globalInjection;
2338 const __instances = new Map();
2339 const __global = createGlobal(options, __legacyMode, VueI18nLegacy);
2340 function __getInstance(component) {
2341 return __instances.get(component) || null;
2342 }
2343 function __setInstance(component, instance) {
2344 __instances.set(component, instance);
2345 }
2346 function __deleteInstance(component) {
2347 __instances.delete(component);
2348 }
2349 {
2350 // extend legacy VueI18n instance
2351 const i18n = __global[LegacyInstanceSymbol]; // eslint-disable-line @typescript-eslint/no-explicit-any
2352 Object.defineProperty(i18n, 'global', {
2353 get() {
2354 return __global;
2355 }
2356 });
2357 Object.defineProperty(i18n, 'mode', {
2358 get() {
2359 return __legacyMode ? 'legacy' : 'composition';
2360 }
2361 });
2362 Object.defineProperty(i18n, '__instances', {
2363 get() {
2364 return __instances;
2365 }
2366 });
2367 Object.defineProperty(i18n, 'install', {
2368 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2369 value: (Vue) => {
2370 const version = (Vue && Vue.version && Number(Vue.version.split('.')[0])) || -1;
2371 if (version !== 2) {
2372 throw createI18nError(I18nErrorCodes.BRIDGE_SUPPORT_VUE_2_ONLY);
2373 }
2374 Vue.mixin(defineMixin(i18n, _legacyVueI18n));
2375 }
2376 });
2377 const methodMap = {
2378 __getInstance,
2379 __setInstance,
2380 __deleteInstance
2381 };
2382 Object.keys(methodMap).forEach(key => Object.defineProperty(i18n, key, { value: methodMap[key] }) // eslint-disable-line @typescript-eslint/no-explicit-any
2383 );
2384 _legacyI18n = i18n;
2385 return i18n;
2386 }
2387 }
2388 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
2389 function useI18n(options = {}) {
2390 const instance = compositionApi.getCurrentInstance();
2391 if (instance == null) {
2392 throw createI18nError(I18nErrorCodes.MUST_BE_CALL_SETUP_TOP);
2393 }
2394 {
2395 if (_legacyVueI18n == null || _legacyI18n == null) {
2396 throw createI18nError(I18nErrorCodes.NOT_INSLALLED);
2397 }
2398 }
2399 const i18n = getI18nInstance(instance);
2400 const global = getGlobalComposer(i18n);
2401 const componentOptions = getComponentOptions(instance);
2402 const scope = getScope(options, componentOptions);
2403 if (scope === 'global') {
2404 adjustI18nResources(global, options, componentOptions);
2405 return global;
2406 }
2407 if (scope === 'parent') {
2408 let composer = getComposer(i18n, instance);
2409 if (composer == null) {
2410 {
2411 warn(getWarnMessage(I18nWarnCodes.NOT_FOUND_PARENT_SCOPE));
2412 }
2413 composer = global;
2414 }
2415 return composer;
2416 }
2417 // scope 'local' case
2418 if (i18n.mode === 'legacy') {
2419 throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE);
2420 }
2421 const i18nInternal = i18n;
2422 let composer = i18nInternal.__getInstance(instance);
2423 if (composer == null) {
2424 const composerOptions = assign({}, options);
2425 if ('__i18n' in componentOptions) {
2426 composerOptions.__i18n = componentOptions.__i18n;
2427 }
2428 if (global) {
2429 composerOptions.__root = global;
2430 }
2431 composer = createComposer(composerOptions, _legacyVueI18n);
2432 setupLifeCycle(i18nInternal, instance, composer);
2433 i18nInternal.__setInstance(instance, composer);
2434 }
2435 return composer;
2436 }
2437 function createGlobal(options, legacyMode, VueI18nLegacy // eslint-disable-line @typescript-eslint/no-explicit-any
2438 ) {
2439 {
2440 if (!isLegacyVueI18n(VueI18nLegacy)) {
2441 throw createI18nError(I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N);
2442 }
2443 return createComposer(options, VueI18nLegacy);
2444 }
2445 }
2446 function getI18nInstance(instance) {
2447 {
2448 const vm = instance.proxy;
2449 /* istanbul ignore if */
2450 if (vm == null) {
2451 throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
2452 }
2453 const i18n = vm._i18nBridgeRoot; // eslint-disable-line @typescript-eslint/no-explicit-any
2454 /* istanbul ignore if */
2455 if (!i18n) {
2456 throw createI18nError(I18nErrorCodes.NOT_INSLALLED);
2457 }
2458 return i18n;
2459 }
2460 }
2461 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2462 function getComponentOptions(instance) {
2463 return instance.proxy.$options;
2464 }
2465 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2466 function getScope(options, componentOptions) {
2467 // prettier-ignore
2468 return isEmptyObject(options)
2469 ? ('__i18n' in componentOptions)
2470 ? 'local'
2471 : 'global'
2472 : !options.useScope
2473 ? 'local'
2474 : options.useScope;
2475 }
2476 function getGlobalComposer(i18n) {
2477 // prettier-ignore
2478 return i18n.global;
2479 }
2480 function adjustI18nResources(global, options, componentOptions // eslint-disable-line @typescript-eslint/no-explicit-any
2481 ) {
2482 let messages = isObject(options.messages) ? options.messages : {};
2483 if ('__i18nGlobal' in componentOptions) {
2484 messages = getLocaleMessages(global.locale.value, {
2485 messages,
2486 __i18n: componentOptions.__i18nGlobal
2487 });
2488 }
2489 // merge locale messages
2490 const locales = Object.keys(messages);
2491 if (locales.length) {
2492 locales.forEach(locale => {
2493 global.mergeLocaleMessage(locale, messages[locale]);
2494 });
2495 }
2496 {
2497 // merge datetime formats
2498 if (isObject(options.datetimeFormats)) {
2499 const locales = Object.keys(options.datetimeFormats);
2500 if (locales.length) {
2501 locales.forEach(locale => {
2502 global.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
2503 });
2504 }
2505 }
2506 // merge number formats
2507 if (isObject(options.numberFormats)) {
2508 const locales = Object.keys(options.numberFormats);
2509 if (locales.length) {
2510 locales.forEach(locale => {
2511 global.mergeNumberFormat(locale, options.numberFormats[locale]);
2512 });
2513 }
2514 }
2515 }
2516 }
2517 function getComposer(i18n, target) {
2518 let composer = null;
2519 const root = target.root;
2520 let current = target.parent;
2521 while (current != null) {
2522 const i18nInternal = i18n;
2523 if (i18n.mode === 'composition') {
2524 composer = i18nInternal.__getInstance(current);
2525 }
2526 else {
2527 {
2528 const vueI18n = i18nInternal.__getInstance(current);
2529 if (vueI18n != null) {
2530 composer = vueI18n
2531 .__composer;
2532 }
2533 }
2534 }
2535 if (composer != null) {
2536 break;
2537 }
2538 if (root === current) {
2539 break;
2540 }
2541 current = current.parent;
2542 }
2543 return composer;
2544 }
2545 function setupLifeCycle(i18n, target, composer) {
2546 {
2547 // assign legacy VueI18n instance to Vue2 instance
2548 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2549 const vm = target.proxy;
2550 if (vm == null) {
2551 throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
2552 }
2553 // eslint-disable-next-line @typescript-eslint/no-explicit-any
2554 const _i18n = composer[LegacyInstanceSymbol];
2555 if (_i18n === i18n) {
2556 throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
2557 }
2558 vm._i18n = _i18n;
2559 vm._i18n_bridge = true;
2560 vm._i18nWatcher = vm._i18n.watchI18nData();
2561 if (vm._i18n._sync) {
2562 vm._localeWatcher = vm._i18n.watchLocale();
2563 }
2564 let subscribing = false;
2565 compositionApi.onBeforeMount(() => {
2566 vm._i18n.subscribeDataChanging(vm);
2567 subscribing = true;
2568 }, target);
2569 compositionApi.onUnmounted(() => {
2570 if (subscribing) {
2571 vm._i18n.unsubscribeDataChanging(vm);
2572 subscribing = false;
2573 }
2574 if (vm._i18nWatcher) {
2575 vm._i18nWatcher();
2576 vm._i18n.destroyVM();
2577 delete vm._i18nWatcher;
2578 }
2579 if (vm._localeWatcher) {
2580 vm._localeWatcher();
2581 delete vm._localeWatcher;
2582 }
2583 delete vm._i18n_bridge;
2584 delete vm._i18n;
2585 }, target);
2586 }
2587 }
2588
2589 // register message resolver at vue-i18n
2590 registerMessageResolver(resolveValue);
2591 // register fallback locale at vue-i18n
2592 registerLocaleFallbacker(fallbackWithLocaleChain);
2593 // NOTE: experimental !!
2594 {
2595 const target = getGlobalThis();
2596 target.__INTLIFY__ = true;
2597 setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__);
2598 }
2599 {
2600 initDev();
2601 }
2602
2603 exports.I18nInjectionKey = I18nInjectionKey;
2604 exports.VERSION = VERSION;
2605 exports.createI18n = createI18n;
2606 exports.useI18n = useI18n;
2607
2608 Object.defineProperty(exports, '__esModule', { value: true });
2609
2610 return exports;
2611
2612}({}, VueCompositionAPI));