Skip to content

Commit

Permalink
fix(search-source): fix language reload on search source (#1189)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeLafreniere18 authored and cbourget committed Mar 21, 2023
1 parent 692a95e commit 750d461
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/lib/language/shared/language.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject } from 'rxjs';
import { BehaviorSubject, combineLatest } from 'rxjs';

@Injectable({
providedIn: 'root'
Expand All @@ -21,8 +21,8 @@ export class LanguageService {

public setLanguage(language: string) {
this.language = language.match(/en|fr/) ? language : 'en';
this.language$.next(this.language);
this.translate.use(this.language);
this.translate.reloadLang(this.language);
combineLatest([this.translate.use(this.language), this.translate.reloadLang(this.language)]).subscribe(() => {
this.language$.next(this.language);
});
}
}
8 changes: 4 additions & 4 deletions packages/geo/src/lib/search/shared/sources/coordinates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export class CoordinatesReverseSearchSource extends SearchSource
@Inject('options') options: SearchSourceOptions,
private languageService: LanguageService,
storageService: StorageService,
@Inject('projections') projections: Projection[],
@Inject('projections') projections: Projection[]
) {
super(options, storageService);
this.projections = projections;
this.languageService.translate
.get(this.options.title)
.subscribe(title => this.title$.next(title));
this.languageService.language$.subscribe(() => {
this.title$.next(this.languageService.translate.instant(this.options.title));
});
}

getId(): string {
Expand Down
14 changes: 7 additions & 7 deletions packages/geo/src/lib/search/shared/sources/icherche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ export class IChercheSearchSource extends SearchSource implements TextSearch {
) {
super(options, storageService);

this.languageService.translate
.get(this.options.title)
.subscribe((title) => this.title$.next(title));

const authService = injector.get(AuthService);
if (this.settings.length) {
if (!authService) {
Expand All @@ -99,6 +95,10 @@ export class IChercheSearchSource extends SearchSource implements TextSearch {
});
}
}

this.languageService.language$.subscribe(() => {
this.title$.next(this.languageService.translate.instant(this.options.title));
});
}

getId(): string {
Expand Down Expand Up @@ -653,9 +653,9 @@ export class IChercheReverseSearchSource extends SearchSource
) {
super(options, storageService);

this.languageService.translate
.get(this.options.title)
.subscribe((title) => this.title$.next(title));
this.languageService.language$.subscribe(() => {
this.title$.next(this.languageService.translate.instant(this.options.title));
});

const authService = injector.get(AuthService);
if (this.settings.length) {
Expand Down
6 changes: 3 additions & 3 deletions packages/geo/src/lib/search/shared/sources/ilayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export class ILayerSearchSource extends SearchSource implements TextSearch {
private formatter: ILayerSearchResultFormatter
) {
super(options, storageService);
this.languageService.translate
.get(this.options.title)
.subscribe(title => this.title$.next(title));
this.languageService.language$.subscribe(() => {
this.title$.next(this.languageService.translate.instant(this.options.title));
});
}

getId(): string {
Expand Down

0 comments on commit 750d461

Please sign in to comment.