@@ -35,6 +35,7 @@ declare module '@vue/runtime-core' {
35
35
// eslint-disable-next-line
36
36
interface App < HostElement = any > {
37
37
__VUE_I18N__ ?: I18n & I18nInternal
38
+ __VUE_I18N_SYMBOL__ ?: InjectionKey < I18n >
38
39
}
39
40
}
40
41
@@ -145,12 +146,6 @@ export interface ComposerAdditionalOptions {
145
146
useScope ?: I18nScope
146
147
}
147
148
148
- /**
149
- * I18n instance injectin key
150
- * @internal
151
- */
152
- export const I18nSymbol : InjectionKey < I18n > = Symbol . for ( 'vue-i18n' )
153
-
154
149
/**
155
150
* I18n factory function
156
151
*
@@ -250,6 +245,7 @@ export function createI18n<
250
245
const __global = __legacyMode
251
246
? createVueI18n ( options )
252
247
: createComposer ( options )
248
+ const symbol : InjectionKey < I18n > = Symbol ( __DEV__ ? 'vue-i18n' : '' )
253
249
254
250
const i18n = {
255
251
// mode
@@ -261,6 +257,7 @@ export function createI18n<
261
257
if ( __DEV__ || __FEATURE_PROD_DEVTOOLS__ ) {
262
258
app . __VUE_I18N__ = i18n as I18n & I18nInternal
263
259
}
260
+ app . __VUE_I18N_SYMBOL__ = symbol
264
261
apply < Messages , DateTimeFormats , NumberFormats > ( app , i18n , ...options )
265
262
if ( __legacyMode ) {
266
263
app . mixin (
@@ -384,7 +381,13 @@ export function useI18n<
384
381
Options [ 'datetimeFormats' ] ,
385
382
Options [ 'numberFormats' ]
386
383
> {
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 <
388
391
Messages ,
389
392
DateTimeFormats ,
390
393
NumberFormats
@@ -406,12 +409,6 @@ export function useI18n<
406
409
return global
407
410
}
408
411
409
- const instance = getCurrentInstance ( )
410
- /* istanbul ignore if */
411
- if ( instance == null ) {
412
- throw createI18nError ( I18nErrorCodes . UNEXPECTED_ERROR )
413
- }
414
-
415
412
if ( scope === 'parent' ) {
416
413
let composer = getComposer ( i18n , instance )
417
414
if ( composer == null ) {
0 commit comments