From 4724fdaaced662bec7794d5c117bf2b4a4441044 Mon Sep 17 00:00:00 2001 From: Marcel Eisentraut Date: Thu, 6 Jul 2023 13:42:14 +0200 Subject: [PATCH] fix: complete current localization call, when a new language is requested --- src/app/core/utils/translate/icm-translate-loader.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/core/utils/translate/icm-translate-loader.ts b/src/app/core/utils/translate/icm-translate-loader.ts index 7790eecb06..bd07529d1f 100644 --- a/src/app/core/utils/translate/icm-translate-loader.ts +++ b/src/app/core/utils/translate/icm-translate-loader.ts @@ -4,8 +4,8 @@ import { Actions, ofType } from '@ngrx/effects'; import { routerNavigationAction } from '@ngrx/router-store'; import { TranslateLoader } from '@ngx-translate/core'; import { memoize } from 'lodash-es'; -import { combineLatest, defer, from, iif, of } from 'rxjs'; -import { catchError, first, map, shareReplay, switchMap, tap } from 'rxjs/operators'; +import { Subject, combineLatest, defer, from, iif, of } from 'rxjs'; +import { catchError, filter, first, map, shareReplay, switchMap, takeUntil, tap } from 'rxjs/operators'; import { LocalizationsService } from 'ish-core/services/localizations/localizations.service'; import { InjectSingle } from 'ish-core/utils/injection'; @@ -21,6 +21,8 @@ export const LOCAL_TRANSLATIONS = new InjectionToken('transla @Injectable() export class ICMTranslateLoader implements TranslateLoader { + newLanguage$ = new Subject(); + constructor( private actions$: Actions, private transferState: TransferState, @@ -29,6 +31,7 @@ export class ICMTranslateLoader implements TranslateLoader { ) {} getTranslation = memoize(lang => { + this.newLanguage$.next(lang); const SSR_TRANSLATIONS = makeStateKey(`ssrTranslations-${lang}`); const local$ = defer(() => from(this.localTranslations.useFactory(lang)).pipe(catchError(() => of({})))); @@ -46,7 +49,9 @@ export class ICMTranslateLoader implements TranslateLoader { this.transferState.set(SSR_TRANSLATIONS, data); }) ) - ) + ), + // close current localization call when a new language is requested + takeUntil(this.newLanguage$.pipe(filter(newLang => newLang !== lang))) ) ); return combineLatest([local$, server$]).pipe(