File tree Expand file tree Collapse file tree 4 files changed +37
-1
lines changed Expand file tree Collapse file tree 4 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,7 @@ yarn add vue-i18n@next
212
212
- [x] preserveDirectiveContent
213
213
- [x] warnHtmlInMessage
214
214
- [x] postTranslation
215
+ - [x] componentInstanceCreatedListener
215
216
- [x] t
216
217
- [x] tc
217
218
- [x] te
Original file line number Diff line number Diff line change @@ -58,6 +58,10 @@ export interface Formatter {
58
58
// eslint-disable-next-line @typescript-eslint/no-explicit-any
59
59
interpolate ( message : string , values : any , path : string ) : Array < any > | null
60
60
}
61
+ export type ComponentInstanceCreatedListener = (
62
+ target : VueI18n ,
63
+ global : VueI18n
64
+ ) => void
61
65
62
66
/**
63
67
* VueI18n Options
@@ -85,6 +89,7 @@ export interface VueI18nOptions {
85
89
pluralizationRules ?: PluralizationRules
86
90
postTranslation ?: PostTranslationHandler
87
91
sync ?: boolean
92
+ componentInstanceCreatedListener ?: ComponentInstanceCreatedListener
88
93
}
89
94
90
95
/**
@@ -156,6 +161,7 @@ export interface VueI18n {
156
161
export interface VueI18nInternal {
157
162
__id : number
158
163
__composer : Composer
164
+ __onComponentInstanceCreated ( target : VueI18n ) : void
159
165
}
160
166
161
167
/**
@@ -253,7 +259,7 @@ export function createVueI18n(
253
259
254
260
// defines VueI18n
255
261
const vueI18n = {
256
- /*!
262
+ /**
257
263
* properties
258
264
*/
259
265
@@ -516,6 +522,14 @@ export function createVueI18n(
516
522
__DEV__ &&
517
523
warn ( getWarnMessage ( I18nWarnCodes . NOT_SUPPORTED_GET_CHOICE_INDEX ) )
518
524
return - 1
525
+ } ,
526
+
527
+ // for internal
528
+ __onComponentInstanceCreated ( target : VueI18n ) : void {
529
+ const { componentInstanceCreatedListener } = options
530
+ if ( componentInstanceCreatedListener ) {
531
+ componentInstanceCreatedListener ( target , vueI18n )
532
+ }
519
533
}
520
534
}
521
535
Original file line number Diff line number Diff line change @@ -160,13 +160,15 @@ export function defineMixin(
160
160
}
161
161
optionsI18n . __root = composer
162
162
this . $i18n = createVueI18n ( optionsI18n )
163
+ legacy . __onComponentInstanceCreated ( this . $i18n )
163
164
164
165
i18n . _setLegacy ( instance , this . $i18n )
165
166
} else if ( options . __i18n ) {
166
167
this . $i18n = createVueI18n ( {
167
168
__i18n : options . __i18n ,
168
169
__root : composer
169
170
} )
171
+ legacy . __onComponentInstanceCreated ( this . $i18n )
170
172
171
173
i18n . _setLegacy ( instance , this . $i18n )
172
174
} else {
Original file line number Diff line number Diff line change @@ -176,6 +176,25 @@ test('$i18n', async () => {
176
176
expect ( vm . $i18n . t ( 'hello' ) ) . toEqual ( 'hello!' )
177
177
} )
178
178
179
+ test ( 'VueI18n componentInstanceCreatedListener option' , async ( ) => {
180
+ const componentInstanceCreatedListener = jest . fn ( )
181
+ const i18n = createI18n ( {
182
+ legacy : true ,
183
+ locale : 'en' ,
184
+ componentInstanceCreatedListener
185
+ } )
186
+
187
+ const App = defineComponent ( {
188
+ template : '<br/>' ,
189
+ i18n : {
190
+ locale : 'ja'
191
+ }
192
+ } )
193
+ await mount ( App , i18n )
194
+
195
+ expect ( componentInstanceCreatedListener ) . toHaveBeenCalled ( )
196
+ } )
197
+
179
198
test . skip ( 'beforeDestroy' , async ( ) => {
180
199
const i18n = createI18n ( {
181
200
legacy : true ,
You can’t perform that action at this time.
0 commit comments