question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[MatPaginator] Extracting the OF preposition out of getRangeLabel for easier I18n

See original GitHub issue

Bug, 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dushkostanoeskicommented, Feb 25, 2018

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.

0reactions
angular-automatic-lock-bot[bot]commented, Jul 31, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found