Browse Source

fix: listen to current lang instead of change in document-dir

pull/11450/head
bnymncoskuner 5 years ago
parent
commit
0fc0fb8345
  1. 6
      npm/ng-packs/packages/core/src/lib/services/localization.service.ts
  2. 16
      npm/ng-packs/packages/theme-shared/src/lib/handlers/document-dir.handler.ts

6
npm/ng-packs/packages/core/src/lib/services/localization.service.ts

@ -27,7 +27,11 @@ export class LocalizationService {
* Returns currently selected language * Returns currently selected language
*/ */
get currentLang(): string { get currentLang(): string {
return this.latestLang || this.sessionState.getLanguage(); return this.latestLang;
}
get currentLang$(): Observable<string> {
return this.sessionState.getLanguage$();
} }
get languageChange$(): Observable<string> { get languageChange$(): Observable<string> {

16
npm/ng-packs/packages/theme-shared/src/lib/handlers/document-dir.handler.ts

@ -1,7 +1,7 @@
import { getLocaleDirection, LocalizationService } from '@abp/ng.core'; import { getLocaleDirection, LocalizationService } from '@abp/ng.core';
import { Injectable, Injector } from '@angular/core'; import { Injectable, Injector } from '@angular/core';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
import { map, startWith } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { LocaleDirection } from '../models/common'; import { LocaleDirection } from '../models/common';
@Injectable() @Injectable()
@ -14,17 +14,11 @@ export class DocumentDirHandlerService {
private listenToLanguageChanges() { private listenToLanguageChanges() {
const l10n = this.injector.get(LocalizationService); const l10n = this.injector.get(LocalizationService);
// will always listen, no need to unsubscribe // will always listen, no need to unsubscribe
l10n.languageChange$ l10n.currentLang$.pipe(map(locale => getLocaleDirection(locale))).subscribe(dir => {
.pipe( this.dir.next(dir);
startWith(l10n.currentLang), this.setBodyDir(dir);
map(locale => getLocaleDirection(locale)), });
)
.subscribe(dir => {
this.dir.next(dir);
this.setBodyDir(dir);
});
} }
private setBodyDir(dir: LocaleDirection) { private setBodyDir(dir: LocaleDirection) {

Loading…
Cancel
Save