@@ -103,7 +103,7 @@ export const i18nVue: Plugin = {
103
103
install ( app , options : PluginOptionsInterface = { } ) {
104
104
options = { ...DEFAULT_PLUGIN_OPTIONS , ...options }
105
105
106
- const i18n = options . shared ? I18n . getSharedInstance ( options ) : new I18n ( options )
106
+ const i18n = options . shared ? I18n . getSharedInstance ( options , true ) : new I18n ( options )
107
107
108
108
app . config . globalProperties . $t = ( key : string , replacements : ReplacementsInterface ) => i18n . trans ( key , replacements )
109
109
app . config . globalProperties . $tChoice = ( key : string , number : number , replacements : ReplacementsInterface ) =>
@@ -134,18 +134,29 @@ export class I18n {
134
134
constructor ( options : OptionsInterface = { } ) {
135
135
this . options = { ...DEFAULT_OPTIONS , ...options }
136
136
137
- this [ isServer ? 'loadLanguage' : 'loadLanguageAsync' ] ( this . getActiveLanguage ( ) )
137
+ this . load ( ) ;
138
138
}
139
139
140
140
/**
141
141
* Sets options on the instance, preserving any values not present in new options
142
142
*/
143
- setOptions ( options : OptionsInterface = { } ) : I18n {
143
+ setOptions ( options : OptionsInterface = { } , forceLoad : boolean = false ) : I18n {
144
144
this . options = { ...this . options , ...options }
145
145
146
+ if ( forceLoad ) {
147
+ this . load ( ) ;
148
+ }
149
+
146
150
return this
147
151
}
148
152
153
+ /**
154
+ * Loads the language.
155
+ */
156
+ load ( ) : void {
157
+ this [ isServer ? 'loadLanguage' : 'loadLanguageAsync' ] ( this . getActiveLanguage ( ) )
158
+ }
159
+
149
160
/**
150
161
* Loads the language async.
151
162
*/
@@ -370,7 +381,7 @@ export class I18n {
370
381
/**
371
382
* Gets the shared I18n instance, instantiating it if not yet created
372
383
*/
373
- static getSharedInstance ( options ?: OptionsInterface ) : I18n {
374
- return sharedInstance ?. setOptions ( options ) || ( sharedInstance = new I18n ( options ) )
384
+ static getSharedInstance ( options ?: OptionsInterface , forceLoad : boolean = false ) : I18n {
385
+ return sharedInstance ?. setOptions ( options , forceLoad ) || ( sharedInstance = new I18n ( options ) )
375
386
}
376
387
}
0 commit comments