[MatPaginator] Extracting the OF preposition out of getRangeLabel for easier I18n
See original GitHub issueBug, feature request, or proposal:
Proposal
What is the expected behavior?
To be able to provide a class that only replaces the string values and not the whole getRangeLabel
function. The code:
...
/** A label for the preposition. */
prepositionLabel: string = 'of';
/** A label for the range of items within the current page and the length of the whole list. */
getRangeLabel = (page: number, pageSize: number, length: number) => {
if (length == 0 || pageSize == 0) { return `0 ${this.prepositionLabel} ${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} ${this.prepositionLabel} ${length}`;
}
...
What is the current behavior?
I don’t know how often people replace the way the range label is generated, but I am guessing most just copy/paste the code and only translate the preposition to their language.
What is the use-case or motivation for changing an existing behavior?
If there are changes in the logic behind getRangeLabel
, they won’t be reflected if you are providing translations. Most languages work the same way (the preposition is between the endIndex
and length
) so extracting the preposition would be much more convenient.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
angular - How to use MatPaginatorIntl? - Stack Overflow
You can do it like this: I'm providing you with croatian labels: customClass.ts import { Injectable } from '@angular/core'; ...
Read more >Translating the MatPaginator Angular Material component
The MatPaginator component of Angular Material can be translated, but it requires a specific approach. Internationalization and localization start to matter ...
Read more >how to update the length in getrangelabel mat paginator
I am assuming you just want to set the total length of mat-pagiator. You are looking for a way to bind it with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That is why I’m not saying to completely hide the
getRangeLabel
property.If you’re working with a language where only the preposition needs to be translated, you provide only the preposition property, but if the whole label needs to be changed, you can skip the preposition and provide the label because the preposition is only used in the label.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.