Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions npm/ng-packs/packages/core/src/lib/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ABP } from './models/common';
import './utils/date-extensions';
import { provideAbpCoreChild, provideAbpCore, withOptions } from './providers';
import {
AsyncLocalizationPipe,
LazyLocalizationPipe,
UtcToLocalPipe,
SafeHtmlPipe,
Expand Down Expand Up @@ -60,6 +61,7 @@ const CORE_PIPES = [
ShortDatePipe,
ToInjectorPipe,
UtcToLocalPipe,
AsyncLocalizationPipe,
LazyLocalizationPipe,
];

Expand Down
10 changes: 5 additions & 5 deletions npm/ng-packs/packages/core/src/lib/localization.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { NgModule } from '@angular/core';
import { LocalizationPipe } from './pipes/localization.pipe';
import { LazyLocalizationPipe } from './pipes';
import { AsyncLocalizationPipe, LazyLocalizationPipe } from './pipes';

/**
* @deprecated Use `LocalizationPipe` and `LazyLocalizationPipe` directly as a standalone pipe.
* This module is no longer necessary for using the `LocalizationPipe` and `LazyLocalizationPipe` pipes.
* @deprecated Use `LocalizationPipe`, `AsyncLocalizationPipe` and `LazyLocalizationPipe` directly as a standalone pipe.
* This module is no longer necessary for using the `LocalizationPipe`, `AsyncLocalizationPipe` and `LazyLocalizationPipe` pipes.
*/

@NgModule({
exports: [LocalizationPipe, LazyLocalizationPipe],
imports: [LocalizationPipe, LazyLocalizationPipe],
exports: [LocalizationPipe, AsyncLocalizationPipe, LazyLocalizationPipe],
imports: [LocalizationPipe, AsyncLocalizationPipe, LazyLocalizationPipe],
})
export class LocalizationModule {}
Original file line number Diff line number Diff line change
@@ -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: 'abpAsyncLocalization',
})
export class AsyncLocalizationPipe 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 change: 1 addition & 0 deletions npm/ng-packs/packages/core/src/lib/pipes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export * from './short-date.pipe';
export * from './short-time.pipe';
export * from './short-date-time.pipe';
export * from './utc-to-local.pipe';
export * from './async-localization.pipe';
export * from './lazy-localization.pipe';
export * from './html-encode.pipe';
43 changes: 7 additions & 36 deletions npm/ng-packs/packages/core/src/lib/pipes/lazy-localization.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,12 @@
import { inject, Injectable, Pipe, PipeTransform } from '@angular/core';
import {
Observable,
of,
filter,
take,
switchMap,
map,
startWith,
distinctUntilChanged,
} from 'rxjs';
import { ConfigStateService, LocalizationService } from '../services';
import { Injectable, Pipe } from '@angular/core';
import { AsyncLocalizationPipe } from './async-localization.pipe';

/**
* @deprecated Use `AsyncLocalizationPipe` instead. This pipe will be removed in a future version.
* LazyLocalizationPipe has been renamed to AsyncLocalizationPipe to better express its async nature.
*/
@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(),
);
}
}
export class LazyLocalizationPipe extends AsyncLocalizationPipe {}
Loading