Skip to content

Commit

Permalink
feat(transloco-locale): expose default transformers (#435) (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
leptoquark1 authored Apr 28, 2023
1 parent 04a5cb5 commit 6b8a3f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docs/docs/plugins/locale.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,28 @@ In some cases you might want to customize the localization transformation, to ac
There are two types of transformers for date and number:

```ts title="custom-transformer.ts"
export class CustomDateTransformer implements TranslocoDateTransformer {
import { DefaultDateTransformer, DefaultNumberTransformer } from '@ngneat/transloco-locale';

export class CustomDateTransformer extends DefaultDateTransformer {
public transform(date: Date, locale: Locale, options: DateFormatOptions): string {
return ...

// Fallback to default transformer
return super.transform(date, locale, options);
}
}

export class CustomNumberTransformer implements TranslocoNumberTransformer {
export class CustomNumberTransformer extends DefaultNumberTransformer {
public transform(
value: number | string,
type: NumberTypes,
locale: string,
options: Intl.NumberFormatOptions
): string {
return ...

// Fallback to default transformer
return super.transform(value, type, locale, options);
}
}

Expand Down
2 changes: 2 additions & 0 deletions libs/transloco-locale/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export {
TRANSLOCO_NUMBER_TRANSFORMER,
TranslocoDateTransformer,
TranslocoNumberTransformer,
DefaultDateTransformer,
DefaultNumberTransformer,
} from './lib/transloco-locale.transformers';
export * from './lib/transloco-locale.types';
export * from './lib/pipes';

0 comments on commit 6b8a3f6

Please sign in to comment.