add label paginator

This commit is contained in:
_Bastler
2021-11-05 18:40:18 +01:00
parent 925a03fd46
commit 112edb2889
2 changed files with 51 additions and 4 deletions
+41 -1
View File
@@ -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 + "" ]);
}
}