@@ -11,7 +11,6 @@ import {
1111import {
1212 InjectionKey ,
1313 effectScope ,
14- getCurrentInstance ,
1514 inject ,
1615 isRef ,
1716 onMounted ,
@@ -29,7 +28,11 @@ import {
2928 EnableEmitter ,
3029 InejctWithOptionSymbol
3130} from './symbols'
32- import { adjustI18nResources , getComponentOptions } from './utils'
31+ import {
32+ adjustI18nResources ,
33+ getComponentOptions ,
34+ getCurrentInstance
35+ } from './utils'
3336import { I18nWarnCodes , getWarnMessage } from './warnings'
3437
3538import type {
@@ -42,7 +45,12 @@ import type {
4245 VueDevToolsEmitter ,
4346 VueDevToolsEmitterEvents
4447} from '@intlify/devtools-types'
45- import type { App , ComponentInternalInstance , EffectScope } from 'vue'
48+ import type {
49+ App ,
50+ ComponentInternalInstance ,
51+ EffectScope ,
52+ GenericComponentInstance
53+ } from 'vue'
4654import type {
4755 Composer ,
4856 ComposerInternalOptions ,
@@ -73,9 +81,27 @@ declare module 'vue' {
7381 export interface ComponentInternalInstance {
7482 /**
7583 * @internal
76- * is custom element?
84+ * whether target component is custom element
85+ */
86+ isCE ?: boolean
87+ /**
88+ * @internal
89+ * for vue/devtools i18n composer hook
90+ */
91+ __VUE_I18N__ ?: Composer
92+ }
93+
94+ export interface GenericComponentInstance {
95+ /**
96+ * @internal
97+ * whether target component is custom element
7798 */
7899 isCE ?: boolean
100+ /**
101+ * @internal
102+ * for vue/devtools i18n composer hook
103+ */
104+ __VUE_I18N__ ?: Composer
79105 }
80106}
81107
@@ -240,7 +266,7 @@ export interface I18nInternal<
240266 OptionLocale = Locale
241267> {
242268 __instances : Map <
243- ComponentInternalInstance ,
269+ ComponentInternalInstance | GenericComponentInstance ,
244270 | VueI18n < Messages , DateTimeFormats , NumberFormats , OptionLocale >
245271 | Composer < Messages , DateTimeFormats , NumberFormats , OptionLocale >
246272 >
@@ -249,17 +275,19 @@ export interface I18nInternal<
249275 | VueI18n < Messages , DateTimeFormats , NumberFormats , OptionLocale >
250276 | Composer < Messages , DateTimeFormats , NumberFormats , OptionLocale >
251277 > (
252- component : ComponentInternalInstance
278+ component : ComponentInternalInstance | GenericComponentInstance
253279 ) : Instance | null
254280 __setInstance <
255281 Instance extends
256282 | VueI18n < Messages , DateTimeFormats , NumberFormats , OptionLocale >
257283 | Composer < Messages , DateTimeFormats , NumberFormats , OptionLocale >
258284 > (
259- component : ComponentInternalInstance ,
285+ component : ComponentInternalInstance | GenericComponentInstance ,
260286 instance : Instance
261287 ) : void
262- __deleteInstance ( component : ComponentInternalInstance ) : void
288+ __deleteInstance (
289+ component : ComponentInternalInstance | GenericComponentInstance
290+ ) : void
263291 __composerExtend ?: ComposerExtender
264292 /**
265293 * @deprecated will be removed at vue-i18n v12
@@ -495,24 +523,29 @@ export function createI18n(options: any = {}): any {
495523 const __globalInjection = isBoolean ( options . globalInjection )
496524 ? options . globalInjection
497525 : true
498- const __instances = new Map < ComponentInternalInstance , VueI18n | Composer > ( )
526+ const __instances = new Map <
527+ ComponentInternalInstance | GenericComponentInstance ,
528+ VueI18n | Composer
529+ > ( )
499530 const [ globalScope , __global ] = createGlobal ( options , __legacyMode )
500531 const symbol : InjectionKey < I18n > | string = /* #__PURE__*/ makeSymbol (
501532 __DEV__ ? 'vue-i18n' : ''
502533 )
503534
504535 function __getInstance < Instance extends VueI18n | Composer > (
505- component : ComponentInternalInstance
536+ component : ComponentInternalInstance | GenericComponentInstance
506537 ) : Instance | null {
507538 return ( __instances . get ( component ) as unknown as Instance ) || null
508539 }
509540 function __setInstance < Instance extends VueI18n | Composer > (
510- component : ComponentInternalInstance ,
541+ component : ComponentInternalInstance | GenericComponentInstance ,
511542 instance : Instance
512543 ) : void {
513544 __instances . set ( component , instance )
514545 }
515- function __deleteInstance ( component : ComponentInternalInstance ) : void {
546+ function __deleteInstance (
547+ component : ComponentInternalInstance | GenericComponentInstance
548+ ) : void {
516549 __instances . delete ( component )
517550 }
518551
@@ -801,7 +834,9 @@ function createGlobal(
801834 return [ scope , obj ]
802835}
803836
804- function getI18nInstance ( instance : ComponentInternalInstance ) : I18n {
837+ function getI18nInstance (
838+ instance : ComponentInternalInstance | GenericComponentInstance
839+ ) : I18n {
805840 const i18n = inject (
806841 ! instance . isCE
807842 ? instance . appContext . app . __VUE_I18N_SYMBOL__ !
@@ -839,15 +874,13 @@ function getGlobalComposer(i18n: I18n): Composer {
839874
840875function getComposer (
841876 i18n : I18n ,
842- target : ComponentInternalInstance ,
877+ target : ComponentInternalInstance | GenericComponentInstance ,
843878 useComponent = false
844879) : Composer | null {
845880 let composer : Composer | null = null
846881 const root = target . root
847- let current : ComponentInternalInstance | null = getParentComponentInstance (
848- target ,
849- useComponent
850- )
882+ let current : ComponentInternalInstance | GenericComponentInstance | null =
883+ getParentComponentInstance ( target , useComponent )
851884 while ( current != null ) {
852885 const i18nInternal = i18n as unknown as I18nInternal
853886 if ( i18n . mode === 'composition' ) {
@@ -880,7 +913,7 @@ function getComposer(
880913}
881914
882915function getParentComponentInstance (
883- target : ComponentInternalInstance | null ,
916+ target : ComponentInternalInstance | GenericComponentInstance | null ,
884917 useComponent = false
885918) {
886919 if ( target == null ) {
@@ -894,19 +927,15 @@ function getParentComponentInstance(
894927
895928function setupLifeCycle (
896929 i18n : I18nInternal ,
897- target : ComponentInternalInstance ,
930+ target : ComponentInternalInstance | GenericComponentInstance ,
898931 composer : Composer
899932) : void {
900933 let emitter : VueDevToolsEmitter | null = null
901934
902935 onMounted ( ( ) => {
903936 // inject composer instance to DOM for intlify-devtools
904- if (
905- ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) &&
906- ! __NODE_JS__ &&
907- target . vnode . el
908- ) {
909- target . vnode . el . __VUE_I18N__ = composer
937+ if ( ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) && ! __NODE_JS__ ) {
938+ target . __VUE_I18N__ = composer
910939 emitter = createEmitter < VueDevToolsEmitterEvents > ( )
911940 // eslint-disable-next-line @typescript-eslint/no-explicit-any
912941 const _composer = composer as any
@@ -920,15 +949,10 @@ function setupLifeCycle(
920949 const _composer = composer as any
921950
922951 // remove composer instance from DOM for intlify-devtools
923- if (
924- ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) &&
925- ! __NODE_JS__ &&
926- target . vnode . el &&
927- target . vnode . el . __VUE_I18N__
928- ) {
952+ if ( ( __DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__ ) && ! __NODE_JS__ ) {
929953 emitter && emitter . off ( '*' , addTimelineEvent )
930954 _composer [ DisableEmitter ] && _composer [ DisableEmitter ] ( )
931- delete target . vnode . el . __VUE_I18N__
955+ delete target . __VUE_I18N__
932956 }
933957 i18n . __deleteInstance ( target )
934958
0 commit comments