mirror of https://github.com/abpframework/abp.git
committed by
GitHub
6 changed files with 34 additions and 14 deletions
@ -0,0 +1 @@ |
|||||
|
export * from './lazy-translate.pipe'; |
||||
@ -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 }), |
||||
|
); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue