Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
feat(front-end): Add Spanish translation for mat-paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosPavajeau committed Feb 27, 2021
1 parent b62fc79 commit 89ec013
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Kaizen/ClientApp/src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { CheckClientExistsService } from '@core/services/check-client-exists.ser
import { CheckUserExistsService } from '@core/services/check-user-exists.service';
import { MomentUtcDateAdapter } from '@global/configs/moment-utc-date-adapter';
import { CookieService } from 'ngx-cookie-service';
import { MatPaginatorIntl } from '@angular/material/paginator';
import { getSpanishPaginatorIntl } from '@core/utils/spanish-mat-paginator-intl';

registerLocaleData(localeEs);

Expand All @@ -41,7 +43,7 @@ export class CoreModule {
constructor(
@Optional()
@SkipSelf()
parentModule: CoreModule
parentModule: CoreModule
) {
if (parentModule) {
throw new Error('CoreModule has already been loaded. You should only import Core modules in the AppModule only.');
Expand All @@ -59,7 +61,8 @@ export class CoreModule {
{ provide: MAT_DATE_LOCALE, useValue: 'es-us' },
{ provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS },
{ provide: DateAdapter, useClass: MomentUtcDateAdapter },
{ provide: LOCALE_ID, useValue: 'es' }
{ provide: LOCALE_ID, useValue: 'es' },
{ provide: MatPaginatorIntl, useValue: getSpanishPaginatorIntl() }
]
};
}
Expand Down
27 changes: 27 additions & 0 deletions Kaizen/ClientApp/src/app/core/utils/spanish-mat-paginator-intl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MatPaginatorIntl } from '@angular/material/paginator';

const spanishRangeLabel = (page: number, pageSize: number, length: number) => {
if (length == 0 || pageSize == 0) {
return `0 de ${ 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 `${ startIndex + 1 } - ${ endIndex } de ${ length }`;
};

export function getSpanishPaginatorIntl() {
const paginatorIntl = new MatPaginatorIntl();

paginatorIntl.itemsPerPageLabel = 'Elementos por página:';
paginatorIntl.nextPageLabel = 'Siguiente página';
paginatorIntl.previousPageLabel = 'Pagina anterior';
paginatorIntl.getRangeLabel = spanishRangeLabel;

return paginatorIntl;
}

0 comments on commit 89ec013

Please sign in to comment.