@@ -103,7 +103,7 @@ export const i18nVue: Plugin = {
103103 install ( app , options : PluginOptionsInterface = { } ) {
104104 options = { ...DEFAULT_PLUGIN_OPTIONS , ...options }
105105
106- const i18n = options . shared ? I18n . getSharedInstance ( options ) : new I18n ( options )
106+ const i18n = options . shared ? I18n . getSharedInstance ( options , true ) : new I18n ( options )
107107
108108 app . config . globalProperties . $t = ( key : string , replacements : ReplacementsInterface ) => i18n . trans ( key , replacements )
109109 app . config . globalProperties . $tChoice = ( key : string , number : number , replacements : ReplacementsInterface ) =>
@@ -134,18 +134,29 @@ export class I18n {
134134 constructor ( options : OptionsInterface = { } ) {
135135 this . options = { ...DEFAULT_OPTIONS , ...options }
136136
137- this [ isServer ? 'loadLanguage' : 'loadLanguageAsync' ] ( this . getActiveLanguage ( ) )
137+ this . load ( ) ;
138138 }
139139
140140 /**
141141 * Sets options on the instance, preserving any values not present in new options
142142 */
143- setOptions ( options : OptionsInterface = { } ) : I18n {
143+ setOptions ( options : OptionsInterface = { } , forceLoad : boolean = false ) : I18n {
144144 this . options = { ...this . options , ...options }
145145
146+ if ( forceLoad ) {
147+ this . load ( ) ;
148+ }
149+
146150 return this
147151 }
148152
153+ /**
154+ * Loads the language.
155+ */
156+ load ( ) : void {
157+ this [ isServer ? 'loadLanguage' : 'loadLanguageAsync' ] ( this . getActiveLanguage ( ) )
158+ }
159+
149160 /**
150161 * Loads the language async.
151162 */
@@ -370,7 +381,7 @@ export class I18n {
370381 /**
371382 * Gets the shared I18n instance, instantiating it if not yet created
372383 */
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 ) )
375386 }
376387}
0 commit comments