From 8eebc691c00f7f01913d56e556df25a2b7b8be47 Mon Sep 17 00:00:00 2001 From: sumeyye Date: Wed, 30 Apr 2025 16:14:11 +0300 Subject: [PATCH] update: transfer lazy localization from theme basic to core package --- .../core/src/lib/localization.module.ts | 4 +- .../packages/core/src/lib/pipes/index.ts | 1 + .../src/lib/pipes/lazy-localization.pipe.ts | 41 +++++++++++++++++++ .../theme-basic/src/lib/pipes/index.ts | 1 - .../src/lib/pipes/lazy-translate.pipe.ts | 20 --------- .../theme-basic/src/lib/theme-basic.module.ts | 2 - .../packages/theme-basic/src/public-api.ts | 1 - 7 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 npm/ng-packs/packages/core/src/lib/pipes/lazy-localization.pipe.ts delete mode 100644 npm/ng-packs/packages/theme-basic/src/lib/pipes/index.ts delete mode 100644 npm/ng-packs/packages/theme-basic/src/lib/pipes/lazy-translate.pipe.ts diff --git a/npm/ng-packs/packages/core/src/lib/localization.module.ts b/npm/ng-packs/packages/core/src/lib/localization.module.ts index 315f27b1ff..9335e944fa 100644 --- a/npm/ng-packs/packages/core/src/lib/localization.module.ts +++ b/npm/ng-packs/packages/core/src/lib/localization.module.ts @@ -1,8 +1,10 @@ import { NgModule } from '@angular/core'; import { LocalizationPipe } from './pipes/localization.pipe'; +import { LazyLocalizationPipe } from './pipes'; @NgModule({ - exports: [LocalizationPipe], + imports: [LazyLocalizationPipe], + exports: [LocalizationPipe, LazyLocalizationPipe], declarations: [LocalizationPipe], }) export class LocalizationModule {} diff --git a/npm/ng-packs/packages/core/src/lib/pipes/index.ts b/npm/ng-packs/packages/core/src/lib/pipes/index.ts index 1a981ca041..f2d810dda5 100644 --- a/npm/ng-packs/packages/core/src/lib/pipes/index.ts +++ b/npm/ng-packs/packages/core/src/lib/pipes/index.ts @@ -5,3 +5,4 @@ export * from './to-injector.pipe'; export * from './short-date.pipe'; export * from './short-time.pipe'; export * from './short-date-time.pipe'; +export * from './lazy-localization.pipe'; diff --git a/npm/ng-packs/packages/core/src/lib/pipes/lazy-localization.pipe.ts b/npm/ng-packs/packages/core/src/lib/pipes/lazy-localization.pipe.ts new file mode 100644 index 0000000000..b715b25ad8 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/pipes/lazy-localization.pipe.ts @@ -0,0 +1,41 @@ +import { inject, Injectable, Pipe, PipeTransform } from '@angular/core'; +import { + Observable, + of, + filter, + take, + switchMap, + map, + startWith, + distinctUntilChanged, +} from 'rxjs'; +import { ConfigStateService, LocalizationService } from '../services'; + +@Injectable() +@Pipe({ + name: 'abpLazyLocalization', +}) +export class LazyLocalizationPipe implements PipeTransform { + private localizationService = inject(LocalizationService); + private configStateService = inject(ConfigStateService); + + transform(key: string, ...params: (string | string[])[]): Observable { + if (!key) { + return of(''); + } + + const flatParams = params.reduce( + (acc, val) => (Array.isArray(val) ? acc.concat(val) : [...acc, val]), + [], + ); + + return this.configStateService.getAll$().pipe( + filter(config => !!config.localization), + take(1), + switchMap(() => this.localizationService.get(key, ...flatParams)), + map(translation => (translation && translation !== key ? translation : '')), + startWith(''), + distinctUntilChanged(), + ); + } +} diff --git a/npm/ng-packs/packages/theme-basic/src/lib/pipes/index.ts b/npm/ng-packs/packages/theme-basic/src/lib/pipes/index.ts deleted file mode 100644 index 0bde64d742..0000000000 --- a/npm/ng-packs/packages/theme-basic/src/lib/pipes/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './lazy-translate.pipe'; diff --git a/npm/ng-packs/packages/theme-basic/src/lib/pipes/lazy-translate.pipe.ts b/npm/ng-packs/packages/theme-basic/src/lib/pipes/lazy-translate.pipe.ts deleted file mode 100644 index d7b36a0c32..0000000000 --- a/npm/ng-packs/packages/theme-basic/src/lib/pipes/lazy-translate.pipe.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { LocalizationService, ConfigStateService } from '@abp/ng.core'; -import { inject, Pipe, PipeTransform } from '@angular/core'; -import { Observable, filter, take, switchMap, shareReplay } from 'rxjs'; - -@Pipe({ - name: 'abpLazyTranslate', -}) -export class LazyTranslatePipe implements PipeTransform { - private localizationService = inject(LocalizationService); - private configStateService = inject(ConfigStateService); - - transform(key: string): Observable { - return this.configStateService.getAll$().pipe( - filter(config => !!config.localization), - take(1), - switchMap(() => this.localizationService.get(key)), - shareReplay({ bufferSize: 1, refCount: true }), - ); - } -} diff --git a/npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts b/npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts index d68d112ac5..d959509dfd 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts @@ -16,7 +16,6 @@ import { PageAlertContainerComponent } from './components/page-alert-container/p import { RoutesComponent } from './components/routes/routes.component'; import { ValidationErrorComponent } from './components/validation-error/validation-error.component'; import { provideThemeBasicConfig } from './providers'; -import { LazyTranslatePipe } from './pipes'; export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, EmptyLayoutComponent]; @@ -49,7 +48,6 @@ export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, Empt NgbCollapseModule, NgbDropdownModule, NgxValidateCoreModule, - LazyTranslatePipe, ], }) export class BaseThemeBasicModule {} diff --git a/npm/ng-packs/packages/theme-basic/src/public-api.ts b/npm/ng-packs/packages/theme-basic/src/public-api.ts index ec57cc892e..5c607ca06d 100644 --- a/npm/ng-packs/packages/theme-basic/src/public-api.ts +++ b/npm/ng-packs/packages/theme-basic/src/public-api.ts @@ -6,7 +6,6 @@ export * from './lib/components'; export * from './lib/enums'; export * from './lib/handlers'; export * from './lib/models'; -export * from './lib/pipes'; export * from './lib/providers'; export * from './lib/theme-basic.module'; export * from './lib/tokens';