@@ -11,7 +11,7 @@ export class I18nextAdapter implements I18n<i18next> {
1111
1212 @observable private _loading = true ;
1313
14- @observable private _changeLanguage = false ;
14+ @observable private _language : I18nLanguages = I18nLanguages . en ;
1515
1616 constructor ( ) {
1717 makeAutoObservable ( this ) ;
@@ -22,8 +22,10 @@ export class I18nextAdapter implements I18n<i18next> {
2222 this . _loading = value ;
2323 } ;
2424
25- @action private _setChangeLanguage = ( value : boolean ) : void => {
26- this . _changeLanguage = value ;
25+ @action private _setLanguage = async ( value : I18nLanguages ) : Promise < void > => {
26+ await this . _instance . changeLanguage ( value ) ;
27+ await this . _instance . reloadResources ( ) ;
28+ this . _language = value ;
2729 } ;
2830
2931 private initialize = async ( ) : Promise < void > => {
@@ -84,29 +86,23 @@ export class I18nextAdapter implements I18n<i18next> {
8486 return this . _loading ;
8587 } ;
8688
87- @computed isChanged = ( ) : boolean => {
88- return this . _changeLanguage ;
89- } ;
90-
9189 getInstance = ( ) : i18next => {
9290 return this . _instance ;
9391 } ;
9492
95- getLanguage = ( ) : I18nLanguages => {
96- return this . _instance . language as I18nLanguages ;
93+ @ computed getLanguage = ( ) : I18nLanguages => {
94+ return this . _language || ( this . _instance . language as I18nLanguages ) ;
9795 } ;
9896
9997 changeLanguage = async ( language : I18nLanguages ) : Promise < boolean > => {
10098 try {
101- this . _setChangeLanguage ( true ) ;
102- await this . _instance . changeLanguage ( language ) ;
103- await this . _instance . reloadResources ( ) ;
99+ await this . _setLanguage ( language ) ;
104100
105101 return true ;
106102 } catch ( error ) {
103+ await this . _setLanguage ( I18nLanguages . en ) ;
104+
107105 return false ;
108- } finally {
109- this . _setChangeLanguage ( false ) ;
110106 }
111107 } ;
112108}
0 commit comments