@dcloudio/uni-cli-shared 3.0.0-5020320260806002 → 3.0.0-5020420260811002

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.
Files changed (46) hide show
  1. package/dist/resolve.d.ts +8 -0
  2. package/dist/resolve.js +78 -2
  3. package/lib/dom2/@intlify/core-base/LICENSE +20 -0
  4. package/lib/dom2/@intlify/core-base/dist/core-base.mjs +1903 -0
  5. package/lib/dom2/@intlify/core-base/package.json +11 -0
  6. package/lib/dom2/@intlify/message-compiler/LICENSE +20 -0
  7. package/lib/dom2/@intlify/message-compiler/dist/message-compiler.mjs +1550 -0
  8. package/lib/dom2/@intlify/message-compiler/package.json +11 -0
  9. package/lib/dom2/@intlify/shared/LICENSE +20 -0
  10. package/lib/dom2/@intlify/shared/dist/shared.mjs +333 -0
  11. package/lib/dom2/@intlify/shared/package.json +11 -0
  12. package/lib/dom2/@vue/devtools-api/LICENSE +21 -0
  13. package/lib/dom2/@vue/devtools-api/dist/index.js +26 -0
  14. package/lib/dom2/@vue/devtools-api/package.json +12 -0
  15. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +71 -68
  16. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +71 -68
  17. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +2 -20
  18. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +53 -29
  19. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +23 -12
  20. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +22 -12
  21. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +80 -30
  22. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +5 -5
  23. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +20 -3
  24. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +369 -317
  25. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +5 -5
  26. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +2032 -5522
  27. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +11114 -33
  28. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +2825 -4668
  29. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +905 -2413
  30. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +378 -544
  31. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +998 -2549
  32. package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
  33. package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +26 -92
  34. package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +26 -92
  35. package/lib/dom2/app/@vue/shared/dist/shared.d.ts +2 -94
  36. package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +24 -83
  37. package/lib/dom2/pinia/LICENSE +21 -0
  38. package/lib/dom2/pinia/dist/pinia.mjs +1941 -0
  39. package/lib/dom2/pinia/package.json +11 -0
  40. package/lib/dom2/vue-i18n/LICENSE +20 -0
  41. package/lib/dom2/vue-i18n/dist/vue-i18n.esm-bundler.js +1 -0
  42. package/lib/dom2/vue-i18n/dist/vue-i18n.mjs +2501 -0
  43. package/lib/dom2/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js +1 -0
  44. package/lib/dom2/vue-i18n/dist/vue-i18n.runtime.mjs +2501 -0
  45. package/lib/dom2/vue-i18n/package.json +12 -0
  46. package/package.json +5 -5
@@ -0,0 +1,2501 @@
1
+ /*!
2
+ * vue-i18n v11.4.6
3
+ * (c) 2026 kazuya kawaguchi
4
+ * Released under the MIT License.
5
+ */
6
+ import { createCompileError, CORE_ERROR_CODES_EXTEND_POINT, CORE_WARN_CODES_EXTEND_POINT, isMessageAST, AST_NODE_PROPS_KEYS, DEFAULT_LOCALE, updateFallbackLocale, setFallbackContext, createCoreContext, clearDateTimeFormat, clearNumberFormat, setAdditionalMeta, getFallbackContext, NOT_REOSLVED, isTranslateFallbackWarn, isTranslateMissingWarn, fallbackWithLocaleChain, parseTranslateArgs, translate, MISSING_RESOLVE_VALUE, parseDateTimeArgs, datetime, parseNumberArgs, number, isMessageFunction, NUMBER_FORMAT_OPTIONS_KEYS, DATETIME_FORMAT_OPTIONS_KEYS, registerMessageCompiler, compile, registerMessageResolver, resolveValue, registerLocaleFallbacker, setDevToolsHook } from '@intlify/core-base';
7
+ import { getGlobalThis, makeSymbol, format, isObject, create, isPlainObject, isArray, deepCopy, isString, hasOwn, warn, isBoolean, isRegExp, isFunction, inBrowser, assign, isNumber, createEmitter, warnOnce, isEmptyObject } from '@intlify/shared';
8
+ import * as Vue from 'vue';
9
+ import { createVNode, Text, computed, watch, ref, shallowRef, Fragment, defineComponent, h, getCurrentScope, onScopeDispose, effectScope, inject, onMounted, onUnmounted, isRef } from 'vue';
10
+ import { setupDevtoolsPlugin } from '@vue/devtools-api';
11
+
12
+ /**
13
+ * Vue I18n Version
14
+ *
15
+ * @remarks
16
+ * Semver format. Same format as the package.json `version` field.
17
+ *
18
+ * @VueI18nGeneral
19
+ */
20
+ const VERSION = '11.4.6';
21
+ /**
22
+ * This is only called in esm-bundler builds.
23
+ * istanbul-ignore-next
24
+ */
25
+ function initFeatureFlags() {
26
+ if (typeof __VUE_I18N_FULL_INSTALL__ !== 'boolean') {
27
+ getGlobalThis().__VUE_I18N_FULL_INSTALL__ = true;
28
+ }
29
+ if (typeof __VUE_I18N_LEGACY_API__ !== 'boolean') {
30
+ getGlobalThis().__VUE_I18N_LEGACY_API__ = true;
31
+ }
32
+ if (typeof __INTLIFY_DROP_MESSAGE_COMPILER__ !== 'boolean') {
33
+ getGlobalThis().__INTLIFY_DROP_MESSAGE_COMPILER__ = false;
34
+ }
35
+ if (typeof __INTLIFY_PROD_DEVTOOLS__ !== 'boolean') {
36
+ getGlobalThis().__INTLIFY_PROD_DEVTOOLS__ = false;
37
+ }
38
+ }
39
+
40
+ const I18nErrorCodes = {
41
+ // composer module errors
42
+ UNEXPECTED_RETURN_TYPE: CORE_ERROR_CODES_EXTEND_POINT, // 24
43
+ // legacy module errors
44
+ INVALID_ARGUMENT: 25,
45
+ // i18n module errors
46
+ MUST_BE_CALL_SETUP_TOP: 26,
47
+ NOT_INSTALLED: 27,
48
+ // directive module errors
49
+ REQUIRED_VALUE: 28,
50
+ INVALID_VALUE: 29,
51
+ // vue-devtools errors
52
+ CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: 30,
53
+ NOT_INSTALLED_WITH_PROVIDE: 31,
54
+ // unexpected error
55
+ UNEXPECTED_ERROR: 32,
56
+ // not compatible legacy vue-i18n constructor
57
+ NOT_COMPATIBLE_LEGACY_VUE_I18N: 33,
58
+ // Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly
59
+ NOT_AVAILABLE_COMPOSITION_IN_LEGACY: 34
60
+ };
61
+ function createI18nError(code, ...args) {
62
+ return createCompileError(code, null, (process.env.NODE_ENV !== 'production') ? { messages: errorMessages, args } : undefined);
63
+ }
64
+ const errorMessages = {
65
+ [I18nErrorCodes.UNEXPECTED_RETURN_TYPE]: 'Unexpected return type in composer',
66
+ [I18nErrorCodes.INVALID_ARGUMENT]: 'Invalid argument',
67
+ [I18nErrorCodes.MUST_BE_CALL_SETUP_TOP]: 'Must be called at the top of a `setup` function',
68
+ [I18nErrorCodes.NOT_INSTALLED]: 'Need to install with `app.use` function',
69
+ [I18nErrorCodes.UNEXPECTED_ERROR]: 'Unexpected error',
70
+ [I18nErrorCodes.REQUIRED_VALUE]: `Required in value: {0}`,
71
+ [I18nErrorCodes.INVALID_VALUE]: `Invalid value`,
72
+ [I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN]: `Cannot setup vue-devtools plugin`,
73
+ [I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE]: 'Need to install with `provide` function',
74
+ [I18nErrorCodes.NOT_COMPATIBLE_LEGACY_VUE_I18N]: 'Not compatible legacy VueI18n.',
75
+ [I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY]: 'Not available Compostion API in Legacy API mode. Please make sure that the legacy API mode is working properly'
76
+ };
77
+
78
+ const TranslateVNodeSymbol =
79
+ /* #__PURE__*/ makeSymbol('__translateVNode');
80
+ const DatetimePartsSymbol = /* #__PURE__*/ makeSymbol('__datetimeParts');
81
+ const NumberPartsSymbol = /* #__PURE__*/ makeSymbol('__numberParts');
82
+ const EnableEmitter = /* #__PURE__*/ makeSymbol('__enableEmitter');
83
+ const DisableEmitter = /* #__PURE__*/ makeSymbol('__disableEmitter');
84
+ const SetPluralRulesSymbol = makeSymbol('__setPluralRules');
85
+ makeSymbol('__intlifyMeta');
86
+ const InejctWithOptionSymbol =
87
+ /* #__PURE__*/ makeSymbol('__injectWithOption');
88
+ const DisposeSymbol = /* #__PURE__*/ makeSymbol('__dispose');
89
+
90
+ const I18nWarnCodes = {
91
+ FALLBACK_TO_ROOT: CORE_WARN_CODES_EXTEND_POINT, // 10
92
+ NOT_FOUND_PARENT_SCOPE: (CORE_WARN_CODES_EXTEND_POINT + 1),
93
+ IGNORE_OBJ_FLATTEN: (CORE_WARN_CODES_EXTEND_POINT + 2),
94
+ /**
95
+ * @deprecated will be removed at vue-i18n v12
96
+ */
97
+ DEPRECATE_LEGACY_MODE: (CORE_WARN_CODES_EXTEND_POINT + 3),
98
+ /**
99
+ * @deprecated will be removed at vue-i18n v12
100
+ */
101
+ DEPRECATE_TRANSLATE_CUSTOME_DIRECTIVE: (CORE_WARN_CODES_EXTEND_POINT +
102
+ 4),
103
+ // duplicate `useI18n` calling
104
+ DUPLICATE_USE_I18N_CALLING: (CORE_WARN_CODES_EXTEND_POINT + 5)
105
+ };
106
+ const warnMessages = {
107
+ [I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`,
108
+ [I18nWarnCodes.NOT_FOUND_PARENT_SCOPE]: `Not found parent scope. use the global scope.`,
109
+ [I18nWarnCodes.IGNORE_OBJ_FLATTEN]: `Ignore object flatten: '{key}' key has an string value`,
110
+ /**
111
+ * @deprecated will be removed at vue-i18n v12
112
+ */
113
+ [I18nWarnCodes.DEPRECATE_LEGACY_MODE]: `Legacy API mode has been deprecated in v11. Use Composition API mode instead.\nAbout how to use the Composition API mode, see https://vue-i18n.intlify.dev/guide/advanced/composition.html`,
114
+ /**
115
+ * @deprecated will be removed at vue-i18n v12
116
+ */
117
+ [I18nWarnCodes.DEPRECATE_TRANSLATE_CUSTOME_DIRECTIVE]: `'v-t' has been deprecated in v11. Use translate APIs ('t' or '$t') instead.`,
118
+ [I18nWarnCodes.DUPLICATE_USE_I18N_CALLING]: "Duplicate `useI18n` calling by local scope. Please don't call it on local scope, due to it does not work properly in component."
119
+ };
120
+ function getWarnMessage(code, ...args) {
121
+ return format(warnMessages[code], ...args);
122
+ }
123
+
124
+ /* eslint-disable @typescript-eslint/no-explicit-any */
125
+ /**
126
+ * Transform flat json in obj to normal json in obj
127
+ */
128
+ function handleFlatJson(obj) {
129
+ // check obj
130
+ if (!isObject(obj)) {
131
+ return obj;
132
+ }
133
+ if (isMessageAST(obj)) {
134
+ return obj;
135
+ }
136
+ for (const key in obj) {
137
+ // check key
138
+ if (!hasOwn(obj, key)) {
139
+ continue;
140
+ }
141
+ // handle for normal json
142
+ if (!key.includes('.')) {
143
+ // recursive process value if value is also a object
144
+ if (isObject(obj[key])) {
145
+ handleFlatJson(obj[key]);
146
+ }
147
+ }
148
+ // handle for flat json, transform to normal json
149
+ else {
150
+ // go to the last object
151
+ const subKeys = key.split('.');
152
+ const lastIndex = subKeys.length - 1;
153
+ let currentObj = obj;
154
+ let hasStringValue = false;
155
+ for (let i = 0; i < lastIndex; i++) {
156
+ if (subKeys[i] === '__proto__') {
157
+ throw new Error(`unsafe key: ${subKeys[i]}`);
158
+ }
159
+ if (!(subKeys[i] in currentObj)) {
160
+ currentObj[subKeys[i]] = create();
161
+ }
162
+ if (!isObject(currentObj[subKeys[i]])) {
163
+ (process.env.NODE_ENV !== 'production') &&
164
+ warn(getWarnMessage(I18nWarnCodes.IGNORE_OBJ_FLATTEN, {
165
+ key: subKeys[i]
166
+ }));
167
+ hasStringValue = true;
168
+ break;
169
+ }
170
+ currentObj = currentObj[subKeys[i]];
171
+ }
172
+ // update last object value, delete old property
173
+ if (!hasStringValue) {
174
+ if (!isMessageAST(currentObj)) {
175
+ currentObj[subKeys[lastIndex]] = obj[key];
176
+ delete obj[key];
177
+ }
178
+ else {
179
+ /**
180
+ * NOTE:
181
+ * if the last object is a message AST and subKeys[lastIndex] has message AST prop key, ignore to copy and key deletion
182
+ */
183
+ if (!AST_NODE_PROPS_KEYS.includes(subKeys[lastIndex])) {
184
+ delete obj[key];
185
+ }
186
+ }
187
+ }
188
+ // recursive process value if value is also a object
189
+ if (!isMessageAST(currentObj)) {
190
+ const target = currentObj[subKeys[lastIndex]];
191
+ if (isObject(target)) {
192
+ handleFlatJson(target);
193
+ }
194
+ }
195
+ }
196
+ }
197
+ return obj;
198
+ }
199
+ function getLocaleMessages(locale, options) {
200
+ const { messages, __i18n, messageResolver, flatJson } = options;
201
+ // prettier-ignore
202
+ const ret = (isPlainObject(messages)
203
+ ? messages
204
+ : isArray(__i18n)
205
+ ? create()
206
+ : { [locale]: create() });
207
+ // merge locale messages of i18n custom block
208
+ if (isArray(__i18n)) {
209
+ __i18n.forEach(custom => {
210
+ if ('locale' in custom && 'resource' in custom) {
211
+ const { locale, resource } = custom;
212
+ if (locale) {
213
+ ret[locale] = ret[locale] || create();
214
+ deepCopy(resource, ret[locale]);
215
+ }
216
+ else {
217
+ deepCopy(resource, ret);
218
+ }
219
+ }
220
+ else {
221
+ isString(custom) && deepCopy(JSON.parse(custom), ret);
222
+ }
223
+ });
224
+ }
225
+ // handle messages for flat json
226
+ if (messageResolver == null && flatJson) {
227
+ for (const key in ret) {
228
+ if (hasOwn(ret, key)) {
229
+ handleFlatJson(ret[key]);
230
+ }
231
+ }
232
+ }
233
+ return ret;
234
+ }
235
+ function getComponentOptions(instance) {
236
+ return instance.type;
237
+ }
238
+ function adjustI18nResources(gl, options, componentOptions) {
239
+ // prettier-ignore
240
+ let messages = isObject(options.messages)
241
+ ? options.messages
242
+ : create();
243
+ if ('__i18nGlobal' in componentOptions) {
244
+ messages = getLocaleMessages(gl.locale.value, {
245
+ messages,
246
+ __i18n: componentOptions.__i18nGlobal
247
+ });
248
+ }
249
+ // merge locale messages
250
+ const locales = Object.keys(messages);
251
+ if (locales.length) {
252
+ locales.forEach(locale => {
253
+ gl.mergeLocaleMessage(locale, messages[locale]);
254
+ });
255
+ }
256
+ {
257
+ // merge datetime formats
258
+ if (isObject(options.datetimeFormats)) {
259
+ const locales = Object.keys(options.datetimeFormats);
260
+ if (locales.length) {
261
+ locales.forEach(locale => {
262
+ gl.mergeDateTimeFormat(locale, options.datetimeFormats[locale]);
263
+ });
264
+ }
265
+ }
266
+ // merge number formats
267
+ if (isObject(options.numberFormats)) {
268
+ const locales = Object.keys(options.numberFormats);
269
+ if (locales.length) {
270
+ locales.forEach(locale => {
271
+ gl.mergeNumberFormat(locale, options.numberFormats[locale]);
272
+ });
273
+ }
274
+ }
275
+ }
276
+ }
277
+ function createTextNode(key) {
278
+ return createVNode(Text, null, key, 0);
279
+ }
280
+ function getCurrentInstance() {
281
+ // NOTE(kazupon): avoid bundler warning
282
+ const key = 'currentInstance';
283
+ if (key in Vue) {
284
+ return Vue[key];
285
+ }
286
+ else {
287
+ return Vue.getCurrentInstance();
288
+ }
289
+ }
290
+ /* eslint-enable @typescript-eslint/no-explicit-any */
291
+
292
+ /* eslint-disable @typescript-eslint/no-explicit-any */
293
+ // extend VNode interface
294
+ const DEVTOOLS_META = '__INTLIFY_META__';
295
+ const NOOP_RETURN_ARRAY = () => [];
296
+ const NOOP_RETURN_FALSE = () => false;
297
+ let composerID = 0;
298
+ function defineCoreMissingHandler(missing) {
299
+ return ((ctx, locale, key, type) => {
300
+ return missing(locale, key, getCurrentInstance() || undefined, type);
301
+ });
302
+ }
303
+ // for Intlify DevTools
304
+ /* #__NO_SIDE_EFFECTS__ */
305
+ const getMetaInfo = () => {
306
+ const instance = getCurrentInstance();
307
+ let meta = null;
308
+ return instance && (meta = getComponentOptions(instance)[DEVTOOLS_META])
309
+ ? { [DEVTOOLS_META]: meta }
310
+ : null;
311
+ };
312
+ /**
313
+ * Create composer interface factory
314
+ *
315
+ * @internal
316
+ */
317
+ function createComposer(options = {}) {
318
+ const { __root, __injectWithOption } = options;
319
+ const _isGlobal = __root === undefined;
320
+ const flatJson = options.flatJson;
321
+ const _ref = inBrowser ? ref : shallowRef;
322
+ let _inheritLocale = isBoolean(options.inheritLocale)
323
+ ? options.inheritLocale
324
+ : true;
325
+ const _locale = _ref(
326
+ // prettier-ignore
327
+ __root && _inheritLocale
328
+ ? __root.locale.value
329
+ : isString(options.locale)
330
+ ? options.locale
331
+ : DEFAULT_LOCALE);
332
+ const _fallbackLocale = _ref(
333
+ // prettier-ignore
334
+ __root && _inheritLocale
335
+ ? __root.fallbackLocale.value
336
+ : isString(options.fallbackLocale) ||
337
+ isArray(options.fallbackLocale) ||
338
+ isPlainObject(options.fallbackLocale) ||
339
+ options.fallbackLocale === false
340
+ ? options.fallbackLocale
341
+ : _locale.value);
342
+ const _messages = _ref(getLocaleMessages(_locale.value, options));
343
+ // prettier-ignore
344
+ const _datetimeFormats = _ref(isPlainObject(options.datetimeFormats)
345
+ ? options.datetimeFormats
346
+ : { [_locale.value]: {} })
347
+ ;
348
+ // prettier-ignore
349
+ const _numberFormats = _ref(isPlainObject(options.numberFormats)
350
+ ? options.numberFormats
351
+ : { [_locale.value]: {} })
352
+ ;
353
+ // warning suppress options
354
+ // prettier-ignore
355
+ let _missingWarn = __root
356
+ ? __root.missingWarn
357
+ : isBoolean(options.missingWarn) || isRegExp(options.missingWarn)
358
+ ? options.missingWarn
359
+ : true;
360
+ // prettier-ignore
361
+ let _fallbackWarn = __root
362
+ ? __root.fallbackWarn
363
+ : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn)
364
+ ? options.fallbackWarn
365
+ : true;
366
+ // prettier-ignore
367
+ let _fallbackRoot = __root
368
+ ? __root.fallbackRoot
369
+ : isBoolean(options.fallbackRoot)
370
+ ? options.fallbackRoot
371
+ : true;
372
+ // configure fall back to root
373
+ let _fallbackFormat = !!options.fallbackFormat;
374
+ // runtime missing
375
+ let _missing = isFunction(options.missing) ? options.missing : null;
376
+ let _runtimeMissing = isFunction(options.missing)
377
+ ? defineCoreMissingHandler(options.missing)
378
+ : null;
379
+ // postTranslation handler
380
+ let _postTranslation = isFunction(options.postTranslation)
381
+ ? options.postTranslation
382
+ : null;
383
+ // prettier-ignore
384
+ let _warnHtmlMessage = __root
385
+ ? __root.warnHtmlMessage
386
+ : isBoolean(options.warnHtmlMessage)
387
+ ? options.warnHtmlMessage
388
+ : true;
389
+ let _escapeParameter = !!options.escapeParameter;
390
+ // custom linked modifiers
391
+ // prettier-ignore
392
+ const _modifiers = __root
393
+ ? __root.modifiers
394
+ : isPlainObject(options.modifiers)
395
+ ? options.modifiers
396
+ : {};
397
+ // pluralRules
398
+ let _pluralRules = options.pluralRules || (__root && __root.pluralRules);
399
+ // runtime context
400
+ // eslint-disable-next-line prefer-const
401
+ let _context;
402
+ const getCoreContext = () => {
403
+ _isGlobal && setFallbackContext(null);
404
+ const ctxOptions = {
405
+ version: VERSION,
406
+ locale: _locale.value,
407
+ fallbackLocale: _fallbackLocale.value,
408
+ messages: _messages.value,
409
+ modifiers: _modifiers,
410
+ pluralRules: _pluralRules,
411
+ missing: _runtimeMissing === null ? undefined : _runtimeMissing,
412
+ missingWarn: _missingWarn,
413
+ fallbackWarn: _fallbackWarn,
414
+ fallbackFormat: _fallbackFormat,
415
+ unresolving: true,
416
+ postTranslation: _postTranslation === null ? undefined : _postTranslation,
417
+ warnHtmlMessage: _warnHtmlMessage,
418
+ escapeParameter: _escapeParameter,
419
+ messageResolver: options.messageResolver,
420
+ messageCompiler: options.messageCompiler,
421
+ __meta: { framework: 'vue' }
422
+ };
423
+ {
424
+ ctxOptions.datetimeFormats = _datetimeFormats.value;
425
+ ctxOptions.numberFormats = _numberFormats.value;
426
+ ctxOptions.__datetimeFormatters = isPlainObject(_context)
427
+ ? _context.__datetimeFormatters
428
+ : undefined;
429
+ ctxOptions.__numberFormatters = isPlainObject(_context)
430
+ ? _context.__numberFormatters
431
+ : undefined;
432
+ }
433
+ if ((process.env.NODE_ENV !== 'production')) {
434
+ ctxOptions.__v_emitter = isPlainObject(_context)
435
+ ? _context.__v_emitter
436
+ : undefined;
437
+ }
438
+ const ctx = createCoreContext(ctxOptions);
439
+ _isGlobal && setFallbackContext(ctx);
440
+ return ctx;
441
+ };
442
+ _context = getCoreContext();
443
+ updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
444
+ // track reactivity
445
+ function trackReactivityValues() {
446
+ return [
447
+ _locale.value,
448
+ _fallbackLocale.value,
449
+ _messages.value,
450
+ _datetimeFormats.value,
451
+ _numberFormats.value
452
+ ]
453
+ ;
454
+ }
455
+ // locale
456
+ const locale = computed({
457
+ get: () => _locale.value,
458
+ set: val => {
459
+ _context.locale = val;
460
+ _locale.value = val;
461
+ }
462
+ });
463
+ // fallbackLocale
464
+ const fallbackLocale = computed({
465
+ get: () => _fallbackLocale.value,
466
+ set: val => {
467
+ _context.fallbackLocale = val;
468
+ _fallbackLocale.value = val;
469
+ updateFallbackLocale(_context, _locale.value, val);
470
+ }
471
+ });
472
+ // messages
473
+ const messages = computed(() => _messages.value);
474
+ // datetimeFormats
475
+ const datetimeFormats = /* #__PURE__*/ computed(() => _datetimeFormats.value);
476
+ // numberFormats
477
+ const numberFormats = /* #__PURE__*/ computed(() => _numberFormats.value);
478
+ // getPostTranslationHandler
479
+ function getPostTranslationHandler() {
480
+ return isFunction(_postTranslation) ? _postTranslation : null;
481
+ }
482
+ // setPostTranslationHandler
483
+ function setPostTranslationHandler(handler) {
484
+ _postTranslation = handler;
485
+ _context.postTranslation = handler;
486
+ }
487
+ // getMissingHandler
488
+ function getMissingHandler() {
489
+ return _missing;
490
+ }
491
+ // setMissingHandler
492
+ function setMissingHandler(handler) {
493
+ if (handler !== null) {
494
+ _runtimeMissing = defineCoreMissingHandler(handler);
495
+ }
496
+ _missing = handler;
497
+ _context.missing = _runtimeMissing;
498
+ }
499
+ function isResolvedTranslateMessage(type, arg) {
500
+ return type !== 'translate' || !arg.resolvedMessage;
501
+ }
502
+ const wrapWithDeps = (fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) => {
503
+ trackReactivityValues(); // track reactive dependency
504
+ // NOTE: experimental !!
505
+ let ret;
506
+ try {
507
+ if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
508
+ setAdditionalMeta(getMetaInfo());
509
+ }
510
+ if (!_isGlobal) {
511
+ _context.fallbackContext = __root
512
+ ? getFallbackContext()
513
+ : undefined;
514
+ }
515
+ ret = fn(_context);
516
+ }
517
+ finally {
518
+ if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
519
+ setAdditionalMeta(null);
520
+ }
521
+ if (!_isGlobal) {
522
+ _context.fallbackContext = undefined;
523
+ }
524
+ }
525
+ if ((warnType !== 'translate exists' && // for not `te` (e.g `t`)
526
+ isNumber(ret) &&
527
+ ret === NOT_REOSLVED) ||
528
+ (warnType === 'translate exists' && !ret) // for `te`
529
+ ) {
530
+ const [key, arg2] = argumentParser();
531
+ if ((process.env.NODE_ENV !== 'production') &&
532
+ __root &&
533
+ isString(key) &&
534
+ isResolvedTranslateMessage(warnType, arg2)) {
535
+ if (_fallbackRoot &&
536
+ (isTranslateFallbackWarn(_fallbackWarn, key) ||
537
+ isTranslateMissingWarn(_missingWarn, key))) {
538
+ warn(getWarnMessage(I18nWarnCodes.FALLBACK_TO_ROOT, {
539
+ key,
540
+ type: warnType
541
+ }));
542
+ }
543
+ // for vue-devtools timeline event
544
+ if ((process.env.NODE_ENV !== 'production')) {
545
+ const { __v_emitter: emitter } = _context;
546
+ if (emitter && _fallbackRoot) {
547
+ emitter.emit('fallback', {
548
+ type: warnType,
549
+ key,
550
+ to: 'global',
551
+ groupId: `${warnType}:${key}`
552
+ });
553
+ }
554
+ }
555
+ }
556
+ return __root && _fallbackRoot
557
+ ? fallbackSuccess(__root)
558
+ : fallbackFail(key);
559
+ }
560
+ else if (successCondition(ret)) {
561
+ return ret;
562
+ }
563
+ else {
564
+ /* istanbul ignore next */
565
+ throw createI18nError(I18nErrorCodes.UNEXPECTED_RETURN_TYPE);
566
+ }
567
+ };
568
+ // t
569
+ function t(...args) {
570
+ return wrapWithDeps(context => Reflect.apply(translate, null, [context, ...args]), () => parseTranslateArgs(...args), 'translate', root => Reflect.apply(root.t, root, [...args]), key => key, val => isString(val));
571
+ }
572
+ // rt
573
+ function rt(...args) {
574
+ const [arg1, arg2, arg3] = args;
575
+ if (arg3 && !isObject(arg3)) {
576
+ throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT);
577
+ }
578
+ return t(...[arg1, arg2, assign({ resolvedMessage: true }, arg3 || {})]);
579
+ }
580
+ // d
581
+ function d(...args) {
582
+ 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) || isArray(val));
583
+ }
584
+ // n
585
+ function n(...args) {
586
+ 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) || isArray(val));
587
+ }
588
+ // for custom processor
589
+ function normalize(values) {
590
+ return values.map(val => isString(val) || isNumber(val) || isBoolean(val)
591
+ ? createTextNode(String(val))
592
+ : val);
593
+ }
594
+ const interpolate = (val) => val;
595
+ const processor = {
596
+ normalize,
597
+ interpolate,
598
+ type: 'vnode'
599
+ };
600
+ // translateVNode, using for `i18n-t` component
601
+ function translateVNode(...args) {
602
+ return wrapWithDeps(context => {
603
+ let ret;
604
+ const _context = context;
605
+ try {
606
+ _context.processor = processor;
607
+ ret = Reflect.apply(translate, null, [_context, ...args]);
608
+ }
609
+ finally {
610
+ _context.processor = null;
611
+ }
612
+ return ret;
613
+ }, () => parseTranslateArgs(...args), 'translate', root => root[TranslateVNodeSymbol](...args), key => [createTextNode(key)], val => isArray(val));
614
+ }
615
+ // numberParts, using for `i18n-n` component
616
+ function numberParts(...args) {
617
+ return wrapWithDeps(context => Reflect.apply(number, null, [context, ...args]), () => parseNumberArgs(...args), 'number format', root => root[NumberPartsSymbol](...args), NOOP_RETURN_ARRAY, val => isString(val) || isArray(val));
618
+ }
619
+ // datetimeParts, using for `i18n-d` component
620
+ function datetimeParts(...args) {
621
+ return wrapWithDeps(context => Reflect.apply(datetime, null, [context, ...args]), () => parseDateTimeArgs(...args), 'datetime format', root => root[DatetimePartsSymbol](...args), NOOP_RETURN_ARRAY, val => isString(val) || isArray(val));
622
+ }
623
+ function setPluralRules(rules) {
624
+ _pluralRules = rules;
625
+ _context.pluralRules = _pluralRules;
626
+ }
627
+ // te
628
+ function te(key, locale) {
629
+ return wrapWithDeps(() => {
630
+ if (!key) {
631
+ return false;
632
+ }
633
+ const targetLocale = isString(locale) ? locale : _locale.value;
634
+ // When locale is explicitly specified, check only that locale (no fallback chain)
635
+ // When locale is not specified, check the fallback locale chain
636
+ const locales = isString(locale)
637
+ ? [targetLocale]
638
+ : fallbackWithLocaleChain(_context, _fallbackLocale.value, targetLocale);
639
+ for (let i = 0; i < locales.length; i++) {
640
+ const message = getLocaleMessage(locales[i]);
641
+ let resolved = _context.messageResolver(message, key);
642
+ // if null, resolve with object key path (for flat keys containing dots)
643
+ if (resolved === null) {
644
+ resolved = message[key];
645
+ }
646
+ if (isMessageAST(resolved) ||
647
+ isMessageFunction(resolved) ||
648
+ isString(resolved)) {
649
+ return true;
650
+ }
651
+ }
652
+ return false;
653
+ }, () => [key], 'translate exists', root => {
654
+ return Reflect.apply(root.te, root, [key, locale]);
655
+ }, NOOP_RETURN_FALSE, val => isBoolean(val));
656
+ }
657
+ function resolveMessages(key) {
658
+ let messages = null;
659
+ const locales = fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value);
660
+ for (let i = 0; i < locales.length; i++) {
661
+ const targetLocaleMessages = _messages.value[locales[i]] || {};
662
+ const messageValue = _context.messageResolver(targetLocaleMessages, key);
663
+ if (messageValue != null) {
664
+ messages = messageValue;
665
+ break;
666
+ }
667
+ }
668
+ return messages;
669
+ }
670
+ // tm
671
+ function tm(key) {
672
+ const messages = resolveMessages(key);
673
+ // prettier-ignore
674
+ return messages != null
675
+ ? messages
676
+ : __root
677
+ ? __root.tm(key) || {}
678
+ : {};
679
+ }
680
+ // getLocaleMessage
681
+ function getLocaleMessage(locale) {
682
+ return (_messages.value[locale] || {});
683
+ }
684
+ // setLocaleMessage
685
+ function setLocaleMessage(locale, message) {
686
+ if (flatJson) {
687
+ const _message = { [locale]: message };
688
+ for (const key in _message) {
689
+ if (hasOwn(_message, key)) {
690
+ handleFlatJson(_message[key]);
691
+ }
692
+ }
693
+ message = _message[locale];
694
+ }
695
+ _messages.value[locale] = message;
696
+ _context.messages = _messages.value;
697
+ }
698
+ // mergeLocaleMessage
699
+ function mergeLocaleMessage(locale, message) {
700
+ _messages.value[locale] = _messages.value[locale] || {};
701
+ const _message = { [locale]: message };
702
+ if (flatJson) {
703
+ for (const key in _message) {
704
+ if (hasOwn(_message, key)) {
705
+ handleFlatJson(_message[key]);
706
+ }
707
+ }
708
+ }
709
+ message = _message[locale];
710
+ deepCopy(message, _messages.value[locale]);
711
+ _context.messages = _messages.value;
712
+ }
713
+ // getDateTimeFormat
714
+ function getDateTimeFormat(locale) {
715
+ return _datetimeFormats.value[locale] || {};
716
+ }
717
+ // setDateTimeFormat
718
+ function setDateTimeFormat(locale, format) {
719
+ _datetimeFormats.value[locale] = format;
720
+ _context.datetimeFormats = _datetimeFormats.value;
721
+ clearDateTimeFormat(_context, locale, format);
722
+ }
723
+ // mergeDateTimeFormat
724
+ function mergeDateTimeFormat(locale, format) {
725
+ _datetimeFormats.value[locale] = assign(_datetimeFormats.value[locale] || {}, format);
726
+ _context.datetimeFormats = _datetimeFormats.value;
727
+ clearDateTimeFormat(_context, locale, format);
728
+ }
729
+ // getNumberFormat
730
+ function getNumberFormat(locale) {
731
+ return _numberFormats.value[locale] || {};
732
+ }
733
+ // setNumberFormat
734
+ function setNumberFormat(locale, format) {
735
+ _numberFormats.value[locale] = format;
736
+ _context.numberFormats = _numberFormats.value;
737
+ clearNumberFormat(_context, locale, format);
738
+ }
739
+ // mergeNumberFormat
740
+ function mergeNumberFormat(locale, format) {
741
+ _numberFormats.value[locale] = assign(_numberFormats.value[locale] || {}, format);
742
+ _context.numberFormats = _numberFormats.value;
743
+ clearNumberFormat(_context, locale, format);
744
+ }
745
+ // for debug
746
+ composerID++;
747
+ // watch root locale & fallbackLocale
748
+ if (__root && inBrowser) {
749
+ watch(__root.locale, (val) => {
750
+ if (_inheritLocale) {
751
+ _locale.value = val;
752
+ _context.locale = val;
753
+ updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
754
+ }
755
+ });
756
+ watch(__root.fallbackLocale, (val) => {
757
+ if (_inheritLocale) {
758
+ _fallbackLocale.value = val;
759
+ _context.fallbackLocale = val;
760
+ updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
761
+ }
762
+ });
763
+ }
764
+ // define basic composition API!
765
+ const composer = {
766
+ id: composerID,
767
+ locale,
768
+ fallbackLocale,
769
+ get inheritLocale() {
770
+ return _inheritLocale;
771
+ },
772
+ set inheritLocale(val) {
773
+ _inheritLocale = val;
774
+ if (val && __root) {
775
+ _locale.value = __root.locale.value;
776
+ _fallbackLocale.value = __root.fallbackLocale.value;
777
+ updateFallbackLocale(_context, _locale.value, _fallbackLocale.value);
778
+ }
779
+ },
780
+ get availableLocales() {
781
+ return Object.keys(_messages.value).sort();
782
+ },
783
+ messages,
784
+ get modifiers() {
785
+ return _modifiers;
786
+ },
787
+ get pluralRules() {
788
+ return _pluralRules || {};
789
+ },
790
+ get isGlobal() {
791
+ return _isGlobal;
792
+ },
793
+ get missingWarn() {
794
+ return _missingWarn;
795
+ },
796
+ set missingWarn(val) {
797
+ _missingWarn = val;
798
+ _context.missingWarn = _missingWarn;
799
+ },
800
+ get fallbackWarn() {
801
+ return _fallbackWarn;
802
+ },
803
+ set fallbackWarn(val) {
804
+ _fallbackWarn = val;
805
+ _context.fallbackWarn = _fallbackWarn;
806
+ },
807
+ get fallbackRoot() {
808
+ return _fallbackRoot;
809
+ },
810
+ set fallbackRoot(val) {
811
+ _fallbackRoot = val;
812
+ },
813
+ get fallbackFormat() {
814
+ return _fallbackFormat;
815
+ },
816
+ set fallbackFormat(val) {
817
+ _fallbackFormat = val;
818
+ _context.fallbackFormat = _fallbackFormat;
819
+ },
820
+ get warnHtmlMessage() {
821
+ return _warnHtmlMessage;
822
+ },
823
+ set warnHtmlMessage(val) {
824
+ _warnHtmlMessage = val;
825
+ _context.warnHtmlMessage = val;
826
+ },
827
+ get escapeParameter() {
828
+ return _escapeParameter;
829
+ },
830
+ set escapeParameter(val) {
831
+ _escapeParameter = val;
832
+ _context.escapeParameter = val;
833
+ },
834
+ t,
835
+ getLocaleMessage,
836
+ setLocaleMessage,
837
+ mergeLocaleMessage,
838
+ getPostTranslationHandler,
839
+ setPostTranslationHandler,
840
+ getMissingHandler,
841
+ setMissingHandler,
842
+ [SetPluralRulesSymbol]: setPluralRules
843
+ };
844
+ {
845
+ composer.datetimeFormats = datetimeFormats;
846
+ composer.numberFormats = numberFormats;
847
+ composer.rt = rt;
848
+ composer.te = te;
849
+ composer.tm = tm;
850
+ composer.d = d;
851
+ composer.n = n;
852
+ composer.getDateTimeFormat = getDateTimeFormat;
853
+ composer.setDateTimeFormat = setDateTimeFormat;
854
+ composer.mergeDateTimeFormat = mergeDateTimeFormat;
855
+ composer.getNumberFormat = getNumberFormat;
856
+ composer.setNumberFormat = setNumberFormat;
857
+ composer.mergeNumberFormat = mergeNumberFormat;
858
+ composer[InejctWithOptionSymbol] = __injectWithOption;
859
+ composer[TranslateVNodeSymbol] = translateVNode;
860
+ composer[DatetimePartsSymbol] = datetimeParts;
861
+ composer[NumberPartsSymbol] = numberParts;
862
+ }
863
+ // for vue-devtools timeline event
864
+ if ((process.env.NODE_ENV !== 'production')) {
865
+ composer[EnableEmitter] = (emitter) => {
866
+ _context.__v_emitter = emitter;
867
+ };
868
+ composer[DisableEmitter] = () => {
869
+ _context.__v_emitter = undefined;
870
+ };
871
+ }
872
+ return composer;
873
+ }
874
+ /* eslint-enable @typescript-eslint/no-explicit-any */
875
+
876
+ const VUE_I18N_COMPONENT_TYPES = 'vue-i18n: composer properties';
877
+ const VueDevToolsLabels = {
878
+ 'vue-devtools-plugin-vue-i18n': 'Vue I18n DevTools',
879
+ 'vue-i18n-resource-inspector': 'Vue I18n DevTools',
880
+ 'vue-i18n-timeline': 'Vue I18n'
881
+ };
882
+ const VueDevToolsPlaceholders = {
883
+ 'vue-i18n-resource-inspector': 'Search for scopes ...'
884
+ };
885
+ const VueDevToolsTimelineColors = {
886
+ 'vue-i18n-timeline': 0xffcd19
887
+ };
888
+ let devtoolsApi;
889
+ async function enableDevTools(app, i18n) {
890
+ return new Promise((resolve, reject) => {
891
+ try {
892
+ setupDevtoolsPlugin({
893
+ id: 'vue-devtools-plugin-vue-i18n',
894
+ label: VueDevToolsLabels['vue-devtools-plugin-vue-i18n'],
895
+ packageName: 'vue-i18n',
896
+ homepage: 'https://vue-i18n.intlify.dev',
897
+ logo: 'https://vue-i18n.intlify.dev/vue-i18n-devtools-logo.png',
898
+ componentStateTypes: [VUE_I18N_COMPONENT_TYPES],
899
+ app: app // eslint-disable-line @typescript-eslint/no-explicit-any
900
+ }, api => {
901
+ devtoolsApi = api;
902
+ api.on.visitComponentTree(({ componentInstance, treeNode }) => {
903
+ updateComponentTreeTags(componentInstance, treeNode, i18n);
904
+ });
905
+ api.on.inspectComponent(({ componentInstance, instanceData }) => {
906
+ if (componentInstance.__VUE_I18N__ && instanceData) {
907
+ if (i18n.mode === 'legacy') {
908
+ // ignore global scope on legacy mode
909
+ if (componentInstance.__VUE_I18N__ !==
910
+ i18n.global.__composer) {
911
+ inspectComposer(instanceData, componentInstance.__VUE_I18N__);
912
+ }
913
+ }
914
+ else {
915
+ inspectComposer(instanceData, componentInstance.__VUE_I18N__);
916
+ }
917
+ }
918
+ });
919
+ api.addInspector({
920
+ id: 'vue-i18n-resource-inspector',
921
+ label: VueDevToolsLabels['vue-i18n-resource-inspector'],
922
+ icon: 'language',
923
+ treeFilterPlaceholder: VueDevToolsPlaceholders['vue-i18n-resource-inspector']
924
+ });
925
+ api.on.getInspectorTree(payload => {
926
+ if (payload.app === app &&
927
+ payload.inspectorId === 'vue-i18n-resource-inspector') {
928
+ registerScope(payload, i18n);
929
+ }
930
+ });
931
+ const roots = new Map();
932
+ api.on.getInspectorState(async (payload) => {
933
+ if (payload.app === app &&
934
+ payload.inspectorId === 'vue-i18n-resource-inspector') {
935
+ api.unhighlightElement();
936
+ inspectScope(payload, i18n);
937
+ if (payload.nodeId === 'global') {
938
+ if (!roots.has(payload.app)) {
939
+ const [root] = await api.getComponentInstances(payload.app);
940
+ roots.set(payload.app, root);
941
+ }
942
+ api.highlightElement(roots.get(payload.app));
943
+ }
944
+ else {
945
+ const instance = getComponentInstance(payload.nodeId, i18n);
946
+ instance && api.highlightElement(instance);
947
+ }
948
+ }
949
+ });
950
+ api.on.editInspectorState(payload => {
951
+ if (payload.app === app &&
952
+ payload.inspectorId === 'vue-i18n-resource-inspector') {
953
+ editScope(payload, i18n);
954
+ }
955
+ });
956
+ api.addTimelineLayer({
957
+ id: 'vue-i18n-timeline',
958
+ label: VueDevToolsLabels['vue-i18n-timeline'],
959
+ color: VueDevToolsTimelineColors['vue-i18n-timeline']
960
+ });
961
+ resolve(true);
962
+ });
963
+ }
964
+ catch (e) {
965
+ console.error(e);
966
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
967
+ reject(false);
968
+ }
969
+ });
970
+ }
971
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
972
+ function getI18nScopeLable(instance) {
973
+ return (instance.type.name ||
974
+ instance.type.displayName ||
975
+ instance.type.__file ||
976
+ 'Anonymous');
977
+ }
978
+ function updateComponentTreeTags(instance, // eslint-disable-line @typescript-eslint/no-explicit-any
979
+ treeNode, i18n) {
980
+ // prettier-ignore
981
+ const global = i18n.mode === 'composition'
982
+ ? i18n.global
983
+ : i18n.global.__composer;
984
+ if (instance && instance.__VUE_I18N__) {
985
+ // add custom tags local scope only
986
+ if (instance.__VUE_I18N__ !== global) {
987
+ const tag = {
988
+ label: `i18n (${getI18nScopeLable(instance)} Scope)`,
989
+ textColor: 0x000000,
990
+ backgroundColor: 0xffcd19
991
+ };
992
+ treeNode.tags.push(tag);
993
+ }
994
+ }
995
+ }
996
+ function inspectComposer(instanceData, composer) {
997
+ const type = VUE_I18N_COMPONENT_TYPES;
998
+ instanceData.state.push({
999
+ type,
1000
+ key: 'locale',
1001
+ editable: true,
1002
+ value: composer.locale.value
1003
+ });
1004
+ instanceData.state.push({
1005
+ type,
1006
+ key: 'availableLocales',
1007
+ editable: false,
1008
+ value: composer.availableLocales
1009
+ });
1010
+ instanceData.state.push({
1011
+ type,
1012
+ key: 'fallbackLocale',
1013
+ editable: true,
1014
+ value: composer.fallbackLocale.value
1015
+ });
1016
+ instanceData.state.push({
1017
+ type,
1018
+ key: 'inheritLocale',
1019
+ editable: true,
1020
+ value: composer.inheritLocale
1021
+ });
1022
+ instanceData.state.push({
1023
+ type,
1024
+ key: 'messages',
1025
+ editable: false,
1026
+ value: getLocaleMessageValue(composer.messages.value)
1027
+ });
1028
+ {
1029
+ instanceData.state.push({
1030
+ type,
1031
+ key: 'datetimeFormats',
1032
+ editable: false,
1033
+ value: composer.datetimeFormats.value
1034
+ });
1035
+ instanceData.state.push({
1036
+ type,
1037
+ key: 'numberFormats',
1038
+ editable: false,
1039
+ value: composer.numberFormats.value
1040
+ });
1041
+ }
1042
+ }
1043
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1044
+ function getLocaleMessageValue(messages) {
1045
+ const value = {};
1046
+ Object.keys(messages).forEach((key) => {
1047
+ const v = messages[key];
1048
+ if (isFunction(v) && 'source' in v) {
1049
+ value[key] = getMessageFunctionDetails(v);
1050
+ }
1051
+ else if (isMessageAST(v) && v.loc && v.loc.source) {
1052
+ value[key] = v.loc.source;
1053
+ }
1054
+ else if (isObject(v)) {
1055
+ value[key] = getLocaleMessageValue(v);
1056
+ }
1057
+ else {
1058
+ value[key] = v;
1059
+ }
1060
+ });
1061
+ return value;
1062
+ }
1063
+ const ESC = {
1064
+ '<': '&lt;',
1065
+ '>': '&gt;',
1066
+ '"': '&quot;',
1067
+ '&': '&amp;'
1068
+ };
1069
+ function escape(s) {
1070
+ return s.replace(/[<>"&]/g, escapeChar);
1071
+ }
1072
+ function escapeChar(a) {
1073
+ return ESC[a] || a;
1074
+ }
1075
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1076
+ function getMessageFunctionDetails(func) {
1077
+ const argString = func.source ? `("${escape(func.source)}")` : `(?)`;
1078
+ return {
1079
+ _custom: {
1080
+ type: 'function',
1081
+ display: `<span>ƒ</span> ${argString}`
1082
+ }
1083
+ };
1084
+ }
1085
+ function registerScope(payload, i18n) {
1086
+ payload.rootNodes.push({
1087
+ id: 'global',
1088
+ label: 'Global Scope'
1089
+ });
1090
+ // prettier-ignore
1091
+ const global = i18n.mode === 'composition'
1092
+ ? i18n.global
1093
+ : i18n.global.__composer;
1094
+ for (const [keyInstance, instance] of i18n.__instances) {
1095
+ // prettier-ignore
1096
+ const composer = i18n.mode === 'composition'
1097
+ ? instance
1098
+ : instance.__composer;
1099
+ if (global === composer) {
1100
+ continue;
1101
+ }
1102
+ payload.rootNodes.push({
1103
+ id: composer.id.toString(),
1104
+ label: `${getI18nScopeLable(keyInstance)} Scope`
1105
+ });
1106
+ }
1107
+ }
1108
+ function getComponentInstance(nodeId, i18n) {
1109
+ let instance = null;
1110
+ if (nodeId !== 'global') {
1111
+ for (const [component, composer] of i18n.__instances.entries()) {
1112
+ if (composer.id.toString() === nodeId) {
1113
+ instance = component;
1114
+ break;
1115
+ }
1116
+ }
1117
+ }
1118
+ return instance;
1119
+ }
1120
+ function getComposer$2(nodeId, i18n) {
1121
+ if (nodeId === 'global') {
1122
+ return i18n.mode === 'composition'
1123
+ ? i18n.global
1124
+ : i18n.global.__composer;
1125
+ }
1126
+ else {
1127
+ const instance = Array.from(i18n.__instances.values()).find(item => item.id.toString() === nodeId);
1128
+ if (instance) {
1129
+ return i18n.mode === 'composition'
1130
+ ? instance
1131
+ : instance.__composer;
1132
+ }
1133
+ else {
1134
+ return null;
1135
+ }
1136
+ }
1137
+ }
1138
+ function inspectScope(payload, i18n
1139
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1140
+ ) {
1141
+ const composer = getComposer$2(payload.nodeId, i18n);
1142
+ if (composer) {
1143
+ // TODO:
1144
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1145
+ payload.state = makeScopeInspectState(composer);
1146
+ }
1147
+ return null;
1148
+ }
1149
+ function makeScopeInspectState(composer) {
1150
+ const state = {};
1151
+ const localeType = 'Locale related info';
1152
+ const localeStates = [
1153
+ {
1154
+ type: localeType,
1155
+ key: 'locale',
1156
+ editable: true,
1157
+ value: composer.locale.value
1158
+ },
1159
+ {
1160
+ type: localeType,
1161
+ key: 'fallbackLocale',
1162
+ editable: true,
1163
+ value: composer.fallbackLocale.value
1164
+ },
1165
+ {
1166
+ type: localeType,
1167
+ key: 'availableLocales',
1168
+ editable: false,
1169
+ value: composer.availableLocales
1170
+ },
1171
+ {
1172
+ type: localeType,
1173
+ key: 'inheritLocale',
1174
+ editable: true,
1175
+ value: composer.inheritLocale
1176
+ }
1177
+ ];
1178
+ state[localeType] = localeStates;
1179
+ const localeMessagesType = 'Locale messages info';
1180
+ const localeMessagesStates = [
1181
+ {
1182
+ type: localeMessagesType,
1183
+ key: 'messages',
1184
+ editable: false,
1185
+ value: getLocaleMessageValue(composer.messages.value)
1186
+ }
1187
+ ];
1188
+ state[localeMessagesType] = localeMessagesStates;
1189
+ {
1190
+ const datetimeFormatsType = 'Datetime formats info';
1191
+ const datetimeFormatsStates = [
1192
+ {
1193
+ type: datetimeFormatsType,
1194
+ key: 'datetimeFormats',
1195
+ editable: false,
1196
+ value: composer.datetimeFormats.value
1197
+ }
1198
+ ];
1199
+ state[datetimeFormatsType] = datetimeFormatsStates;
1200
+ const numberFormatsType = 'Datetime formats info';
1201
+ const numberFormatsStates = [
1202
+ {
1203
+ type: numberFormatsType,
1204
+ key: 'numberFormats',
1205
+ editable: false,
1206
+ value: composer.numberFormats.value
1207
+ }
1208
+ ];
1209
+ state[numberFormatsType] = numberFormatsStates;
1210
+ }
1211
+ return state;
1212
+ }
1213
+ function addTimelineEvent(event, payload) {
1214
+ if (devtoolsApi) {
1215
+ let groupId;
1216
+ if (payload && 'groupId' in payload) {
1217
+ groupId = payload.groupId;
1218
+ delete payload.groupId;
1219
+ }
1220
+ devtoolsApi.addTimelineEvent({
1221
+ layerId: 'vue-i18n-timeline',
1222
+ event: {
1223
+ title: event,
1224
+ groupId,
1225
+ time: Date.now(),
1226
+ meta: {},
1227
+ data: payload || {},
1228
+ logType: event === 'compile-error'
1229
+ ? 'error'
1230
+ : event === 'fallback' || event === 'missing'
1231
+ ? 'warning'
1232
+ : 'default'
1233
+ }
1234
+ });
1235
+ }
1236
+ }
1237
+ function editScope(payload, i18n) {
1238
+ const composer = getComposer$2(payload.nodeId, i18n);
1239
+ if (composer) {
1240
+ const [field] = payload.path;
1241
+ if (field === 'locale' && isString(payload.state.value)) {
1242
+ composer.locale.value = payload.state.value;
1243
+ }
1244
+ else if (field === 'fallbackLocale' &&
1245
+ (isString(payload.state.value) ||
1246
+ isArray(payload.state.value) ||
1247
+ isObject(payload.state.value))) {
1248
+ composer.fallbackLocale.value = payload.state.value;
1249
+ }
1250
+ else if (field === 'inheritLocale' && isBoolean(payload.state.value)) {
1251
+ composer.inheritLocale = payload.state.value;
1252
+ }
1253
+ }
1254
+ }
1255
+
1256
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1257
+ /**
1258
+ * Convert to I18n Composer Options from VueI18n Options
1259
+ *
1260
+ * @internal
1261
+ */
1262
+ function convertComposerOptions(options) {
1263
+ const locale = isString(options.locale) ? options.locale : DEFAULT_LOCALE;
1264
+ const fallbackLocale = isString(options.fallbackLocale) ||
1265
+ isArray(options.fallbackLocale) ||
1266
+ isPlainObject(options.fallbackLocale) ||
1267
+ options.fallbackLocale === false
1268
+ ? options.fallbackLocale
1269
+ : locale;
1270
+ const missing = isFunction(options.missing) ? options.missing : undefined;
1271
+ const missingWarn = isBoolean(options.silentTranslationWarn) ||
1272
+ isRegExp(options.silentTranslationWarn)
1273
+ ? !options.silentTranslationWarn
1274
+ : true;
1275
+ const fallbackWarn = isBoolean(options.silentFallbackWarn) ||
1276
+ isRegExp(options.silentFallbackWarn)
1277
+ ? !options.silentFallbackWarn
1278
+ : true;
1279
+ const fallbackRoot = isBoolean(options.fallbackRoot)
1280
+ ? options.fallbackRoot
1281
+ : true;
1282
+ const fallbackFormat = !!options.formatFallbackMessages;
1283
+ const modifiers = isPlainObject(options.modifiers) ? options.modifiers : {};
1284
+ const pluralizationRules = options.pluralizationRules;
1285
+ const postTranslation = isFunction(options.postTranslation)
1286
+ ? options.postTranslation
1287
+ : undefined;
1288
+ const warnHtmlMessage = isString(options.warnHtmlInMessage)
1289
+ ? options.warnHtmlInMessage !== 'off'
1290
+ : true;
1291
+ const escapeParameter = !!options.escapeParameterHtml;
1292
+ const inheritLocale = isBoolean(options.sync) ? options.sync : true;
1293
+ let messages = options.messages;
1294
+ if (isPlainObject(options.sharedMessages)) {
1295
+ const sharedMessages = options.sharedMessages;
1296
+ const locales = Object.keys(sharedMessages);
1297
+ messages = locales.reduce((messages, locale) => {
1298
+ const message = messages[locale] || (messages[locale] = {});
1299
+ assign(message, sharedMessages[locale]);
1300
+ return messages;
1301
+ }, (messages || {}));
1302
+ }
1303
+ const { __i18n, __root, __injectWithOption } = options;
1304
+ const datetimeFormats = options.datetimeFormats;
1305
+ const numberFormats = options.numberFormats;
1306
+ const flatJson = options.flatJson;
1307
+ return {
1308
+ locale,
1309
+ fallbackLocale,
1310
+ messages,
1311
+ flatJson,
1312
+ datetimeFormats,
1313
+ numberFormats,
1314
+ missing,
1315
+ missingWarn,
1316
+ fallbackWarn,
1317
+ fallbackRoot,
1318
+ fallbackFormat,
1319
+ modifiers,
1320
+ pluralRules: pluralizationRules,
1321
+ postTranslation,
1322
+ warnHtmlMessage,
1323
+ escapeParameter,
1324
+ messageResolver: options.messageResolver,
1325
+ inheritLocale,
1326
+ __i18n,
1327
+ __root,
1328
+ __injectWithOption
1329
+ };
1330
+ }
1331
+ /**
1332
+ * create VueI18n interface factory
1333
+ *
1334
+ * @internal
1335
+ *
1336
+ * @deprecated will be removed at vue-i18n v12
1337
+ */
1338
+ function createVueI18n(options = {}) {
1339
+ const composer = createComposer(convertComposerOptions(options));
1340
+ const { __extender } = options;
1341
+ // defines VueI18n
1342
+ const vueI18n = {
1343
+ // id
1344
+ id: composer.id,
1345
+ // locale
1346
+ get locale() {
1347
+ return composer.locale.value;
1348
+ },
1349
+ set locale(val) {
1350
+ composer.locale.value = val;
1351
+ },
1352
+ // fallbackLocale
1353
+ get fallbackLocale() {
1354
+ return composer.fallbackLocale.value;
1355
+ },
1356
+ set fallbackLocale(val) {
1357
+ composer.fallbackLocale.value = val;
1358
+ },
1359
+ // messages
1360
+ get messages() {
1361
+ return composer.messages.value;
1362
+ },
1363
+ // datetimeFormats
1364
+ get datetimeFormats() {
1365
+ return composer.datetimeFormats.value;
1366
+ },
1367
+ // numberFormats
1368
+ get numberFormats() {
1369
+ return composer.numberFormats.value;
1370
+ },
1371
+ // availableLocales
1372
+ get availableLocales() {
1373
+ return composer.availableLocales;
1374
+ },
1375
+ // missing
1376
+ get missing() {
1377
+ return composer.getMissingHandler();
1378
+ },
1379
+ set missing(handler) {
1380
+ composer.setMissingHandler(handler);
1381
+ },
1382
+ // silentTranslationWarn
1383
+ get silentTranslationWarn() {
1384
+ return isBoolean(composer.missingWarn)
1385
+ ? !composer.missingWarn
1386
+ : composer.missingWarn;
1387
+ },
1388
+ set silentTranslationWarn(val) {
1389
+ composer.missingWarn = isBoolean(val) ? !val : val;
1390
+ },
1391
+ // silentFallbackWarn
1392
+ get silentFallbackWarn() {
1393
+ return isBoolean(composer.fallbackWarn)
1394
+ ? !composer.fallbackWarn
1395
+ : composer.fallbackWarn;
1396
+ },
1397
+ set silentFallbackWarn(val) {
1398
+ composer.fallbackWarn = isBoolean(val) ? !val : val;
1399
+ },
1400
+ // modifiers
1401
+ get modifiers() {
1402
+ return composer.modifiers;
1403
+ },
1404
+ // formatFallbackMessages
1405
+ get formatFallbackMessages() {
1406
+ return composer.fallbackFormat;
1407
+ },
1408
+ set formatFallbackMessages(val) {
1409
+ composer.fallbackFormat = val;
1410
+ },
1411
+ // postTranslation
1412
+ get postTranslation() {
1413
+ return composer.getPostTranslationHandler();
1414
+ },
1415
+ set postTranslation(handler) {
1416
+ composer.setPostTranslationHandler(handler);
1417
+ },
1418
+ // sync
1419
+ get sync() {
1420
+ return composer.inheritLocale;
1421
+ },
1422
+ set sync(val) {
1423
+ composer.inheritLocale = val;
1424
+ },
1425
+ // warnInHtmlMessage
1426
+ get warnHtmlInMessage() {
1427
+ return composer.warnHtmlMessage ? 'warn' : 'off';
1428
+ },
1429
+ set warnHtmlInMessage(val) {
1430
+ composer.warnHtmlMessage = val !== 'off';
1431
+ },
1432
+ // escapeParameterHtml
1433
+ get escapeParameterHtml() {
1434
+ return composer.escapeParameter;
1435
+ },
1436
+ set escapeParameterHtml(val) {
1437
+ composer.escapeParameter = val;
1438
+ },
1439
+ // pluralizationRules
1440
+ get pluralizationRules() {
1441
+ return composer.pluralRules || {};
1442
+ },
1443
+ // for internal
1444
+ __composer: composer,
1445
+ // t
1446
+ t(...args) {
1447
+ return Reflect.apply(composer.t, composer, [...args]);
1448
+ },
1449
+ // rt
1450
+ rt(...args) {
1451
+ return Reflect.apply(composer.rt, composer, [...args]);
1452
+ },
1453
+ // te
1454
+ te(key, locale) {
1455
+ return composer.te(key, locale);
1456
+ },
1457
+ // tm
1458
+ tm(key) {
1459
+ return composer.tm(key);
1460
+ },
1461
+ // getLocaleMessage
1462
+ getLocaleMessage(locale) {
1463
+ return composer.getLocaleMessage(locale);
1464
+ },
1465
+ // setLocaleMessage
1466
+ setLocaleMessage(locale, message) {
1467
+ composer.setLocaleMessage(locale, message);
1468
+ },
1469
+ // mergeLocaleMessage
1470
+ mergeLocaleMessage(locale, message) {
1471
+ composer.mergeLocaleMessage(locale, message);
1472
+ },
1473
+ // d
1474
+ d(...args) {
1475
+ return Reflect.apply(composer.d, composer, [...args]);
1476
+ },
1477
+ // getDateTimeFormat
1478
+ getDateTimeFormat(locale) {
1479
+ return composer.getDateTimeFormat(locale);
1480
+ },
1481
+ // setDateTimeFormat
1482
+ setDateTimeFormat(locale, format) {
1483
+ composer.setDateTimeFormat(locale, format);
1484
+ },
1485
+ // mergeDateTimeFormat
1486
+ mergeDateTimeFormat(locale, format) {
1487
+ composer.mergeDateTimeFormat(locale, format);
1488
+ },
1489
+ // n
1490
+ n(...args) {
1491
+ return Reflect.apply(composer.n, composer, [...args]);
1492
+ },
1493
+ // getNumberFormat
1494
+ getNumberFormat(locale) {
1495
+ return composer.getNumberFormat(locale);
1496
+ },
1497
+ // setNumberFormat
1498
+ setNumberFormat(locale, format) {
1499
+ composer.setNumberFormat(locale, format);
1500
+ },
1501
+ // mergeNumberFormat
1502
+ mergeNumberFormat(locale, format) {
1503
+ composer.mergeNumberFormat(locale, format);
1504
+ }
1505
+ };
1506
+ vueI18n.__extender = __extender;
1507
+ // for vue-devtools timeline event
1508
+ if ((process.env.NODE_ENV !== 'production')) {
1509
+ vueI18n.__enableEmitter = (emitter) => {
1510
+ const __composer = composer;
1511
+ __composer[EnableEmitter] && __composer[EnableEmitter](emitter);
1512
+ };
1513
+ vueI18n.__disableEmitter = () => {
1514
+ const __composer = composer;
1515
+ __composer[DisableEmitter] && __composer[DisableEmitter]();
1516
+ };
1517
+ }
1518
+ return vueI18n;
1519
+ }
1520
+ /* eslint-enable @typescript-eslint/no-explicit-any */
1521
+
1522
+ /**
1523
+ * Supports compatibility for legacy vue-i18n APIs
1524
+ * This mixin is used when we use vue-i18n@v9.x or later
1525
+ */
1526
+ function defineMixin(vuei18n, composer, i18n) {
1527
+ return {
1528
+ beforeCreate() {
1529
+ const instance = getCurrentInstance();
1530
+ /* istanbul ignore if */
1531
+ if (!instance) {
1532
+ throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
1533
+ }
1534
+ const options = this.$options;
1535
+ if (options.i18n) {
1536
+ const optionsI18n = options.i18n;
1537
+ if (options.__i18n) {
1538
+ optionsI18n.__i18n = options.__i18n;
1539
+ }
1540
+ optionsI18n.__root = composer;
1541
+ if (this === this.$root) {
1542
+ // merge option and gttach global
1543
+ this.$i18n = mergeToGlobal(vuei18n, optionsI18n);
1544
+ }
1545
+ else {
1546
+ optionsI18n.__injectWithOption = true;
1547
+ optionsI18n.__extender = i18n.__vueI18nExtend;
1548
+ // atttach local VueI18n instance
1549
+ this.$i18n = createVueI18n(optionsI18n);
1550
+ // extend VueI18n instance
1551
+ const _vueI18n = this.$i18n;
1552
+ if (_vueI18n.__extender) {
1553
+ _vueI18n.__disposer = _vueI18n.__extender(this.$i18n);
1554
+ }
1555
+ }
1556
+ }
1557
+ else if (options.__i18n) {
1558
+ if (this === this.$root) {
1559
+ // merge option and gttach global
1560
+ this.$i18n = mergeToGlobal(vuei18n, options);
1561
+ }
1562
+ else {
1563
+ // atttach local VueI18n instance
1564
+ this.$i18n = createVueI18n({
1565
+ __i18n: options.__i18n,
1566
+ __injectWithOption: true,
1567
+ __extender: i18n.__vueI18nExtend,
1568
+ __root: composer
1569
+ });
1570
+ // extend VueI18n instance
1571
+ const _vueI18n = this.$i18n;
1572
+ if (_vueI18n.__extender) {
1573
+ _vueI18n.__disposer = _vueI18n.__extender(this.$i18n);
1574
+ }
1575
+ }
1576
+ }
1577
+ else {
1578
+ // attach global VueI18n instance
1579
+ this.$i18n = vuei18n;
1580
+ }
1581
+ if (options.__i18nGlobal) {
1582
+ adjustI18nResources(composer, options, options);
1583
+ }
1584
+ // defines vue-i18n legacy APIs
1585
+ this.$t = (...args) => this.$i18n.t(...args);
1586
+ this.$rt = (...args) => this.$i18n.rt(...args);
1587
+ this.$te = (key, locale) => this.$i18n.te(key, locale);
1588
+ this.$d = (...args) => this.$i18n.d(...args);
1589
+ this.$n = (...args) => this.$i18n.n(...args);
1590
+ this.$tm = (key) => this.$i18n.tm(key);
1591
+ i18n.__setInstance(instance, this.$i18n);
1592
+ },
1593
+ mounted() {
1594
+ /* istanbul ignore if */
1595
+ if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) &&
1596
+ true &&
1597
+ this.$i18n) {
1598
+ const instance = getCurrentInstance();
1599
+ if (!instance) {
1600
+ return;
1601
+ }
1602
+ const _vueI18n = this.$i18n;
1603
+ instance.__VUE_I18N__ = _vueI18n.__composer;
1604
+ const emitter = (this.__v_emitter =
1605
+ createEmitter());
1606
+ _vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter);
1607
+ emitter.on('*', addTimelineEvent);
1608
+ }
1609
+ },
1610
+ unmounted() {
1611
+ const instance = getCurrentInstance();
1612
+ /* istanbul ignore if */
1613
+ if (!instance) {
1614
+ throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
1615
+ }
1616
+ const _vueI18n = this.$i18n;
1617
+ /* istanbul ignore if */
1618
+ if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) &&
1619
+ true &&
1620
+ instance.__VUE_I18N__) {
1621
+ if (this.__v_emitter) {
1622
+ this.__v_emitter.off('*', addTimelineEvent);
1623
+ delete this.__v_emitter;
1624
+ }
1625
+ if (_vueI18n) {
1626
+ _vueI18n.__disableEmitter && _vueI18n.__disableEmitter();
1627
+ delete instance.__VUE_I18N__;
1628
+ }
1629
+ }
1630
+ // setup-only components skip beforeCreate but still run unmounted
1631
+ if (!_vueI18n) {
1632
+ return;
1633
+ }
1634
+ delete this.$t;
1635
+ delete this.$rt;
1636
+ delete this.$te;
1637
+ delete this.$d;
1638
+ delete this.$n;
1639
+ delete this.$tm;
1640
+ if (_vueI18n?.__disposer) {
1641
+ _vueI18n.__disposer();
1642
+ delete _vueI18n.__disposer;
1643
+ delete _vueI18n.__extender;
1644
+ }
1645
+ i18n.__deleteInstance(instance);
1646
+ delete this.$i18n;
1647
+ }
1648
+ };
1649
+ }
1650
+ function mergeToGlobal(g, options) {
1651
+ g.locale = options.locale || g.locale;
1652
+ g.fallbackLocale = options.fallbackLocale || g.fallbackLocale;
1653
+ g.missing = options.missing || g.missing;
1654
+ g.silentTranslationWarn =
1655
+ options.silentTranslationWarn || g.silentFallbackWarn;
1656
+ g.silentFallbackWarn = options.silentFallbackWarn || g.silentFallbackWarn;
1657
+ g.formatFallbackMessages =
1658
+ options.formatFallbackMessages || g.formatFallbackMessages;
1659
+ g.postTranslation = options.postTranslation || g.postTranslation;
1660
+ g.warnHtmlInMessage = options.warnHtmlInMessage || g.warnHtmlInMessage;
1661
+ g.escapeParameterHtml = options.escapeParameterHtml || g.escapeParameterHtml;
1662
+ g.sync = options.sync || g.sync;
1663
+ g.__composer[SetPluralRulesSymbol](options.pluralizationRules || g.pluralizationRules);
1664
+ const messages = getLocaleMessages(g.locale, {
1665
+ messages: options.messages,
1666
+ __i18n: options.__i18n
1667
+ });
1668
+ Object.keys(messages).forEach(locale => g.mergeLocaleMessage(locale, messages[locale]));
1669
+ if (options.datetimeFormats) {
1670
+ Object.keys(options.datetimeFormats).forEach(locale => g.mergeDateTimeFormat(locale, options.datetimeFormats[locale]));
1671
+ }
1672
+ if (options.numberFormats) {
1673
+ Object.keys(options.numberFormats).forEach(locale => g.mergeNumberFormat(locale, options.numberFormats[locale]));
1674
+ }
1675
+ return g;
1676
+ }
1677
+
1678
+ const baseFormatProps = {
1679
+ tag: {
1680
+ type: [String, Object]
1681
+ },
1682
+ locale: {
1683
+ type: String
1684
+ },
1685
+ scope: {
1686
+ type: String,
1687
+ // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
1688
+ validator: (val /* ComponentI18nScope */) => val === 'parent' || val === 'global',
1689
+ default: 'parent' /* ComponentI18nScope */
1690
+ },
1691
+ i18n: {
1692
+ type: Object
1693
+ }
1694
+ };
1695
+
1696
+ function getInterpolateArg(
1697
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1698
+ { slots }, // SetupContext,
1699
+ keys) {
1700
+ if (keys.length === 1 && keys[0] === 'default') {
1701
+ // default slot with list
1702
+ const ret = slots.default ? slots.default() : [];
1703
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1704
+ return ret.reduce((slot, current) => {
1705
+ return [
1706
+ ...slot,
1707
+ // prettier-ignore
1708
+ ...(current.type === Fragment ? current.children : [current])
1709
+ ];
1710
+ }, []);
1711
+ }
1712
+ else {
1713
+ // named slots
1714
+ return keys.reduce((arg, key) => {
1715
+ const slot = slots[key];
1716
+ if (slot) {
1717
+ arg[key] = slot();
1718
+ }
1719
+ return arg;
1720
+ }, create());
1721
+ }
1722
+ }
1723
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1724
+ function getFragmentableTag() {
1725
+ return Fragment;
1726
+ }
1727
+
1728
+ const TranslationImpl = /*#__PURE__*/ defineComponent({
1729
+ /* eslint-disable */
1730
+ name: 'i18n-t',
1731
+ props: assign({
1732
+ keypath: {
1733
+ type: String,
1734
+ required: true
1735
+ },
1736
+ plural: {
1737
+ type: [Number, String],
1738
+ validator: (val) => isNumber(val) || !isNaN(val)
1739
+ }
1740
+ }, baseFormatProps),
1741
+ /* eslint-enable */
1742
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1743
+ setup(props, context) {
1744
+ const { slots, attrs } = context;
1745
+ // NOTE: avoid https://github.com/microsoft/rushstack/issues/1050
1746
+ const i18n = props.i18n ||
1747
+ useI18n({
1748
+ useScope: props.scope,
1749
+ __useComponent: true
1750
+ });
1751
+ return () => {
1752
+ const renderChildren = () => {
1753
+ const keys = Object.keys(slots).filter(key => key[0] !== '_');
1754
+ const options = create();
1755
+ if (props.locale) {
1756
+ options.locale = props.locale;
1757
+ }
1758
+ if (props.plural !== undefined) {
1759
+ options.plural = isString(props.plural) ? +props.plural : props.plural;
1760
+ }
1761
+ const arg = getInterpolateArg(context, keys);
1762
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1763
+ return i18n[TranslateVNodeSymbol](props.keypath, arg, options);
1764
+ };
1765
+ const assignedAttrs = assign(create(), attrs);
1766
+ const tag = isString(props.tag) || isObject(props.tag)
1767
+ ? props.tag
1768
+ : getFragmentableTag();
1769
+ return isObject(tag)
1770
+ ? h(tag, assignedAttrs, { default: renderChildren })
1771
+ : h(tag, assignedAttrs, renderChildren());
1772
+ };
1773
+ }
1774
+ });
1775
+ /**
1776
+ * export the public type for h/tsx inference
1777
+ * also to avoid inline import() in generated d.ts files
1778
+ */
1779
+ /**
1780
+ * Translation Component
1781
+ *
1782
+ * @remarks
1783
+ * See the following items for property about details
1784
+ *
1785
+ * @VueI18nSee [TranslationProps](component#translationprops)
1786
+ * @VueI18nSee [BaseFormatProps](component#baseformatprops)
1787
+ * @VueI18nSee [Component Interpolation](../guide/advanced/component)
1788
+ *
1789
+ * @example
1790
+ * ```html
1791
+ * <div id="app">
1792
+ * <!-- ... -->
1793
+ * <i18n keypath="term" tag="label" for="tos">
1794
+ * <a :href="url" target="_blank">{{ $t('tos') }}</a>
1795
+ * </i18n>
1796
+ * <!-- ... -->
1797
+ * </div>
1798
+ * ```
1799
+ * ```js
1800
+ * import { createApp } from 'vue'
1801
+ * import { createI18n } from 'vue-i18n'
1802
+ *
1803
+ * const messages = {
1804
+ * en: {
1805
+ * tos: 'Term of Service',
1806
+ * term: 'I accept xxx {0}.'
1807
+ * },
1808
+ * ja: {
1809
+ * tos: '利用規約',
1810
+ * term: '私は xxx の{0}に同意します。'
1811
+ * }
1812
+ * }
1813
+ *
1814
+ * const i18n = createI18n({
1815
+ * locale: 'en',
1816
+ * messages
1817
+ * })
1818
+ *
1819
+ * const app = createApp({
1820
+ * data: {
1821
+ * url: '/term'
1822
+ * }
1823
+ * }).use(i18n).mount('#app')
1824
+ * ```
1825
+ *
1826
+ * @VueI18nComponent
1827
+ */
1828
+ const Translation = TranslationImpl;
1829
+ const I18nT = Translation;
1830
+
1831
+ function isVNode(target) {
1832
+ return isArray(target) && !isString(target[0]);
1833
+ }
1834
+ function renderFormatter(props, context, slotKeys, partFormatter) {
1835
+ const { slots, attrs } = context;
1836
+ return () => {
1837
+ const renderChildren = () => {
1838
+ const options = { part: true };
1839
+ let overrides = create();
1840
+ if (props.locale) {
1841
+ options.locale = props.locale;
1842
+ }
1843
+ if (isString(props.format)) {
1844
+ options.key = props.format;
1845
+ }
1846
+ else if (isObject(props.format)) {
1847
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1848
+ if (isString(props.format.key)) {
1849
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1850
+ options.key = props.format.key;
1851
+ }
1852
+ // Filter out number format options only
1853
+ overrides = Object.keys(props.format).reduce((options, prop) => {
1854
+ return slotKeys.includes(prop)
1855
+ ? assign(create(), options, { [prop]: props.format[prop] }) // eslint-disable-line @typescript-eslint/no-explicit-any
1856
+ : options;
1857
+ }, create());
1858
+ }
1859
+ const parts = partFormatter(...[props.value, options, overrides]);
1860
+ let children = [options.key];
1861
+ if (isArray(parts)) {
1862
+ children = parts.map((part, index) => {
1863
+ const slot = slots[part.type];
1864
+ const node = slot
1865
+ ? slot({ [part.type]: part.value, index, parts })
1866
+ : [part.value];
1867
+ if (isVNode(node)) {
1868
+ node[0].key = `${part.type}-${index}`;
1869
+ }
1870
+ return node;
1871
+ });
1872
+ }
1873
+ else if (isString(parts)) {
1874
+ children = [parts];
1875
+ }
1876
+ return children;
1877
+ };
1878
+ const assignedAttrs = assign(create(), attrs);
1879
+ const tag = isString(props.tag) || isObject(props.tag)
1880
+ ? props.tag
1881
+ : getFragmentableTag();
1882
+ return isObject(tag)
1883
+ ? h(tag, assignedAttrs, { default: renderChildren })
1884
+ : h(tag, assignedAttrs, renderChildren());
1885
+ };
1886
+ }
1887
+
1888
+ const NumberFormatImpl = /*#__PURE__*/ defineComponent({
1889
+ /* eslint-disable */
1890
+ name: 'i18n-n',
1891
+ props: assign({
1892
+ value: {
1893
+ type: Number,
1894
+ required: true
1895
+ },
1896
+ format: {
1897
+ type: [String, Object]
1898
+ }
1899
+ }, baseFormatProps),
1900
+ /* eslint-enable */
1901
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1902
+ setup(props, context) {
1903
+ const i18n = props.i18n ||
1904
+ useI18n({
1905
+ useScope: props.scope,
1906
+ __useComponent: true
1907
+ });
1908
+ return renderFormatter(props, context, NUMBER_FORMAT_OPTIONS_KEYS, (...args) =>
1909
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1910
+ i18n[NumberPartsSymbol](...args));
1911
+ }
1912
+ });
1913
+ /**
1914
+ * export the public type for h/tsx inference
1915
+ * also to avoid inline import() in generated d.ts files
1916
+ */
1917
+ /**
1918
+ * Number Format Component
1919
+ *
1920
+ * @remarks
1921
+ * See the following items for property about details
1922
+ *
1923
+ * @VueI18nSee [FormattableProps](component#formattableprops)
1924
+ * @VueI18nSee [BaseFormatProps](component#baseformatprops)
1925
+ * @VueI18nSee [Custom Formatting](../guide/essentials/number#custom-formatting)
1926
+ *
1927
+ * @VueI18nDanger
1928
+ * Not supported IE, due to no support `Intl.NumberFormat#formatToParts` in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
1929
+ *
1930
+ * If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-numberformat)
1931
+ *
1932
+ * @VueI18nComponent
1933
+ */
1934
+ const NumberFormat = NumberFormatImpl;
1935
+ const I18nN = NumberFormat;
1936
+
1937
+ function getComposer$1(i18n, instance) {
1938
+ const i18nInternal = i18n;
1939
+ if (i18n.mode === 'composition') {
1940
+ return (i18nInternal.__getInstance(instance) || i18n.global);
1941
+ }
1942
+ else {
1943
+ const vueI18n = i18nInternal.__getInstance(instance);
1944
+ return vueI18n != null
1945
+ ? vueI18n.__composer
1946
+ : i18n.global.__composer;
1947
+ }
1948
+ }
1949
+ /**
1950
+ * @deprecated will be removed at vue-i18n v12
1951
+ */
1952
+ function vTDirective(i18n) {
1953
+ const _process = (binding) => {
1954
+ if ((process.env.NODE_ENV !== 'production')) {
1955
+ warnOnce(getWarnMessage(I18nWarnCodes.DEPRECATE_TRANSLATE_CUSTOME_DIRECTIVE));
1956
+ }
1957
+ const { instance, value } = binding;
1958
+ /* istanbul ignore if */
1959
+ if (!instance || !instance.$) {
1960
+ throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
1961
+ }
1962
+ const composer = getComposer$1(i18n, instance.$);
1963
+ const parsedValue = parseValue(value);
1964
+ return [
1965
+ Reflect.apply(composer.t, composer, [...makeParams(parsedValue)]),
1966
+ composer
1967
+ ];
1968
+ };
1969
+ const register = (el, binding) => {
1970
+ const [textContent, composer] = _process(binding);
1971
+ if (inBrowser) {
1972
+ el.__i18nWatcher = watch(composer.locale, () => {
1973
+ binding.instance && binding.instance.$forceUpdate();
1974
+ });
1975
+ }
1976
+ el.__composer = composer;
1977
+ el.textContent = textContent;
1978
+ };
1979
+ const unregister = (el) => {
1980
+ if (inBrowser && el.__i18nWatcher) {
1981
+ el.__i18nWatcher();
1982
+ el.__i18nWatcher = undefined;
1983
+ delete el.__i18nWatcher;
1984
+ }
1985
+ if (el.__composer) {
1986
+ el.__composer = undefined;
1987
+ delete el.__composer;
1988
+ }
1989
+ };
1990
+ const update = (el, { value }) => {
1991
+ if (el.__composer) {
1992
+ const composer = el.__composer;
1993
+ const parsedValue = parseValue(value);
1994
+ el.textContent = Reflect.apply(composer.t, composer, [
1995
+ ...makeParams(parsedValue)
1996
+ ]);
1997
+ }
1998
+ };
1999
+ const getSSRProps = (binding) => {
2000
+ const [textContent] = _process(binding);
2001
+ return { textContent };
2002
+ };
2003
+ return {
2004
+ created: register,
2005
+ unmounted: unregister,
2006
+ beforeUpdate: update,
2007
+ getSSRProps
2008
+ };
2009
+ }
2010
+ function parseValue(value) {
2011
+ if (isString(value)) {
2012
+ return { path: value };
2013
+ }
2014
+ else if (isPlainObject(value)) {
2015
+ if (!('path' in value)) {
2016
+ throw createI18nError(I18nErrorCodes.REQUIRED_VALUE, 'path');
2017
+ }
2018
+ return value;
2019
+ }
2020
+ else {
2021
+ throw createI18nError(I18nErrorCodes.INVALID_VALUE);
2022
+ }
2023
+ }
2024
+ function makeParams(value) {
2025
+ const { path, locale, args, choice, plural } = value;
2026
+ const options = {};
2027
+ const named = args || {};
2028
+ if (isString(locale)) {
2029
+ options.locale = locale;
2030
+ }
2031
+ if (isNumber(choice)) {
2032
+ options.plural = choice;
2033
+ }
2034
+ if (isNumber(plural)) {
2035
+ options.plural = plural;
2036
+ }
2037
+ return [path, named, options];
2038
+ }
2039
+
2040
+ function apply(app, i18n, ...options) {
2041
+ const pluginOptions = isPlainObject(options[0])
2042
+ ? options[0]
2043
+ : {};
2044
+ const globalInstall = isBoolean(pluginOptions.globalInstall)
2045
+ ? pluginOptions.globalInstall
2046
+ : true;
2047
+ if (globalInstall) {
2048
+ [Translation.name, 'I18nT'].forEach(name => app.component(name, Translation));
2049
+ [NumberFormat.name, 'I18nN'].forEach(name => app.component(name, NumberFormat));
2050
+ [DatetimeFormat.name, 'I18nD'].forEach(name => app.component(name, DatetimeFormat));
2051
+ }
2052
+ // install directive
2053
+ {
2054
+ app.directive('t', vTDirective(i18n));
2055
+ }
2056
+ }
2057
+
2058
+ /**
2059
+ * Injection key for {@link useI18n}
2060
+ *
2061
+ * @remarks
2062
+ * The global injection key for I18n instances with `useI18n`. this injection key is used in Web Components.
2063
+ * Specify the i18n instance created by {@link createI18n} together with `provide` function.
2064
+ *
2065
+ * @VueI18nGeneral
2066
+ */
2067
+ const I18nInjectionKey =
2068
+ /* #__PURE__*/ makeSymbol('global-vue-i18n');
2069
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2070
+ function createI18n(options = {}) {
2071
+ // prettier-ignore
2072
+ const __legacyMode = __VUE_I18N_LEGACY_API__ && isBoolean(options.legacy)
2073
+ ? options.legacy
2074
+ : __VUE_I18N_LEGACY_API__;
2075
+ if ((process.env.NODE_ENV !== 'production') && __legacyMode) {
2076
+ warnOnce(getWarnMessage(I18nWarnCodes.DEPRECATE_LEGACY_MODE));
2077
+ }
2078
+ // prettier-ignore
2079
+ const __globalInjection = isBoolean(options.globalInjection)
2080
+ ? options.globalInjection
2081
+ : true;
2082
+ const __instances = new Map();
2083
+ const [globalScope, __global] = createGlobal(options, __legacyMode);
2084
+ const symbol = /* #__PURE__*/ makeSymbol((process.env.NODE_ENV !== 'production') ? 'vue-i18n' : '');
2085
+ function __getInstance(component) {
2086
+ return __instances.get(component) || null;
2087
+ }
2088
+ function __setInstance(component, instance) {
2089
+ __instances.set(component, instance);
2090
+ }
2091
+ function __deleteInstance(component) {
2092
+ __instances.delete(component);
2093
+ }
2094
+ const i18n = {
2095
+ // mode
2096
+ get mode() {
2097
+ return __VUE_I18N_LEGACY_API__ && __legacyMode
2098
+ ? 'legacy'
2099
+ : 'composition';
2100
+ },
2101
+ // install plugin
2102
+ async install(app, ...options) {
2103
+ if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) && true) {
2104
+ app.__VUE_I18N__ = i18n;
2105
+ }
2106
+ // setup global provider
2107
+ app.__VUE_I18N_SYMBOL__ = symbol;
2108
+ app.provide(app.__VUE_I18N_SYMBOL__, i18n);
2109
+ // set composer & vuei18n extend hook options from plugin options
2110
+ if (isPlainObject(options[0])) {
2111
+ const opts = options[0];
2112
+ i18n.__composerExtend =
2113
+ opts.__composerExtend;
2114
+ i18n.__vueI18nExtend =
2115
+ opts.__vueI18nExtend;
2116
+ }
2117
+ // global method and properties injection for Composition API
2118
+ let globalReleaseHandler = null;
2119
+ if (!__legacyMode && __globalInjection) {
2120
+ globalReleaseHandler = injectGlobalFields(app, i18n.global);
2121
+ }
2122
+ // install built-in components and directive
2123
+ if (__VUE_I18N_FULL_INSTALL__) {
2124
+ apply(app, i18n, ...options);
2125
+ }
2126
+ // setup mixin for Legacy API
2127
+ if (__VUE_I18N_LEGACY_API__ && __legacyMode) {
2128
+ app.mixin(defineMixin(__global, __global.__composer, i18n));
2129
+ }
2130
+ // release global scope
2131
+ const unmountApp = app.unmount;
2132
+ app.unmount = () => {
2133
+ globalReleaseHandler && globalReleaseHandler();
2134
+ i18n.dispose();
2135
+ unmountApp();
2136
+ };
2137
+ // setup vue-devtools plugin
2138
+ if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) && true) {
2139
+ const ret = await enableDevTools(app, i18n);
2140
+ if (!ret) {
2141
+ throw createI18nError(I18nErrorCodes.CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN);
2142
+ }
2143
+ const emitter = createEmitter();
2144
+ if (__legacyMode) {
2145
+ const _vueI18n = __global;
2146
+ _vueI18n.__enableEmitter && _vueI18n.__enableEmitter(emitter);
2147
+ }
2148
+ else {
2149
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2150
+ const _composer = __global;
2151
+ _composer[EnableEmitter] && _composer[EnableEmitter](emitter);
2152
+ }
2153
+ emitter.on('*', addTimelineEvent);
2154
+ }
2155
+ },
2156
+ // global accessor
2157
+ get global() {
2158
+ return __global;
2159
+ },
2160
+ dispose() {
2161
+ globalScope.stop();
2162
+ },
2163
+ // @internal
2164
+ __instances,
2165
+ // @internal
2166
+ __getInstance,
2167
+ // @internal
2168
+ __setInstance,
2169
+ // @internal
2170
+ __deleteInstance
2171
+ };
2172
+ return i18n;
2173
+ }
2174
+ function useI18n(options = {}) {
2175
+ const instance = getCurrentInstance();
2176
+ if (instance == null) {
2177
+ throw createI18nError(I18nErrorCodes.MUST_BE_CALL_SETUP_TOP);
2178
+ }
2179
+ if (!instance.isCE &&
2180
+ instance.appContext.app != null &&
2181
+ !instance.appContext.app.__VUE_I18N_SYMBOL__) {
2182
+ throw createI18nError(I18nErrorCodes.NOT_INSTALLED);
2183
+ }
2184
+ const i18n = getI18nInstance(instance);
2185
+ const gl = getGlobalComposer(i18n);
2186
+ const componentOptions = getComponentOptions(instance);
2187
+ const scope = getScope(options, componentOptions);
2188
+ if (scope === 'global') {
2189
+ adjustI18nResources(gl, options, componentOptions);
2190
+ return gl;
2191
+ }
2192
+ if (scope === 'parent') {
2193
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2194
+ let composer = getComposer(i18n, instance, options.__useComponent);
2195
+ if (composer == null) {
2196
+ if ((process.env.NODE_ENV !== 'production')) {
2197
+ warn(getWarnMessage(I18nWarnCodes.NOT_FOUND_PARENT_SCOPE));
2198
+ }
2199
+ composer = gl;
2200
+ }
2201
+ return composer;
2202
+ }
2203
+ // Isolated scope - independent composer not tied to component
2204
+ if (scope === 'isolated') {
2205
+ // Composition API mode only
2206
+ if (i18n.mode !== 'composition') {
2207
+ throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY);
2208
+ }
2209
+ const i18nInternalIso = i18n;
2210
+ const composerOptions = assign({}, options);
2211
+ // Find parent composer via parent chain (or fall back to global)
2212
+ const parentComposer = getComposer(i18n, instance);
2213
+ composerOptions.__root = parentComposer || gl;
2214
+ const composer = createComposer(composerOptions);
2215
+ // ComposerExtend hook
2216
+ if (i18nInternalIso.__composerExtend) {
2217
+ composer[DisposeSymbol] =
2218
+ i18nInternalIso.__composerExtend(composer);
2219
+ }
2220
+ // Setup devtools emitter (no target.__VUE_I18N__ attachment -
2221
+ // multiple isolated composers per component are allowed)
2222
+ let emitter = null;
2223
+ if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) && true) {
2224
+ emitter = createEmitter();
2225
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2226
+ const _composer = composer;
2227
+ _composer[EnableEmitter] && _composer[EnableEmitter](emitter);
2228
+ emitter.on('*', addTimelineEvent);
2229
+ }
2230
+ // Lifecycle cleanup via onScopeDispose
2231
+ const currentScope = getCurrentScope();
2232
+ if (currentScope) {
2233
+ onScopeDispose(() => {
2234
+ if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) && true) {
2235
+ emitter && emitter.off('*', addTimelineEvent);
2236
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2237
+ const _composer = composer;
2238
+ _composer[DisableEmitter] && _composer[DisableEmitter]();
2239
+ }
2240
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2241
+ const dispose = composer[DisposeSymbol];
2242
+ if (dispose) {
2243
+ dispose();
2244
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2245
+ delete composer[DisposeSymbol];
2246
+ }
2247
+ });
2248
+ }
2249
+ return composer;
2250
+ }
2251
+ const i18nInternal = i18n;
2252
+ let composer = i18nInternal.__getInstance(instance);
2253
+ if (composer == null) {
2254
+ const composerOptions = assign({}, options);
2255
+ if ('__i18n' in componentOptions) {
2256
+ composerOptions.__i18n = componentOptions.__i18n;
2257
+ }
2258
+ if (gl) {
2259
+ composerOptions.__root = gl;
2260
+ }
2261
+ composer = createComposer(composerOptions);
2262
+ if (i18nInternal.__composerExtend) {
2263
+ composer[DisposeSymbol] =
2264
+ i18nInternal.__composerExtend(composer);
2265
+ }
2266
+ setupLifeCycle(i18nInternal, instance, composer);
2267
+ i18nInternal.__setInstance(instance, composer);
2268
+ }
2269
+ else {
2270
+ if ((process.env.NODE_ENV !== 'production') && scope === 'local') {
2271
+ warn(getWarnMessage(I18nWarnCodes.DUPLICATE_USE_I18N_CALLING));
2272
+ }
2273
+ }
2274
+ return composer;
2275
+ }
2276
+ function createGlobal(options, legacyMode) {
2277
+ const scope = effectScope();
2278
+ const obj = __VUE_I18N_LEGACY_API__ && legacyMode
2279
+ ? scope.run(() => createVueI18n(options))
2280
+ : scope.run(() => createComposer(options));
2281
+ if (obj == null) {
2282
+ throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
2283
+ }
2284
+ return [scope, obj];
2285
+ }
2286
+ function getI18nInstance(instance) {
2287
+ const i18n = inject(!instance.isCE
2288
+ ? instance.appContext.app.__VUE_I18N_SYMBOL__
2289
+ : I18nInjectionKey);
2290
+ /* istanbul ignore if */
2291
+ if (!i18n) {
2292
+ throw createI18nError(!instance.isCE
2293
+ ? I18nErrorCodes.UNEXPECTED_ERROR
2294
+ : I18nErrorCodes.NOT_INSTALLED_WITH_PROVIDE);
2295
+ }
2296
+ return i18n;
2297
+ }
2298
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2299
+ function getScope(options, componentOptions) {
2300
+ // prettier-ignore
2301
+ return isEmptyObject(options)
2302
+ ? ('__i18n' in componentOptions)
2303
+ ? 'local'
2304
+ : 'global'
2305
+ : !options.useScope
2306
+ ? 'local'
2307
+ : options.useScope;
2308
+ }
2309
+ function getGlobalComposer(i18n) {
2310
+ // prettier-ignore
2311
+ return i18n.mode === 'composition'
2312
+ ? i18n.global
2313
+ : i18n.global.__composer;
2314
+ }
2315
+ function getComposer(i18n, target, useComponent = false) {
2316
+ let composer = null;
2317
+ const root = target.root;
2318
+ let current = getParentComponentInstance(target, useComponent);
2319
+ while (current != null) {
2320
+ const i18nInternal = i18n;
2321
+ if (i18n.mode === 'composition') {
2322
+ composer = i18nInternal.__getInstance(current);
2323
+ }
2324
+ else {
2325
+ if (__VUE_I18N_LEGACY_API__) {
2326
+ const vueI18n = i18nInternal.__getInstance(current);
2327
+ if (vueI18n != null) {
2328
+ composer = vueI18n
2329
+ .__composer;
2330
+ if (useComponent &&
2331
+ composer &&
2332
+ !composer[InejctWithOptionSymbol] // eslint-disable-line @typescript-eslint/no-explicit-any
2333
+ ) {
2334
+ composer = null;
2335
+ }
2336
+ }
2337
+ }
2338
+ }
2339
+ if (composer != null) {
2340
+ break;
2341
+ }
2342
+ if (root === current) {
2343
+ break;
2344
+ }
2345
+ current = current.parent;
2346
+ }
2347
+ return composer;
2348
+ }
2349
+ function getParentComponentInstance(target, useComponent = false) {
2350
+ if (target == null) {
2351
+ return null;
2352
+ }
2353
+ // if `useComponent: true` will be specified, we get lexical scope owner instance for use-case slots
2354
+ return !useComponent
2355
+ ? target.parent
2356
+ : target.vnode.ctx || target.parent; // eslint-disable-line @typescript-eslint/no-explicit-any
2357
+ }
2358
+ function setupLifeCycle(i18n, target, composer) {
2359
+ let emitter = null;
2360
+ onMounted(() => {
2361
+ // inject composer instance to DOM for intlify-devtools
2362
+ if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) && true) {
2363
+ target.__VUE_I18N__ = composer;
2364
+ emitter = createEmitter();
2365
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2366
+ const _composer = composer;
2367
+ _composer[EnableEmitter] && _composer[EnableEmitter](emitter);
2368
+ emitter.on('*', addTimelineEvent);
2369
+ }
2370
+ }, target);
2371
+ onUnmounted(() => {
2372
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2373
+ const _composer = composer;
2374
+ // remove composer instance from DOM for intlify-devtools
2375
+ if (((process.env.NODE_ENV !== 'production') || __VUE_PROD_DEVTOOLS__) && true) {
2376
+ emitter && emitter.off('*', addTimelineEvent);
2377
+ _composer[DisableEmitter] && _composer[DisableEmitter]();
2378
+ delete target.__VUE_I18N__;
2379
+ }
2380
+ i18n.__deleteInstance(target);
2381
+ // dispose extended resources
2382
+ const dispose = _composer[DisposeSymbol];
2383
+ if (dispose) {
2384
+ dispose();
2385
+ delete _composer[DisposeSymbol];
2386
+ }
2387
+ }, target);
2388
+ }
2389
+ const globalExportProps = [
2390
+ 'locale',
2391
+ 'fallbackLocale',
2392
+ 'availableLocales'
2393
+ ];
2394
+ const globalExportMethods = ['t', 'rt', 'd', 'n', 'tm', 'te']
2395
+ ;
2396
+ function injectGlobalFields(app, composer) {
2397
+ const i18n = Object.create(null);
2398
+ globalExportProps.forEach(prop => {
2399
+ const desc = Object.getOwnPropertyDescriptor(composer, prop);
2400
+ if (!desc) {
2401
+ throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
2402
+ }
2403
+ const wrap = isRef(desc.value) // check computed props
2404
+ ? {
2405
+ get() {
2406
+ return desc.value.value;
2407
+ },
2408
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2409
+ set(val) {
2410
+ desc.value.value = val;
2411
+ }
2412
+ }
2413
+ : {
2414
+ get() {
2415
+ return desc.get && desc.get();
2416
+ }
2417
+ };
2418
+ Object.defineProperty(i18n, prop, wrap);
2419
+ });
2420
+ app.config.globalProperties.$i18n = i18n;
2421
+ globalExportMethods.forEach(method => {
2422
+ const desc = Object.getOwnPropertyDescriptor(composer, method);
2423
+ if (!desc || !desc.value) {
2424
+ throw createI18nError(I18nErrorCodes.UNEXPECTED_ERROR);
2425
+ }
2426
+ Object.defineProperty(app.config.globalProperties, `$${method}`, desc);
2427
+ });
2428
+ const dispose = () => {
2429
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2430
+ delete app.config.globalProperties.$i18n;
2431
+ globalExportMethods.forEach(method => {
2432
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2433
+ delete app.config.globalProperties[`$${method}`];
2434
+ });
2435
+ };
2436
+ return dispose;
2437
+ }
2438
+
2439
+ const DatetimeFormatImpl = /* #__PURE__*/ defineComponent({
2440
+ /* eslint-disable */
2441
+ name: 'i18n-d',
2442
+ props: assign({
2443
+ value: {
2444
+ type: [Number, Date],
2445
+ required: true
2446
+ },
2447
+ format: {
2448
+ type: [String, Object]
2449
+ }
2450
+ }, baseFormatProps),
2451
+ /* eslint-enable */
2452
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2453
+ setup(props, context) {
2454
+ const i18n = props.i18n ||
2455
+ useI18n({
2456
+ useScope: props.scope,
2457
+ __useComponent: true
2458
+ });
2459
+ return renderFormatter(props, context, DATETIME_FORMAT_OPTIONS_KEYS, (...args) =>
2460
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2461
+ i18n[DatetimePartsSymbol](...args));
2462
+ }
2463
+ });
2464
+ /**
2465
+ * Datetime Format Component
2466
+ *
2467
+ * @remarks
2468
+ * See the following items for property about details
2469
+ *
2470
+ * @VueI18nSee [FormattableProps](component#formattableprops)
2471
+ * @VueI18nSee [BaseFormatProps](component#baseformatprops)
2472
+ * @VueI18nSee [Custom Formatting](../guide/essentials/datetime#custom-formatting)
2473
+ *
2474
+ * @VueI18nDanger
2475
+ * Not supported IE, due to no support `Intl.DateTimeFormat#formatToParts` in [IE](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
2476
+ *
2477
+ * If you want to use it, you need to use [polyfill](https://github.com/formatjs/formatjs/tree/main/packages/intl-datetimeformat)
2478
+ *
2479
+ * @VueI18nComponent
2480
+ */
2481
+ const DatetimeFormat = DatetimeFormatImpl;
2482
+ const I18nD = DatetimeFormat;
2483
+
2484
+ {
2485
+ initFeatureFlags();
2486
+ }
2487
+ // register message compiler for jit compilation
2488
+ registerMessageCompiler(compile);
2489
+ // register message resolver at vue-i18n
2490
+ registerMessageResolver(resolveValue);
2491
+ // register fallback locale at vue-i18n
2492
+ registerLocaleFallbacker(fallbackWithLocaleChain);
2493
+ // NOTE: experimental !!
2494
+ if ((process.env.NODE_ENV !== 'production') || __INTLIFY_PROD_DEVTOOLS__) {
2495
+ const target = getGlobalThis();
2496
+ target.__INTLIFY__ = true;
2497
+ setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__);
2498
+ }
2499
+ if ((process.env.NODE_ENV !== 'production')) ;
2500
+
2501
+ export { DatetimeFormat, I18nD, I18nInjectionKey, I18nN, I18nT, NumberFormat, Translation, VERSION, createI18n, useI18n, vTDirective };