Skip to content

Commit 8eebc69

Browse files
update: transfer lazy localization from theme basic to core package
1 parent 0f1c326 commit 8eebc69

File tree

7 files changed

+45
-25
lines changed

7 files changed

+45
-25
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { NgModule } from '@angular/core';
22
import { LocalizationPipe } from './pipes/localization.pipe';
3+
import { LazyLocalizationPipe } from './pipes';
34

45
@NgModule({
5-
exports: [LocalizationPipe],
6+
imports: [LazyLocalizationPipe],
7+
exports: [LocalizationPipe, LazyLocalizationPipe],
68
declarations: [LocalizationPipe],
79
})
810
export class LocalizationModule {}

npm/ng-packs/packages/core/src/lib/pipes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './to-injector.pipe';
55
export * from './short-date.pipe';
66
export * from './short-time.pipe';
77
export * from './short-date-time.pipe';
8+
export * from './lazy-localization.pipe';
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { inject, Injectable, Pipe, PipeTransform } from '@angular/core';
2+
import {
3+
Observable,
4+
of,
5+
filter,
6+
take,
7+
switchMap,
8+
map,
9+
startWith,
10+
distinctUntilChanged,
11+
} from 'rxjs';
12+
import { ConfigStateService, LocalizationService } from '../services';
13+
14+
@Injectable()
15+
@Pipe({
16+
name: 'abpLazyLocalization',
17+
})
18+
export class LazyLocalizationPipe implements PipeTransform {
19+
private localizationService = inject(LocalizationService);
20+
private configStateService = inject(ConfigStateService);
21+
22+
transform(key: string, ...params: (string | string[])[]): Observable<string> {
23+
if (!key) {
24+
return of('');
25+
}
26+
27+
const flatParams = params.reduce<string[]>(
28+
(acc, val) => (Array.isArray(val) ? acc.concat(val) : [...acc, val]),
29+
[],
30+
);
31+
32+
return this.configStateService.getAll$().pipe(
33+
filter(config => !!config.localization),
34+
take(1),
35+
switchMap(() => this.localizationService.get(key, ...flatParams)),
36+
map(translation => (translation && translation !== key ? translation : '')),
37+
startWith(''),
38+
distinctUntilChanged(),
39+
);
40+
}
41+
}

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { PageAlertContainerComponent } from './components/page-alert-container/p
1616
import { RoutesComponent } from './components/routes/routes.component';
1717
import { ValidationErrorComponent } from './components/validation-error/validation-error.component';
1818
import { provideThemeBasicConfig } from './providers';
19-
import { LazyTranslatePipe } from './pipes';
2019

2120
export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, EmptyLayoutComponent];
2221

@@ -49,7 +48,6 @@ export const LAYOUTS = [ApplicationLayoutComponent, AccountLayoutComponent, Empt
4948
NgbCollapseModule,
5049
NgbDropdownModule,
5150
NgxValidateCoreModule,
52-
LazyTranslatePipe,
5351
],
5452
})
5553
export class BaseThemeBasicModule {}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export * from './lib/components';
66
export * from './lib/enums';
77
export * from './lib/handlers';
88
export * from './lib/models';
9-
export * from './lib/pipes';
109
export * from './lib/providers';
1110
export * from './lib/theme-basic.module';
1211
export * from './lib/tokens';

0 commit comments

Comments
 (0)