add label paginator
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { MatPaginatorIntl } from '@angular/material/paginator';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -96,10 +98,48 @@ export class I18nService {
|
||||
insertArguments(label: string, args: string[]) {
|
||||
if (args) {
|
||||
for (let index in args) {
|
||||
label = label.replace(`{${index}}`, this.get(args[ index ], []));
|
||||
label = label.replace(`{${index}}`, this.get(args[ index ], null));
|
||||
}
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class I18nPaginatorIntl implements MatPaginatorIntl {
|
||||
|
||||
changes = new Subject<void>();
|
||||
|
||||
i18n: I18nService;
|
||||
|
||||
itemsPerPageLabel: string;
|
||||
nextPageLabel: string;
|
||||
previousPageLabel: string;
|
||||
firstPageLabel: string;
|
||||
lastPageLabel: string;
|
||||
|
||||
|
||||
injectI18n(i18n: I18nService) {
|
||||
this.i18n = i18n;
|
||||
|
||||
this.firstPageLabel = this.i18n.get('paginator.firstPage', []);
|
||||
this.itemsPerPageLabel = this.i18n.get('paginator.itemsPerPage', []);
|
||||
this.lastPageLabel = this.i18n.get('paginator.lastPage', []);
|
||||
|
||||
this.nextPageLabel = this.i18n.get('paginator.nextPage', []);
|
||||
this.previousPageLabel = this.i18n.get('paginator.previousPage', []);
|
||||
|
||||
}
|
||||
|
||||
|
||||
getRangeLabel(page: number, pageSize: number, length: number): string {
|
||||
if (length === 0) {
|
||||
return this.i18n.get('paginator.empty', []);
|
||||
}
|
||||
|
||||
const amountPages = Math.ceil(length / pageSize);
|
||||
return this.i18n.get('paginator.range', [ page + 1 + "", amountPages + "" ]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user