Skip to content

Commit

Permalink
Merge pull request #11450 from abpframework/fix/11449
Browse files Browse the repository at this point in the history
fix: listen to current lang instead of change in document-dir
  • Loading branch information
bnymncoskuner authored Jan 25, 2022
2 parents 8fcfa3b + 80fb1ab commit fd70a2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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) {
Expand Down

0 comments on commit fd70a2f

Please sign in to comment.