mirror of https://github.com/abpframework/abp.git
committed by
GitHub
58 changed files with 166 additions and 122 deletions
|
After Width: | Height: | Size: 3.1 KiB |
@ -1,8 +1,10 @@ |
|||||
import { NgModule } from '@angular/core'; |
import { NgModule } from '@angular/core'; |
||||
import { LocalizationPipe } from './pipes/localization.pipe'; |
import { LocalizationPipe } from './pipes/localization.pipe'; |
||||
|
import { LazyLocalizationPipe } from './pipes'; |
||||
|
|
||||
@NgModule({ |
@NgModule({ |
||||
exports: [LocalizationPipe], |
imports: [LazyLocalizationPipe], |
||||
|
exports: [LocalizationPipe, LazyLocalizationPipe], |
||||
declarations: [LocalizationPipe], |
declarations: [LocalizationPipe], |
||||
}) |
}) |
||||
export class LocalizationModule {} |
export class LocalizationModule {} |
||||
|
|||||
@ -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<string> { |
||||
|
if (!key) { |
||||
|
return of(''); |
||||
|
} |
||||
|
|
||||
|
const flatParams = params.reduce<string[]>( |
||||
|
(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(), |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -1 +0,0 @@ |
|||||
export * from './lazy-translate.pipe'; |
|
||||
@ -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<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