UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

1,087 lines (1,086 loc) 37.7 kB
import { makeSymbol, assign, isNumber, isString, isObject, isEmptyObject, isBoolean, isArray, isPlainObject, isRegExp, isFunction, getGlobalThis, hasOwn, inBrowser } from "../../@intlify/shared/dist/shared.esm-bundler.mjs"; import { CoreWarnCodes, NUMBER_FORMAT_OPTIONS_KEYS, DATETIME_FORMAT_OPTIONS_KEYS, DEFAULT_LOCALE, registerMessageCompiler, registerMessageResolver, registerLocaleFallbacker, setDevToolsHook, updateFallbackLocale, compileToFunction, resolveValue, fallbackWithLocaleChain, createCoreContext, clearDateTimeFormat, clearNumberFormat, setAdditionalMeta, getFallbackContext, NOT_REOSLVED, parseTranslateArgs, translate, MISSING_RESOLVE_VALUE, parseDateTimeArgs, datetime, parseNumberArgs, number, setFallbackContext } from "../../@intlify/core-base/dist/core-base.esm-bundler.mjs"; import { h, getCurrentInstance, inject, onMounted, onUnmounted, shallowRef, ref, computed, onBeforeMount, watch, Fragment, createVNode, Text } from "vue"; import { CompileErrorCodes, createCompileError } from "../../@intlify/message-compiler/dist/message-compiler.esm-bundler.mjs"; /*! * vue-i18n v9.2.2 * (c) 2022 kazuya kawaguchi * Released under the MIT License. */ const VERSION = "9.2.2"; function initFeatureFlags() { if (typeof __VUE_I18N_FULL_INSTALL__ !== "boolean") { getGlobalThis().__VUE_I18N_FULL_INSTALL__ = true; } if (typeof __VUE_I18N_LEGACY_API__ !== "boolean") { getGlobalThis().__VUE_I18N_LEGACY_API__ = true; } if (typeof __INTLIFY_PROD_DEVTOOLS__ !== "boolean") { getGlobalThis().__INTLIFY_PROD_DEVTOOLS__ = false; } } CoreWarnCodes.__EXTEND_POINT__; let code = CompileErrorCodes.__EXTEND_POINT__; const inc = () => ++code; const I18nErrorCodes = { UNEXPECTED_RETURN_TYPE: code, INVALID_ARGUMENT: inc(), MUST_BE_CALL_SETUP_TOP: inc(), NOT_INSLALLED: inc(), NOT_AVAILABLE_IN_LEGACY_MODE: inc(), REQUIRED_VALUE: inc(), INVALID_VALUE: inc(), CANNOT_SETUP_VUE_DEVTOOLS_PLUGIN: inc(), NOT_INSLALLED_WITH_PROVIDE: inc(), UNEXPECTED_ERROR: inc(), NOT_COMPATIBLE_LEGACY_VUE_I18N: inc(), BRIDGE_SUPPORT_VUE_2_ONLY: inc(), MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION: inc(), NOT_AVAILABLE_COMPOSITION_IN_LEGACY: inc(), __EXTEND_POINT__: inc() }; function createI18nError(code2, ...args) { return createCompileError(code2, null, void 0); } const TransrateVNodeSymbol = /* @__PURE__ */ makeSymbol("__transrateVNode"); const DatetimePartsSymbol = /* @__PURE__ */ makeSymbol("__datetimeParts"); const NumberPartsSymbol = /* @__PURE__ */ makeSymbol("__numberParts"); const SetPluralRulesSymbol = makeSymbol("__setPluralRules"); makeSymbol("__intlifyMeta"); const InejctWithOption = /* @__PURE__ */ makeSymbol("__injectWithOption"); function handleFlatJson(obj) { if (!isObject(obj)) { return obj; } for (const key in obj) { if (!hasOwn(obj, key)) { continue; } if (!key.includes(".")) { if (isObject(obj[key])) { handleFlatJson(obj[key]); } } else { const subKeys = key.split("."); const lastIndex = subKeys.length - 1; let currentObj = obj; for (let i = 0; i < lastIndex; i++) { if (!(subKeys[i] in currentObj)) { currentObj[subKeys[i]] = {}; } currentObj = currentObj[subKeys[i]]; } currentObj[subKeys[lastIndex]] = obj[key]; delete obj[key]; if (isObject(currentObj[subKeys[lastIndex]])) { handleFlatJson(currentObj[subKeys[lastIndex]]); } } } return obj; } function getLocaleMessages(locale, options) { const { messages, __i18n, messageResolver, flatJson } = options; const ret = isPlainObject(messages) ? messages : isArray(__i18n) ? {} : { [locale]: {} }; if (isArray(__i18n)) { __i18n.forEach((custom) => { if ("locale" in custom && "resource" in custom) { const { locale: locale2, resource } = custom; if (locale2) { ret[locale2] = ret[locale2] || {}; deepCopy(resource, ret[locale2]); } else { deepCopy(resource, ret); } } else { isString(custom) && deepCopy(JSON.parse(custom), ret); } }); } if (messageResolver == null && flatJson) { for (const key in ret) { if (hasOwn(ret, key)) { handleFlatJson(ret[key]); } } } return ret; } const isNotObjectOrIsArray = (val) => !isObject(val) || isArray(val); function deepCopy(src, des) { if (isNotObjectOrIsArray(src) || isNotObjectOrIsArray(des)) { throw createI18nError(I18nErrorCodes.INVALID_VALUE); } for (const key in src) { if (hasOwn(src, key)) { if (isNotObjectOrIsArray(src[key]) || isNotObjectOrIsArray(des[key])) { des[key] = src[key]; } else { deepCopy(src[key], des[key]); } } } } function getComponentOptions(instance) { return instance.type; } function adjustI18nResources(global, options, componentOptions) { let messages = isObject(options.messages) ? options.messages : {}; if ("__i18nGlobal" in componentOptions) { messages = getLocaleMessages(global.locale.value, { messages, __i18n: componentOptions.__i18nGlobal }); } const locales = Object.keys(messages); if (locales.length) { locales.forEach((locale) => { global.mergeLocaleMessage(locale, messages[locale]); }); } { if (isObject(options.datetimeFormats)) { const locales2 = Object.keys(options.datetimeFormats); if (locales2.length) { locales2.forEach((locale) => { global.mergeDateTimeFormat(locale, options.datetimeFormats[locale]); }); } } if (isObject(options.numberFormats)) { const locales2 = Object.keys(options.numberFormats); if (locales2.length) { locales2.forEach((locale) => { global.mergeNumberFormat(locale, options.numberFormats[locale]); }); } } } } function createTextNode(key) { return createVNode(Text, null, key, 0); } const DEVTOOLS_META = "__INTLIFY_META__"; let composerID = 0; function defineCoreMissingHandler(missing) { return (ctx, locale, key, type) => { return missing(locale, key, getCurrentInstance() || void 0, type); }; } const getMetaInfo = () => { const instance = getCurrentInstance(); let meta = null; return instance && (meta = getComponentOptions(instance)[DEVTOOLS_META]) ? { [DEVTOOLS_META]: meta } : null; }; function createComposer(options = {}, VueI18nLegacy) { const { __root } = options; const _isGlobal = __root === void 0; let _inheritLocale = isBoolean(options.inheritLocale) ? options.inheritLocale : true; const _locale = ref( __root && _inheritLocale ? __root.locale.value : isString(options.locale) ? options.locale : DEFAULT_LOCALE ); const _fallbackLocale = ref( __root && _inheritLocale ? __root.fallbackLocale.value : isString(options.fallbackLocale) || isArray(options.fallbackLocale) || isPlainObject(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale.value ); const _messages = ref(getLocaleMessages(_locale.value, options)); const _datetimeFormats = ref(isPlainObject(options.datetimeFormats) ? options.datetimeFormats : { [_locale.value]: {} }); const _numberFormats = ref(isPlainObject(options.numberFormats) ? options.numberFormats : { [_locale.value]: {} }); let _missingWarn = __root ? __root.missingWarn : isBoolean(options.missingWarn) || isRegExp(options.missingWarn) ? options.missingWarn : true; let _fallbackWarn = __root ? __root.fallbackWarn : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn) ? options.fallbackWarn : true; let _fallbackRoot = __root ? __root.fallbackRoot : isBoolean(options.fallbackRoot) ? options.fallbackRoot : true; let _fallbackFormat = !!options.fallbackFormat; let _missing = isFunction(options.missing) ? options.missing : null; let _runtimeMissing = isFunction(options.missing) ? defineCoreMissingHandler(options.missing) : null; let _postTranslation = isFunction(options.postTranslation) ? options.postTranslation : null; let _warnHtmlMessage = __root ? __root.warnHtmlMessage : isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true; let _escapeParameter = !!options.escapeParameter; const _modifiers = __root ? __root.modifiers : isPlainObject(options.modifiers) ? options.modifiers : {}; let _pluralRules = options.pluralRules || __root && __root.pluralRules; let _context; const getCoreContext = () => { _isGlobal && setFallbackContext(null); const ctxOptions = { version: VERSION, locale: _locale.value, fallbackLocale: _fallbackLocale.value, messages: _messages.value, modifiers: _modifiers, pluralRules: _pluralRules, missing: _runtimeMissing === null ? void 0 : _runtimeMissing, missingWarn: _missingWarn, fallbackWarn: _fallbackWarn, fallbackFormat: _fallbackFormat, unresolving: true, postTranslation: _postTranslation === null ? void 0 : _postTranslation, warnHtmlMessage: _warnHtmlMessage, escapeParameter: _escapeParameter, messageResolver: options.messageResolver, __meta: { framework: "vue" } }; { ctxOptions.datetimeFormats = _datetimeFormats.value; ctxOptions.numberFormats = _numberFormats.value; ctxOptions.__datetimeFormatters = isPlainObject(_context) ? _context.__datetimeFormatters : void 0; ctxOptions.__numberFormatters = isPlainObject(_context) ? _context.__numberFormatters : void 0; } const ctx = createCoreContext(ctxOptions); _isGlobal && setFallbackContext(ctx); return ctx; }; _context = getCoreContext(); updateFallbackLocale(_context, _locale.value, _fallbackLocale.value); function trackReactivityValues() { return [ _locale.value, _fallbackLocale.value, _messages.value, _datetimeFormats.value, _numberFormats.value ]; } const locale = computed({ get: () => _locale.value, set: (val) => { _locale.value = val; _context.locale = _locale.value; } }); const fallbackLocale = computed({ get: () => _fallbackLocale.value, set: (val) => { _fallbackLocale.value = val; _context.fallbackLocale = _fallbackLocale.value; updateFallbackLocale(_context, _locale.value, val); } }); const messages = computed(() => _messages.value); const datetimeFormats = /* @__PURE__ */ computed(() => _datetimeFormats.value); const numberFormats = /* @__PURE__ */ computed(() => _numberFormats.value); function getPostTranslationHandler() { return isFunction(_postTranslation) ? _postTranslation : null; } function setPostTranslationHandler(handler) { _postTranslation = handler; _context.postTranslation = handler; } function getMissingHandler() { return _missing; } function setMissingHandler(handler) { if (handler !== null) { _runtimeMissing = defineCoreMissingHandler(handler); } _missing = handler; _context.missing = _runtimeMissing; } const wrapWithDeps = (fn, argumentParser, warnType, fallbackSuccess, fallbackFail, successCondition) => { trackReactivityValues(); let ret; if (__INTLIFY_PROD_DEVTOOLS__) { try { setAdditionalMeta(getMetaInfo()); if (!_isGlobal) { _context.fallbackContext = __root ? getFallbackContext() : void 0; } ret = fn(_context); } finally { setAdditionalMeta(null); if (!_isGlobal) { _context.fallbackContext = void 0; } } } else { ret = fn(_context); } if (isNumber(ret) && ret === NOT_REOSLVED) { const [key, arg2] = argumentParser(); return __root && _fallbackRoot ? fallbackSuccess(__root) : fallbackFail(key); } else if (successCondition(ret)) { return ret; } else { throw createI18nError(I18nErrorCodes.UNEXPECTED_RETURN_TYPE); } }; function t(...args) { return wrapWithDeps((context) => Reflect.apply(translate, null, [context, ...args]), () => parseTranslateArgs(...args), "translate", (root) => Reflect.apply(root.t, root, [...args]), (key) => key, (val) => isString(val)); } function rt(...args) { const [arg1, arg2, arg3] = args; if (arg3 && !isObject(arg3)) { throw createI18nError(I18nErrorCodes.INVALID_ARGUMENT); } return t(...[arg1, arg2, assign({ resolvedMessage: true }, arg3 || {})]); } function d(...args) { 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)); } function n(...args) { 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)); } function normalize(values) { return values.map((val) => isString(val) || isNumber(val) || isBoolean(val) ? createTextNode(String(val)) : val); } const interpolate = (val) => val; const processor = { normalize, interpolate, type: "vnode" }; function transrateVNode(...args) { return wrapWithDeps( (context) => { let ret; const _context2 = context; try { _context2.processor = processor; ret = Reflect.apply(translate, null, [_context2, ...args]); } finally { _context2.processor = null; } return ret; }, () => parseTranslateArgs(...args), "translate", (root) => root[TransrateVNodeSymbol](...args), (key) => [createTextNode(key)], (val) => isArray(val) ); } function numberParts(...args) { return wrapWithDeps( (context) => Reflect.apply(number, null, [context, ...args]), () => parseNumberArgs(...args), "number format", (root) => root[NumberPartsSymbol](...args), () => [], (val) => isString(val) || isArray(val) ); } function datetimeParts(...args) { return wrapWithDeps( (context) => Reflect.apply(datetime, null, [context, ...args]), () => parseDateTimeArgs(...args), "datetime format", (root) => root[DatetimePartsSymbol](...args), () => [], (val) => isString(val) || isArray(val) ); } function setPluralRules(rules) { _pluralRules = rules; _context.pluralRules = _pluralRules; } function te(key, locale2) { const targetLocale = isString(locale2) ? locale2 : _locale.value; const message = getLocaleMessage(targetLocale); return _context.messageResolver(message, key) !== null; } function resolveMessages(key) { let messages2 = null; const locales = fallbackWithLocaleChain(_context, _fallbackLocale.value, _locale.value); for (let i = 0; i < locales.length; i++) { const targetLocaleMessages = _messages.value[locales[i]] || {}; const messageValue = _context.messageResolver(targetLocaleMessages, key); if (messageValue != null) { messages2 = messageValue; break; } } return messages2; } function tm(key) { const messages2 = resolveMessages(key); return messages2 != null ? messages2 : __root ? __root.tm(key) || {} : {}; } function getLocaleMessage(locale2) { return _messages.value[locale2] || {}; } function setLocaleMessage(locale2, message) { _messages.value[locale2] = message; _context.messages = _messages.value; } function mergeLocaleMessage(locale2, message) { _messages.value[locale2] = _messages.value[locale2] || {}; deepCopy(message, _messages.value[locale2]); _context.messages = _messages.value; } function getDateTimeFormat(locale2) { return _datetimeFormats.value[locale2] || {}; } function setDateTimeFormat(locale2, format) { _datetimeFormats.value[locale2] = format; _context.datetimeFormats = _datetimeFormats.value; clearDateTimeFormat(_context, locale2, format); } function mergeDateTimeFormat(locale2, format) { _datetimeFormats.value[locale2] = assign(_datetimeFormats.value[locale2] || {}, format); _context.datetimeFormats = _datetimeFormats.value; clearDateTimeFormat(_context, locale2, format); } function getNumberFormat(locale2) { return _numberFormats.value[locale2] || {}; } function setNumberFormat(locale2, format) { _numberFormats.value[locale2] = format; _context.numberFormats = _numberFormats.value; clearNumberFormat(_context, locale2, format); } function mergeNumberFormat(locale2, format) { _numberFormats.value[locale2] = assign(_numberFormats.value[locale2] || {}, format); _context.numberFormats = _numberFormats.value; clearNumberFormat(_context, locale2, format); } composerID++; if (__root && inBrowser) { watch(__root.locale, (val) => { if (_inheritLocale) { _locale.value = val; _context.locale = val; updateFallbackLocale(_context, _locale.value, _fallbackLocale.value); } }); watch(__root.fallbackLocale, (val) => { if (_inheritLocale) { _fallbackLocale.value = val; _context.fallbackLocale = val; updateFallbackLocale(_context, _locale.value, _fallbackLocale.value); } }); } const composer = { id: composerID, locale, fallbackLocale, get inheritLocale() { return _inheritLocale; }, set inheritLocale(val) { _inheritLocale = val; if (val && __root) { _locale.value = __root.locale.value; _fallbackLocale.value = __root.fallbackLocale.value; updateFallbackLocale(_context, _locale.value, _fallbackLocale.value); } }, get availableLocales() { return Object.keys(_messages.value).sort(); }, messages, get modifiers() { return _modifiers; }, get pluralRules() { return _pluralRules || {}; }, get isGlobal() { return _isGlobal; }, get missingWarn() { return _missingWarn; }, set missingWarn(val) { _missingWarn = val; _context.missingWarn = _missingWarn; }, get fallbackWarn() { return _fallbackWarn; }, set fallbackWarn(val) { _fallbackWarn = val; _context.fallbackWarn = _fallbackWarn; }, get fallbackRoot() { return _fallbackRoot; }, set fallbackRoot(val) { _fallbackRoot = val; }, get fallbackFormat() { return _fallbackFormat; }, set fallbackFormat(val) { _fallbackFormat = val; _context.fallbackFormat = _fallbackFormat; }, get warnHtmlMessage() { return _warnHtmlMessage; }, set warnHtmlMessage(val) { _warnHtmlMessage = val; _context.warnHtmlMessage = val; }, get escapeParameter() { return _escapeParameter; }, set escapeParameter(val) { _escapeParameter = val; _context.escapeParameter = val; }, t, getLocaleMessage, setLocaleMessage, mergeLocaleMessage, getPostTranslationHandler, setPostTranslationHandler, getMissingHandler, setMissingHandler, [SetPluralRulesSymbol]: setPluralRules }; { composer.datetimeFormats = datetimeFormats; composer.numberFormats = numberFormats; composer.rt = rt; composer.te = te; composer.tm = tm; composer.d = d; composer.n = n; composer.getDateTimeFormat = getDateTimeFormat; composer.setDateTimeFormat = setDateTimeFormat; composer.mergeDateTimeFormat = mergeDateTimeFormat; composer.getNumberFormat = getNumberFormat; composer.setNumberFormat = setNumberFormat; composer.mergeNumberFormat = mergeNumberFormat; composer[InejctWithOption] = options.__injectWithOption; composer[TransrateVNodeSymbol] = transrateVNode; composer[DatetimePartsSymbol] = datetimeParts; composer[NumberPartsSymbol] = numberParts; } return composer; } const baseFormatProps = { tag: { type: [String, Object] }, locale: { type: String }, scope: { type: String, validator: (val) => val === "parent" || val === "global", default: "parent" }, i18n: { type: Object } }; function getInterpolateArg({ slots }, keys) { if (keys.length === 1 && keys[0] === "default") { const ret = slots.default ? slots.default() : []; return ret.reduce((slot, current) => { return slot = [ ...slot, ...isArray(current.children) ? current.children : [current] ]; }, []); } else { return keys.reduce((arg, key) => { const slot = slots[key]; if (slot) { arg[key] = slot(); } return arg; }, {}); } } function getFragmentableTag(tag) { return Fragment; } ({ name: "i18n-t", props: assign({ keypath: { type: String, required: true }, plural: { type: [Number, String], validator: (val) => isNumber(val) || !isNaN(val) } }, baseFormatProps), setup(props, context) { const { slots, attrs } = context; const i18n = props.i18n || useI18n({ useScope: props.scope, __useComponent: true }); return () => { const keys = Object.keys(slots).filter((key) => key !== "_"); const options = {}; if (props.locale) { options.locale = props.locale; } if (props.plural !== void 0) { options.plural = isString(props.plural) ? +props.plural : props.plural; } const arg = getInterpolateArg(context, keys); const children = i18n[TransrateVNodeSymbol](props.keypath, arg, options); const assignedAttrs = assign({}, attrs); const tag = isString(props.tag) || isObject(props.tag) ? props.tag : getFragmentableTag(); return h(tag, assignedAttrs, children); }; } }); function isVNode(target) { return isArray(target) && !isString(target[0]); } function renderFormatter(props, context, slotKeys, partFormatter) { const { slots, attrs } = context; return () => { const options = { part: true }; let overrides = {}; if (props.locale) { options.locale = props.locale; } if (isString(props.format)) { options.key = props.format; } else if (isObject(props.format)) { if (isString(props.format.key)) { options.key = props.format.key; } overrides = Object.keys(props.format).reduce((options2, prop) => { return slotKeys.includes(prop) ? assign({}, options2, { [prop]: props.format[prop] }) : options2; }, {}); } const parts = partFormatter(...[props.value, options, overrides]); let children = [options.key]; if (isArray(parts)) { children = parts.map((part, index) => { const slot = slots[part.type]; const node = slot ? slot({ [part.type]: part.value, index, parts }) : [part.value]; if (isVNode(node)) { node[0].key = `${part.type}-${index}`; } return node; }); } else if (isString(parts)) { children = [parts]; } const assignedAttrs = assign({}, attrs); const tag = isString(props.tag) || isObject(props.tag) ? props.tag : getFragmentableTag(); return h(tag, assignedAttrs, children); }; } ({ name: "i18n-n", props: assign({ value: { type: Number, required: true }, format: { type: [String, Object] } }, baseFormatProps), setup(props, context) { const i18n = props.i18n || useI18n({ useScope: "parent", __useComponent: true }); return renderFormatter(props, context, NUMBER_FORMAT_OPTIONS_KEYS, (...args) => i18n[NumberPartsSymbol](...args)); } }); ({ name: "i18n-d", props: assign({ value: { type: [Number, Date], required: true }, format: { type: [String, Object] } }, baseFormatProps), setup(props, context) { const i18n = props.i18n || useI18n({ useScope: "parent", __useComponent: true }); return renderFormatter(props, context, DATETIME_FORMAT_OPTIONS_KEYS, (...args) => i18n[DatetimePartsSymbol](...args)); } }); const I18nInjectionKey = /* @__PURE__ */ makeSymbol("global-vue-i18n"); function useI18n(options = {}) { const instance = getCurrentInstance(); if (instance == null) { throw createI18nError(I18nErrorCodes.MUST_BE_CALL_SETUP_TOP); } if (!instance.isCE && instance.appContext.app != null && !instance.appContext.app.__VUE_I18N_SYMBOL__) { throw createI18nError(I18nErrorCodes.NOT_INSLALLED); } const i18n = getI18nInstance(instance); const global = getGlobalComposer(i18n); const componentOptions = getComponentOptions(instance); const scope = getScope(options, componentOptions); if (__VUE_I18N_LEGACY_API__) { if (i18n.mode === "legacy" && !options.__useComponent) { if (!i18n.allowComposition) { throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_IN_LEGACY_MODE); } return useI18nForLegacy(instance, scope, global, options); } } if (scope === "global") { adjustI18nResources(global, options, componentOptions); return global; } if (scope === "parent") { let composer2 = getComposer(i18n, instance, options.__useComponent); if (composer2 == null) { composer2 = global; } return composer2; } const i18nInternal = i18n; let composer = i18nInternal.__getInstance(instance); if (composer == null) { const composerOptions = assign({}, options); if ("__i18n" in componentOptions) { composerOptions.__i18n = componentOptions.__i18n; } if (global) { composerOptions.__root = global; } composer = createComposer(composerOptions); setupLifeCycle(i18nInternal, instance); i18nInternal.__setInstance(instance, composer); } return composer; } function getI18nInstance(instance) { { const i18n = inject(!instance.isCE ? instance.appContext.app.__VUE_I18N_SYMBOL__ : I18nInjectionKey); if (!i18n) { throw createI18nError(!instance.isCE ? I18nErrorCodes.UNEXPECTED_ERROR : I18nErrorCodes.NOT_INSLALLED_WITH_PROVIDE); } return i18n; } } function getScope(options, componentOptions) { return isEmptyObject(options) ? "__i18n" in componentOptions ? "local" : "global" : !options.useScope ? "local" : options.useScope; } function getGlobalComposer(i18n) { return i18n.mode === "composition" ? i18n.global : i18n.global.__composer; } function getComposer(i18n, target, useComponent = false) { let composer = null; const root = target.root; let current = target.parent; while (current != null) { const i18nInternal = i18n; if (i18n.mode === "composition") { composer = i18nInternal.__getInstance(current); } else { if (__VUE_I18N_LEGACY_API__) { const vueI18n = i18nInternal.__getInstance(current); if (vueI18n != null) { composer = vueI18n.__composer; if (useComponent && composer && !composer[InejctWithOption]) { composer = null; } } } } if (composer != null) { break; } if (root === current) { break; } current = current.parent; } return composer; } function setupLifeCycle(i18n, target, composer) { { onMounted(() => { }, target); onUnmounted(() => { i18n.__deleteInstance(target); }, target); } } function useI18nForLegacy(instance, scope, root, options = {}) { const isLocale = scope === "local"; const _composer = shallowRef(null); if (isLocale && instance.proxy && !(instance.proxy.$options.i18n || instance.proxy.$options.__i18n)) { throw createI18nError(I18nErrorCodes.MUST_DEFINE_I18N_OPTION_IN_ALLOW_COMPOSITION); } const _inheritLocale = isBoolean(options.inheritLocale) ? options.inheritLocale : true; const _locale = ref( isLocale && _inheritLocale ? root.locale.value : isString(options.locale) ? options.locale : DEFAULT_LOCALE ); const _fallbackLocale = ref( isLocale && _inheritLocale ? root.fallbackLocale.value : isString(options.fallbackLocale) || isArray(options.fallbackLocale) || isPlainObject(options.fallbackLocale) || options.fallbackLocale === false ? options.fallbackLocale : _locale.value ); const _messages = ref(getLocaleMessages(_locale.value, options)); const _datetimeFormats = ref(isPlainObject(options.datetimeFormats) ? options.datetimeFormats : { [_locale.value]: {} }); const _numberFormats = ref(isPlainObject(options.numberFormats) ? options.numberFormats : { [_locale.value]: {} }); const _missingWarn = isLocale ? root.missingWarn : isBoolean(options.missingWarn) || isRegExp(options.missingWarn) ? options.missingWarn : true; const _fallbackWarn = isLocale ? root.fallbackWarn : isBoolean(options.fallbackWarn) || isRegExp(options.fallbackWarn) ? options.fallbackWarn : true; const _fallbackRoot = isLocale ? root.fallbackRoot : isBoolean(options.fallbackRoot) ? options.fallbackRoot : true; const _fallbackFormat = !!options.fallbackFormat; const _missing = isFunction(options.missing) ? options.missing : null; const _postTranslation = isFunction(options.postTranslation) ? options.postTranslation : null; const _warnHtmlMessage = isLocale ? root.warnHtmlMessage : isBoolean(options.warnHtmlMessage) ? options.warnHtmlMessage : true; const _escapeParameter = !!options.escapeParameter; const _modifiers = isLocale ? root.modifiers : isPlainObject(options.modifiers) ? options.modifiers : {}; const _pluralRules = options.pluralRules || isLocale && root.pluralRules; function trackReactivityValues() { return [ _locale.value, _fallbackLocale.value, _messages.value, _datetimeFormats.value, _numberFormats.value ]; } const locale = computed({ get: () => { return _composer.value ? _composer.value.locale.value : _locale.value; }, set: (val) => { if (_composer.value) { _composer.value.locale.value = val; } _locale.value = val; } }); const fallbackLocale = computed({ get: () => { return _composer.value ? _composer.value.fallbackLocale.value : _fallbackLocale.value; }, set: (val) => { if (_composer.value) { _composer.value.fallbackLocale.value = val; } _fallbackLocale.value = val; } }); const messages = computed(() => { if (_composer.value) { return _composer.value.messages.value; } else { return _messages.value; } }); const datetimeFormats = computed(() => _datetimeFormats.value); const numberFormats = computed(() => _numberFormats.value); function getPostTranslationHandler() { return _composer.value ? _composer.value.getPostTranslationHandler() : _postTranslation; } function setPostTranslationHandler(handler) { if (_composer.value) { _composer.value.setPostTranslationHandler(handler); } } function getMissingHandler() { return _composer.value ? _composer.value.getMissingHandler() : _missing; } function setMissingHandler(handler) { if (_composer.value) { _composer.value.setMissingHandler(handler); } } function warpWithDeps(fn) { trackReactivityValues(); return fn(); } function t(...args) { return _composer.value ? warpWithDeps(() => Reflect.apply(_composer.value.t, null, [...args])) : warpWithDeps(() => ""); } function rt(...args) { return _composer.value ? Reflect.apply(_composer.value.rt, null, [...args]) : ""; } function d(...args) { return _composer.value ? warpWithDeps(() => Reflect.apply(_composer.value.d, null, [...args])) : warpWithDeps(() => ""); } function n(...args) { return _composer.value ? warpWithDeps(() => Reflect.apply(_composer.value.n, null, [...args])) : warpWithDeps(() => ""); } function tm(key) { return _composer.value ? _composer.value.tm(key) : {}; } function te(key, locale2) { return _composer.value ? _composer.value.te(key, locale2) : false; } function getLocaleMessage(locale2) { return _composer.value ? _composer.value.getLocaleMessage(locale2) : {}; } function setLocaleMessage(locale2, message) { if (_composer.value) { _composer.value.setLocaleMessage(locale2, message); _messages.value[locale2] = message; } } function mergeLocaleMessage(locale2, message) { if (_composer.value) { _composer.value.mergeLocaleMessage(locale2, message); } } function getDateTimeFormat(locale2) { return _composer.value ? _composer.value.getDateTimeFormat(locale2) : {}; } function setDateTimeFormat(locale2, format) { if (_composer.value) { _composer.value.setDateTimeFormat(locale2, format); _datetimeFormats.value[locale2] = format; } } function mergeDateTimeFormat(locale2, format) { if (_composer.value) { _composer.value.mergeDateTimeFormat(locale2, format); } } function getNumberFormat(locale2) { return _composer.value ? _composer.value.getNumberFormat(locale2) : {}; } function setNumberFormat(locale2, format) { if (_composer.value) { _composer.value.setNumberFormat(locale2, format); _numberFormats.value[locale2] = format; } } function mergeNumberFormat(locale2, format) { if (_composer.value) { _composer.value.mergeNumberFormat(locale2, format); } } const wrapper = { get id() { return _composer.value ? _composer.value.id : -1; }, locale, fallbackLocale, messages, datetimeFormats, numberFormats, get inheritLocale() { return _composer.value ? _composer.value.inheritLocale : _inheritLocale; }, set inheritLocale(val) { if (_composer.value) { _composer.value.inheritLocale = val; } }, get availableLocales() { return _composer.value ? _composer.value.availableLocales : Object.keys(_messages.value); }, get modifiers() { return _composer.value ? _composer.value.modifiers : _modifiers; }, get pluralRules() { return _composer.value ? _composer.value.pluralRules : _pluralRules; }, get isGlobal() { return _composer.value ? _composer.value.isGlobal : false; }, get missingWarn() { return _composer.value ? _composer.value.missingWarn : _missingWarn; }, set missingWarn(val) { if (_composer.value) { _composer.value.missingWarn = val; } }, get fallbackWarn() { return _composer.value ? _composer.value.fallbackWarn : _fallbackWarn; }, set fallbackWarn(val) { if (_composer.value) { _composer.value.missingWarn = val; } }, get fallbackRoot() { return _composer.value ? _composer.value.fallbackRoot : _fallbackRoot; }, set fallbackRoot(val) { if (_composer.value) { _composer.value.fallbackRoot = val; } }, get fallbackFormat() { return _composer.value ? _composer.value.fallbackFormat : _fallbackFormat; }, set fallbackFormat(val) { if (_composer.value) { _composer.value.fallbackFormat = val; } }, get warnHtmlMessage() { return _composer.value ? _composer.value.warnHtmlMessage : _warnHtmlMessage; }, set warnHtmlMessage(val) { if (_composer.value) { _composer.value.warnHtmlMessage = val; } }, get escapeParameter() { return _composer.value ? _composer.value.escapeParameter : _escapeParameter; }, set escapeParameter(val) { if (_composer.value) { _composer.value.escapeParameter = val; } }, t, getPostTranslationHandler, setPostTranslationHandler, getMissingHandler, setMissingHandler, rt, d, n, tm, te, getLocaleMessage, setLocaleMessage, mergeLocaleMessage, getDateTimeFormat, setDateTimeFormat, mergeDateTimeFormat, getNumberFormat, setNumberFormat, mergeNumberFormat }; function sync(composer) { composer.locale.value = _locale.value; composer.fallbackLocale.value = _fallbackLocale.value; Object.keys(_messages.value).forEach((locale2) => { composer.mergeLocaleMessage(locale2, _messages.value[locale2]); }); Object.keys(_datetimeFormats.value).forEach((locale2) => { composer.mergeDateTimeFormat(locale2, _datetimeFormats.value[locale2]); }); Object.keys(_numberFormats.value).forEach((locale2) => { composer.mergeNumberFormat(locale2, _numberFormats.value[locale2]); }); composer.escapeParameter = _escapeParameter; composer.fallbackFormat = _fallbackFormat; composer.fallbackRoot = _fallbackRoot; composer.fallbackWarn = _fallbackWarn; composer.missingWarn = _missingWarn; composer.warnHtmlMessage = _warnHtmlMessage; } onBeforeMount(() => { if (instance.proxy == null || instance.proxy.$i18n == null) { throw createI18nError(I18nErrorCodes.NOT_AVAILABLE_COMPOSITION_IN_LEGACY); } const composer = _composer.value = instance.proxy.$i18n.__composer; if (scope === "global") { _locale.value = composer.locale.value; _fallbackLocale.value = composer.fallbackLocale.value; _messages.value = composer.messages.value; _datetimeFormats.value = composer.datetimeFormats.value; _numberFormats.value = composer.numberFormats.value; } else if (isLocale) { sync(composer); } }); return wrapper; } registerMessageCompiler(compileToFunction); registerMessageResolver(resolveValue); registerLocaleFallbacker(fallbackWithLocaleChain); { initFeatureFlags(); } if (__INTLIFY_PROD_DEVTOOLS__) { const target = getGlobalThis(); target.__INTLIFY__ = true; setDevToolsHook(target.__INTLIFY_DEVTOOLS_GLOBAL_HOOK__); } export { I18nInjectionKey, VERSION, useI18n };