Last active
November 28, 2023 00:01
-
-
Save ipetinate/ceaeacaf241605d581af1b9c8d0f33e1 to your computer and use it in GitHub Desktop.
Tradutor para o Componente Paginador de Tabelas do Angular Material (no momento está configurado para traduzir do inglês para portugues).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MatPaginatorIntl } from '@angular/material'; | |
const portugueseRangeLabel = (page: number, pageSize: number, length: number) => { | |
if (length === 0 || pageSize === 0) { return `0 de ${length}`; } | |
length = Math.max(length, 0); | |
const startIndex = page * pageSize; | |
const endIndex = startIndex < length ? | |
Math.min(startIndex + pageSize, length) : | |
startIndex + pageSize; | |
return `${startIndex + 1} - ${endIndex} de ${length}`; | |
}; | |
export function getPortuguesePaginatorIntl() { | |
const paginatorIntl = new MatPaginatorIntl(); | |
paginatorIntl.itemsPerPageLabel = 'Itens por página:'; | |
paginatorIntl.nextPageLabel = 'Página seguinte'; | |
paginatorIntl.previousPageLabel = 'Página anterior'; | |
paginatorIntl.getRangeLabel = portugueseRangeLabel; | |
return paginatorIntl; | |
} | |
// Baseado neste código: https://stackblitz.com/edit/angular-5mgfxh-9pusym?file=app%2Fdutch-paginator-intl.ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Atualização para 2023/2024:
O import do
MatPaginatorIntl
, foi atualizado para:A função
getPortuguesePaginatorIntl()
, atualizou para:Como utilizar, adicionar na array providers do
app.module.ts
, o seguinte objeto:Obrigado!