mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-23 06:25:24 -07:00
Localize paginator
This commit is contained in:
parent
fb19ace3e9
commit
a5ec79717b
3 changed files with 50 additions and 0 deletions
|
@ -65,6 +65,9 @@ import { TooltipModule } from "primeng/tooltip";
|
|||
import { TranslateHttpLoader } from "@ngx-translate/http-loader";
|
||||
import { UnauthorizedInterceptor } from "./auth/unauthorized.interceptor";
|
||||
import { environment } from "../environments/environment";
|
||||
import { MatPaginatorIntl } from "@angular/material/paginator";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
import { MatPaginatorI18n } from "./localization/MatPaginatorI18n";
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: "*", component: PageNotFoundComponent },
|
||||
|
@ -212,6 +215,10 @@ export function JwtTokenGetter() {
|
|||
useClass: UnauthorizedInterceptor,
|
||||
multi: true
|
||||
},
|
||||
{
|
||||
provide: MatPaginatorIntl, deps: [TranslateService],
|
||||
useFactory: (translateService: TranslateService) => new MatPaginatorI18n(translateService).getPaginatorIntl()
|
||||
},
|
||||
],
|
||||
bootstrap: [AppComponent],
|
||||
})
|
||||
|
|
34
src/Ombi/ClientApp/src/app/localization/MatPaginatorI18n.ts
Normal file
34
src/Ombi/ClientApp/src/app/localization/MatPaginatorI18n.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { MatPaginatorIntl } from '@angular/material/paginator';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
|
||||
export class MatPaginatorI18n {
|
||||
|
||||
constructor(private translate: TranslateService) { }
|
||||
|
||||
getPaginatorIntl(): MatPaginatorIntl {
|
||||
const paginatorIntl = new MatPaginatorIntl();
|
||||
paginatorIntl.itemsPerPageLabel = this.translate.instant('Paginator.itemsPerPageLabel');
|
||||
paginatorIntl.nextPageLabel = this.translate.instant('Paginator.nextPageLabel');
|
||||
paginatorIntl.previousPageLabel = this.translate.instant('Paginator.previousPageLabel');
|
||||
paginatorIntl.firstPageLabel = this.translate.instant('Paginator.firstPageLabel');
|
||||
paginatorIntl.lastPageLabel = this.translate.instant('Paginator.lastPageLabel');
|
||||
paginatorIntl.getRangeLabel = this.getRangeLabel.bind(this);
|
||||
return paginatorIntl;
|
||||
}
|
||||
|
||||
private getRangeLabel(page: number, pageSize: number, length: number): string {
|
||||
if (length == 0 || pageSize == 0) {
|
||||
return this.translate.instant('Paginator.rangePageLabel1', { length });
|
||||
}
|
||||
|
||||
length = Math.max(length, 0);
|
||||
|
||||
const startIndex = page * pageSize;
|
||||
|
||||
// If the start index exceeds the list length, do not try and fix the end index to the end.
|
||||
const endIndex =
|
||||
startIndex < length ? Math.min(startIndex + pageSize, length) : startIndex + pageSize;
|
||||
|
||||
return this.translate.instant('Paginator.rangePageLabel2', { startIndex: startIndex + 1, endIndex, length });
|
||||
}
|
||||
}
|
|
@ -408,6 +408,15 @@
|
|||
"3": "Emby User",
|
||||
"4": "Emby Connect User",
|
||||
"5": "Jellyfin User"
|
||||
},
|
||||
"Paginator": {
|
||||
"itemsPerPageLabel": "Items per page:",
|
||||
"nextPageLabel": "Next page",
|
||||
"previousPageLabel": "Previous page",
|
||||
"firstPageLabel": "First page",
|
||||
"lastPageLabel": "Last page",
|
||||
"rangePageLabel1": "0 of {{length}}",
|
||||
"rangePageLabel2": "{{startIndex}} – {{endIndex}} of {{length}}"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue