@@ -35,6 +35,7 @@ declare module '@vue/runtime-core' {
3535 // eslint-disable-next-line
3636 interface App < HostElement = any > {
3737 __VUE_I18N__ ?: I18n & I18nInternal
38+ __VUE_I18N_SYMBOL__ ?: InjectionKey < I18n >
3839 }
3940}
4041
@@ -145,12 +146,6 @@ export interface ComposerAdditionalOptions {
145146 useScope ?: I18nScope
146147}
147148
148- /**
149- * I18n instance injectin key
150- * @internal
151- */
152- export const I18nSymbol : InjectionKey < I18n > = Symbol . for ( 'vue-i18n' )
153-
154149/**
155150 * I18n factory function
156151 *
@@ -250,6 +245,7 @@ export function createI18n<
250245 const __global = __legacyMode
251246 ? createVueI18n ( options )
252247 : createComposer ( options )
248+ const symbol : InjectionKey < I18n > = Symbol ( __DEV__ ? 'vue-i18n' : '' )
253249
254250 const i18n = {
255251 // mode
@@ -261,6 +257,7 @@ export function createI18n<
261257 if ( __DEV__ || __FEATURE_PROD_DEVTOOLS__ ) {
262258 app . __VUE_I18N__ = i18n as I18n & I18nInternal
263259 }
260+ app . __VUE_I18N_SYMBOL__ = symbol
264261 apply < Messages , DateTimeFormats , NumberFormats > ( app , i18n , ...options )
265262 if ( __legacyMode ) {
266263 app . mixin (
@@ -384,7 +381,13 @@ export function useI18n<
384381 Options [ 'datetimeFormats' ] ,
385382 Options [ 'numberFormats' ]
386383> {
387- const i18n = inject ( I18nSymbol ) as I18n <
384+ const instance = getCurrentInstance ( )
385+ /* istanbul ignore if */
386+ if ( instance == null || ! instance . appContext . app . __VUE_I18N_SYMBOL__ ) {
387+ throw createI18nError ( I18nErrorCodes . UNEXPECTED_ERROR )
388+ }
389+
390+ const i18n = inject ( instance . appContext . app . __VUE_I18N_SYMBOL__ ) as I18n <
388391 Messages ,
389392 DateTimeFormats ,
390393 NumberFormats
@@ -406,12 +409,6 @@ export function useI18n<
406409 return global
407410 }
408411
409- const instance = getCurrentInstance ( )
410- /* istanbul ignore if */
411- if ( instance == null ) {
412- throw createI18nError ( I18nErrorCodes . UNEXPECTED_ERROR )
413- }
414-
415412 if ( scope === 'parent' ) {
416413 let composer = getComposer ( i18n , instance )
417414 if ( composer == null ) {
0 commit comments