|
| 1 | +import {Component, Injectable, NgModule} from '@angular/core'; |
| 2 | +import {MatPaginatorIntl, MatPaginatorModule} from '@angular/material/paginator'; |
| 3 | +import {Subject} from 'rxjs'; |
| 4 | + |
| 5 | +@Injectable() |
| 6 | +export class MyCustomPaginatorIntl implements MatPaginatorIntl { |
| 7 | + changes = new Subject<void>(); |
| 8 | + |
| 9 | + // For internationalization, the `$localize` function from |
| 10 | + // the `@angular/localize` package can be used. |
| 11 | + firstPageLabel = $localize`First page`; |
| 12 | + itemsPerPageLabel = $localize`Items per page:`; |
| 13 | + lastPageLabel = $localize`Last page`; |
| 14 | + |
| 15 | + // You can set labels to an arbitrary string too, or dynamically compute |
| 16 | + // it through other third-party internationalization libraries. |
| 17 | + nextPageLabel = 'Next page'; |
| 18 | + previousPageLabel = 'Previous page'; |
| 19 | + |
| 20 | + getRangeLabel(page: number, pageSize: number, length: number): string { |
| 21 | + if (length === 0) { |
| 22 | + return $localize`Page 1 of 1`; |
| 23 | + } |
| 24 | + const amountPages = Math.ceil(length / pageSize); |
| 25 | + return $localize`Page ${page + 1} of ${amountPages}`; |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * @title Paginator internationalization |
| 31 | + */ |
| 32 | +@Component({ |
| 33 | + selector: 'paginator-intl-example', |
| 34 | + templateUrl: 'paginator-intl-example.html', |
| 35 | +}) |
| 36 | +export class PaginatorIntlExample {} |
| 37 | + |
| 38 | +@NgModule({ |
| 39 | + imports: [MatPaginatorModule], |
| 40 | + declarations: [PaginatorIntlExample], |
| 41 | + providers: [ |
| 42 | + {provide: MatPaginatorIntl, useClass: MyCustomPaginatorIntl} |
| 43 | + ] |
| 44 | +}) |
| 45 | +export class PaginatorIntlExampleModule {} |
0 commit comments