add label paginator
This commit is contained in:
parent
925a03fd46
commit
112edb2889
@ -55,13 +55,13 @@ import { BorrowProvingComponent, BorrowProvingResultDialog } from './pages/borro
|
||||
import { DividerComponent } from './ui/divider/divider.component';
|
||||
import { DividertestComponent } from './pages/dividertest/dividertest.component';
|
||||
|
||||
|
||||
import { I18nService } from './services/i18n.service';
|
||||
import { I18nService, I18nPaginatorIntl } from './services/i18n.service';
|
||||
import { MinetestAccountsComponent } from './pages/minetest/accounts/accounts.component';
|
||||
import { BorrowComponent } from './pages/borrow/borrow.component';
|
||||
import { DurationpickerComponent } from './ui/durationpicker/durationpicker.component';
|
||||
import { InviteCodeComponent } from './pages/invites/code/code.component';
|
||||
import { InviteEditComponent } from './pages/invites/edit/invite.edit';
|
||||
import { MatPaginatorIntl } from '@angular/material/paginator';
|
||||
|
||||
|
||||
export function init_app(i18n: I18nService) {
|
||||
@ -134,7 +134,14 @@ export class XhrInterceptor implements HttpInterceptor {
|
||||
QrCodeModule,
|
||||
],
|
||||
exports: [ MaterialModule ],
|
||||
providers: [ { provide: APP_INITIALIZER, useFactory: init_app, deps: [ I18nService ], multi: true }, { provide: HTTP_INTERCEPTORS, useClass: XhrInterceptor, multi: true }, DatePipe ],
|
||||
providers: [ { provide: APP_INITIALIZER, useFactory: init_app, deps: [ I18nService ], multi: true }, { provide: HTTP_INTERCEPTORS, useClass: XhrInterceptor, multi: true }, DatePipe,
|
||||
{
|
||||
provide: MatPaginatorIntl, useFactory: (i18n) => {
|
||||
const service = new I18nPaginatorIntl();
|
||||
service.injectI18n(i18n)
|
||||
return service;
|
||||
}, deps: [ I18nService ]
|
||||
} ],
|
||||
bootstrap: [ AppComponent ],
|
||||
})
|
||||
export class AppModule {
|
||||
|
@ -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 + "" ]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user