Browse Source
Merge pull request #5609 from abpframework/fix/5229
Fixed the current language problems in Session State
pull/5611/head
Levent Arman Özak
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
13 additions and
14 deletions
-
npm/ng-packs/packages/core/src/lib/services/localization.service.ts
-
npm/ng-packs/packages/core/src/lib/states/config.state.ts
-
npm/ng-packs/packages/core/src/lib/tests/config.state.spec.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<SetLanguage> { |
|
|
|
return this.actions.pipe(ofActionSuccessful(SetLanguage)); |
|
|
|
return this.actions.pipe( |
|
|
|
ofActionSuccessful(SetLanguage), |
|
|
|
filter((action: SetLanguage) => action.dispatchAppConfiguration !== false), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
constructor( |
|
|
|
|
|
|
|
@ -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)); |
|
|
|
|
|
|
|
@ -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(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|