Browse Source
Merge pull request #11450 from abpframework/fix/11449
fix: listen to current lang instead of change in document-dir
pull/11451/head
Bunyamin Coskuner
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
12 additions and
11 deletions
-
npm/ng-packs/packages/core/src/lib/services/localization.service.ts
-
npm/ng-packs/packages/theme-shared/src/lib/handlers/document-dir.handler.ts
|
|
|
@ -25,11 +25,18 @@ export class LocalizationService { |
|
|
|
|
|
|
|
/** |
|
|
|
* Returns currently selected language |
|
|
|
* Even though this looks like it's redundant to return the same value as `getLanguage()`, |
|
|
|
* it's actually not. This could be invoked any time, and the latestLang could be different from the |
|
|
|
* sessionState.getLanguage() value. |
|
|
|
*/ |
|
|
|
get currentLang(): string { |
|
|
|
return this.latestLang || this.sessionState.getLanguage(); |
|
|
|
} |
|
|
|
|
|
|
|
get currentLang$(): Observable<string> { |
|
|
|
return this.sessionState.getLanguage$(); |
|
|
|
} |
|
|
|
|
|
|
|
get languageChange$(): Observable<string> { |
|
|
|
return this._languageChange$.asObservable(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,7 +1,7 @@ |
|
|
|
import { getLocaleDirection, LocalizationService } from '@abp/ng.core'; |
|
|
|
import { Injectable, Injector } from '@angular/core'; |
|
|
|
import { BehaviorSubject } from 'rxjs'; |
|
|
|
import { map, startWith } from 'rxjs/operators'; |
|
|
|
import { map } from 'rxjs/operators'; |
|
|
|
import { LocaleDirection } from '../models/common'; |
|
|
|
|
|
|
|
@Injectable() |
|
|
|
@ -14,17 +14,11 @@ export class DocumentDirHandlerService { |
|
|
|
|
|
|
|
private listenToLanguageChanges() { |
|
|
|
const l10n = this.injector.get(LocalizationService); |
|
|
|
|
|
|
|
// will always listen, no need to unsubscribe
|
|
|
|
l10n.languageChange$ |
|
|
|
.pipe( |
|
|
|
startWith(l10n.currentLang), |
|
|
|
map(locale => getLocaleDirection(locale)), |
|
|
|
) |
|
|
|
.subscribe(dir => { |
|
|
|
this.dir.next(dir); |
|
|
|
this.setBodyDir(dir); |
|
|
|
}); |
|
|
|
l10n.currentLang$.pipe(map(locale => getLocaleDirection(locale))).subscribe(dir => { |
|
|
|
this.dir.next(dir); |
|
|
|
this.setBodyDir(dir); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private setBodyDir(dir: LocaleDirection) { |
|
|
|
|