Browse Source

add: `LazyTranslatePipe` for theme basic

pull/22629/head
sumeyye 1 year ago
parent
commit
51c85c9867
  1. 1
      npm/ng-packs/packages/theme-basic/src/lib/pipes/index.ts
  2. 20
      npm/ng-packs/packages/theme-basic/src/lib/pipes/lazy-translate.pipe.ts
  3. 2
      npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts
  4. 1
      npm/ng-packs/packages/theme-basic/src/public-api.ts

1
npm/ng-packs/packages/theme-basic/src/lib/pipes/index.ts

@ -0,0 +1 @@
export * from './lazy-translate.pipe';

20
npm/ng-packs/packages/theme-basic/src/lib/pipes/lazy-translate.pipe.ts

@ -0,0 +1,20 @@
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<string> {
return this.configStateService.getAll$().pipe(
filter(config => !!config.localization),
take(1),
switchMap(() => this.localizationService.get(key)),
shareReplay({ bufferSize: 1, refCount: true }),
);
}
}

2
npm/ng-packs/packages/theme-basic/src/lib/theme-basic.module.ts

@ -16,6 +16,7 @@ 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];
@ -48,6 +49,7 @@ export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, Empt
NgbCollapseModule,
NgbDropdownModule,
NgxValidateCoreModule,
LazyTranslatePipe,
],
})
export class BaseThemeBasicModule {}

1
npm/ng-packs/packages/theme-basic/src/public-api.ts

@ -6,6 +6,7 @@ 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';

Loading…
Cancel
Save