@@ -7,18 +7,24 @@ import {
77 makeSymbol ,
88 warn
99} from '@intlify/shared'
10- import { effectScope , getCurrentInstance , inject , isRef , onMounted , onUnmounted } from 'vue'
10+ import { effectScope , inject , isRef , onMounted , onUnmounted } from 'vue'
1111import { createComposer } from './composer'
1212import { addTimelineEvent , enableDevTools } from './devtools'
1313import { I18nErrorCodes , createI18nError } from './errors'
1414import { apply as applyPlugin } from './plugin/next'
1515import { DisableEmitter , DisposeSymbol , EnableEmitter } from './symbols'
16- import { adjustI18nResources , getComponentOptions } from './utils'
16+ import { adjustI18nResources , getComponentOptions , getCurrentInstance } from './utils'
1717import { I18nWarnCodes , getWarnMessage } from './warnings'
1818
1919import type { FallbackLocale , Locale , LocaleParams , SchemaParams } from '@intlify/core-base'
2020import type { VueDevToolsEmitter , VueDevToolsEmitterEvents } from '@intlify/devtools-types'
21- import type { App , ComponentInternalInstance , EffectScope , InjectionKey } from 'vue'
21+ import type {
22+ App ,
23+ ComponentInternalInstance ,
24+ EffectScope ,
25+ GenericComponentInstance ,
26+ InjectionKey
27+ } from 'vue'
2228import type {
2329 Composer ,
2430 ComposerInternalOptions ,
@@ -136,17 +142,17 @@ export interface I18nInternal<
136142 OptionLocale = Locale
137143> {
138144 __instances : Map <
139- ComponentInternalInstance ,
145+ ComponentInternalInstance | GenericComponentInstance ,
140146 Composer < Messages , DateTimeFormats , NumberFormats , OptionLocale >
141147 >
142148 __getInstance < Instance extends Composer < Messages , DateTimeFormats , NumberFormats , OptionLocale > > (
143- component : ComponentInternalInstance
149+ component : ComponentInternalInstance | GenericComponentInstance
144150 ) : Instance | null
145151 __setInstance < Instance extends Composer < Messages , DateTimeFormats , NumberFormats , OptionLocale > > (
146- component : ComponentInternalInstance ,
152+ component : ComponentInternalInstance | GenericComponentInstance ,
147153 instance : Instance
148154 ) : void
149- __deleteInstance ( component : ComponentInternalInstance ) : void
155+ __deleteInstance ( component : ComponentInternalInstance | GenericComponentInstance ) : void
150156 __composerExtend ?: ComposerExtender
151157}
152158
@@ -314,17 +320,22 @@ export function createI18n(options: any = {}): any {
314320 const __globalInjection = isBoolean ( options . globalInjection )
315321 ? options . globalInjection
316322 : true
317- const __instances = new Map < ComponentInternalInstance , Composer > ( )
323+ const __instances = new Map < ComponentInternalInstance | GenericComponentInstance , Composer > ( )
318324 const [ globalScope , __global ] = createGlobal ( options )
319325 const symbol : InjectionKey < I18n > | string = /* #__PURE__*/ makeSymbol ( __DEV__ ? 'vue-i18n' : '' )
320326
321- function __getInstance ( component : ComponentInternalInstance ) : Composer | null {
327+ function __getInstance (
328+ component : ComponentInternalInstance | GenericComponentInstance
329+ ) : Composer | null {
322330 return __instances . get ( component ) || null
323331 }
324- function __setInstance ( component : ComponentInternalInstance , instance : Composer ) : void {
332+ function __setInstance (
333+ component : ComponentInternalInstance | GenericComponentInstance ,
334+ instance : Composer
335+ ) : void {
325336 __instances . set ( component , instance )
326337 }
327- function __deleteInstance ( component : ComponentInternalInstance ) : void {
338+ function __deleteInstance ( component : ComponentInternalInstance | GenericComponentInstance ) : void {
328339 __instances . delete ( component )
329340 }
330341
@@ -556,7 +567,7 @@ function createGlobal(options: I18nOptions): [EffectScope, Composer] {
556567 return [ scope , obj ]
557568}
558569
559- function getI18nInstance ( instance : ComponentInternalInstance ) : I18n {
570+ function getI18nInstance ( instance : ComponentInternalInstance | GenericComponentInstance ) : I18n {
560571 const i18n = inject (
561572 ! instance . isCE ? instance . appContext . app . __VUE_I18N_SYMBOL__ ! : I18nInjectionKey
562573 )
@@ -588,12 +599,13 @@ function getGlobalComposer(i18n: I18n): Composer {
588599
589600function getComposer (
590601 i18n : I18n ,
591- target : ComponentInternalInstance ,
602+ target : ComponentInternalInstance | GenericComponentInstance ,
592603 useComponent = false
593604) : Composer | null {
594605 let composer : Composer | null = null
595606 const root = target . root
596- let current : ComponentInternalInstance | null = getParentComponentInstance ( target , useComponent )
607+ let current : ComponentInternalInstance | GenericComponentInstance | null =
608+ getParentComponentInstance ( target , useComponent )
597609 while ( current != null ) {
598610 const i18nInternal = i18n as unknown as I18nInternal
599611 composer = i18nInternal . __getInstance ( current )
@@ -610,7 +622,7 @@ function getComposer(
610622}
611623
612624function getParentComponentInstance (
613- target : ComponentInternalInstance | null ,
625+ target : ComponentInternalInstance | GenericComponentInstance | null ,
614626 useComponent = false
615627) {
616628 if ( target == null ) {
@@ -622,16 +634,16 @@ function getParentComponentInstance(
622634
623635function setupLifeCycle (
624636 i18n : I18nInternal ,
625- target : ComponentInternalInstance ,
637+ target : ComponentInternalInstance | GenericComponentInstance ,
626638 composer : Composer
627639) : void {
628640 let emitter : VueDevToolsEmitter | null = null
629641
630642 // eslint-disable-next-line vue-composable/lifecycle-placement -- NOTE(kazupon): not Vue component
631643 onMounted ( ( ) => {
632644 // inject composer instance to DOM for intlify-devtools
633- if ( ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) && ! __NODE_JS__ && target . vnode . el ) {
634- target . vnode . el . __VUE_I18N__ = composer
645+ if ( ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) && ! __NODE_JS__ ) {
646+ target . __VUE_I18N__ = composer
635647 emitter = createEmitter < VueDevToolsEmitterEvents > ( )
636648 // eslint-disable-next-line @typescript-eslint/no-explicit-any
637649 const _composer = composer as any
@@ -646,15 +658,10 @@ function setupLifeCycle(
646658 const _composer = composer as any
647659
648660 // remove composer instance from DOM for intlify-devtools
649- if (
650- ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) &&
651- ! __NODE_JS__ &&
652- target . vnode . el &&
653- target . vnode . el . __VUE_I18N__
654- ) {
661+ if ( ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) && ! __NODE_JS__ && target . __VUE_I18N__ ) {
655662 emitter && emitter . off ( '*' , addTimelineEvent )
656663 _composer [ DisableEmitter ] && _composer [ DisableEmitter ] ( )
657- delete target . vnode . el . __VUE_I18N__
664+ delete target . __VUE_I18N__
658665 }
659666 i18n . __deleteInstance ( target )
660667
0 commit comments