diff --git a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts index dd64bd27eca..5cdbe3c2911 100644 --- a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts @@ -2,7 +2,7 @@ import { Injectable, Injector, NgZone, Optional, SkipSelf } from '@angular/core' import { ActivatedRouteSnapshot, Router } from '@angular/router'; import { Actions, ofActionSuccessful, Store } from '@ngxs/store'; import { noop, Observable } from 'rxjs'; -import { map } from 'rxjs/operators'; +import { filter, map } from 'rxjs/operators'; import { SetLanguage } from '../actions/session.actions'; import { Config } from '../models/config'; import { ConfigState } from '../states/config.state'; @@ -22,7 +22,10 @@ export class LocalizationService { } get languageChange(): Observable { - return this.actions.pipe(ofActionSuccessful(SetLanguage)); + return this.actions.pipe( + ofActionSuccessful(SetLanguage), + filter((action: SetLanguage) => action.dispatchAppConfiguration !== false), + ); } constructor( diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index 86399814566..4e686dbe622 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -218,20 +218,17 @@ export class ConfigState { }), ), switchMap(configuration => { - let defaultLang: string = - configuration.setting.values['Abp.Localization.DefaultLanguage']; + let lang = configuration.localization.currentCulture.cultureName; - if (defaultLang.includes(';')) { - defaultLang = defaultLang.split(';')[0]; + if (lang.includes(';')) { + lang = lang.split(';')[0]; } - document.documentElement.setAttribute( - 'lang', - configuration.localization.currentCulture.cultureName, - ); + document.documentElement.setAttribute('lang', lang); + return this.store.selectSnapshot(SessionState.getLanguage) ? of(null) - : dispatch(new SetLanguage(defaultLang, false)); + : dispatch(new SetLanguage(lang, false)); }), catchError((err: HttpErrorResponse) => { dispatch(new RestOccurError(err)); diff --git a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts index f9a68e5fd63..e641cc22416 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts @@ -249,8 +249,7 @@ describe('ConfigState', () => { let dispatchArg; const configuration = { - setting: { values: { 'Abp.Localization.DefaultLanguage': 'tr;TR' } }, - localization: { currentCulture: {} }, + localization: { currentCulture: { cultureName: 'en;EN' } }, }; const res$ = new ReplaySubject(1); @@ -269,7 +268,7 @@ describe('ConfigState', () => { timer(0).subscribe(() => { expect(patchStateArg).toEqual(configuration); expect(dispatchArg instanceof SetLanguage).toBeTruthy(); - expect(dispatchArg).toEqual({ payload: 'tr', dispatchAppConfiguration: false }); + expect(dispatchArg).toEqual({ payload: 'en', dispatchAppConfiguration: false }); done(); }); });