Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[table] TablePagination component does not localize the numbers #40589

Closed
aliabbaszade1990 opened this issue Jan 3, 2024 · 6 comments
Closed
Labels
component: table This is the name of the generic UI component, not the React module! i18n internationalization l10n localization

Comments

@aliabbaszade1990
Copy link

aliabbaszade1990 commented Jan 3, 2024

Steps to reproduce

No response

Current behavior

293506581-83f0d3fa-4514-4d9c-842a-3d8341d17c80

Expected behavior

TablePagination component should localize numbers like text part

Context

No response

Your environment

No response

Search keywords: TablePagination

Search keywords:

@aliabbaszade1990 aliabbaszade1990 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 3, 2024
@zannager zannager added the l10n localization label Jan 3, 2024
@michelengelen michelengelen changed the title TablePagination component does not localize the numbers [data grid] TablePagination component does not localize the numbers Jan 3, 2024
@michelengelen michelengelen added component: data grid This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 3, 2024
@MBilalShafi
Copy link
Member

MBilalShafi commented Jan 4, 2024

That's because it's localized that way. TablePagination comes from @mui/material package, and so does its localization. The localization is mostly done by the community members, here's a diff that adds the functionality to convert from English numbers to Arabic ones for the locale arSA for TablePagination.

diff --git a/packages/mui-material/src/locale/index.ts b/packages/mui-material/src/locale/index.ts
index 8c3e85ea88..9d76cf4b55 100644
--- a/packages/mui-material/src/locale/index.ts
+++ b/packages/mui-material/src/locale/index.ts
@@ -170,6 +170,9 @@ export const arEG: Localization = {
   },
 };
 
+// https://stackoverflow.com/a/52089026/1685741
+const enToAr = (value: number) => String(value).replace(/\d/g, d => String.fromCharCode('0x06F'+d));
+
 export const arSA: Localization = {
   components: {
     MuiBreadcrumbs: {
@@ -194,7 +197,7 @@ export const arSA: Localization = {
         },
         labelRowsPerPage: 'عدد الصفوف في الصفحة:',
         labelDisplayedRows: ({ from, to, count }) =>
-          `${from}–${to} من ${count !== -1 ? count : ` أكثر من${to}`}`,
+          `${enToAr(from)}–${enToAr(to)} من ${count !== -1 ? enToAr(count) : ` أكثر من${enToAr(to)}`}`,
       },
     },
     MuiRating: {

Feel free to open up a PR with a similar change of the locale you are interested in.
Check this related issue for more details and examples of the PRs opened by other users: mui/mui-x#3211

@MBilalShafi MBilalShafi added the status: waiting for author Issue with insufficient information label Jan 4, 2024
@MaSsoumeh
Copy link

MaSsoumeh commented Jan 4, 2024

Apply this style to your DataGrid , it could fix it.

 ["& .MuiDataGrid-footerContainer *"]: {
    fontFamily: "IRANSans",  //or any other Persian font
  },

and for the pageSize pass this prop to customize it

  <DataGrid
    pageSizeOptions={[
          { value: 5, label: "۱۰" },
          { value: 10, label: "۲۰" },
          { value: 20, label: "۳۰" },
        ]}

https://mui.com/x/react-data-grid/pagination/

@aliabbaszade1990

Copy link

The issue has been inactive for 7 days and has been automatically closed. If you think that it has been incorrectly closed, please reopen it and provide missing information (if any) or continue the last discussion.

@oliviertassinari oliviertassinari transferred this issue from mui/mui-x Jan 14, 2024
@oliviertassinari oliviertassinari added component: table This is the name of the generic UI component, not the React module! and removed component: data grid This is the name of the generic UI component, not the React module! labels Jan 14, 2024
@oliviertassinari oliviertassinari changed the title [data grid] TablePagination component does not localize the numbers [table] TablePagination component does not localize the numbers Jan 14, 2024
@oliviertassinari oliviertassinari removed the status: waiting for author Issue with insufficient information label Jan 14, 2024
@oliviertassinari oliviertassinari added the i18n internationalization label Jan 14, 2024
@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 14, 2024

This issue looks like a sub issue of #24495, more or less a duplicate.

There are workaround, but not built-in solutions.

@flaviendelangle
Copy link
Member

flaviendelangle commented Jan 15, 2024

This makes me think of mui/mui-x#11639 which I did recently

For dates, the will to render digits as in the localized alphabet or note is handled by the date library (moment & co), all we have to do it to make sure that we are handling this scenario correctly (if the date library renders a localized digit, then we should pass localized digits when typing for instance).

For your scenario, you don't have a date library for the user to define if he wants to localize or not. And it's unclear to me if all users would want their digit to be localized.
I don't think any french dev would complain if you would use the french formatting of large numbers (12 345), but for digit in another alphabet, it's unclear to me if all devs want the localized version or if some want the localized and other the non-localized.

@MBilalShafi
Copy link
Member

MBilalShafi commented Jan 15, 2024

And it's unclear to me if all users would want their digit to be localized

That's a very good point. My experience around Urdu (ur-PK) locale implies that it's a mixed ratio, more people would want to use English digits rather than the Urdu ones, as people are more comfortable with the former. So as @oliviertassinari mentioned, the solution I proposed might not be a long term one and would not work for all the cases.

In Data Grid's perspective, a more specific and quicker workaround that would not require an update on the locale could be providing the translation keys for MuiTablePagination using localeText prop. Could this be a reasonable middle-ground for now keeping in mind the point of not everyone would want the digits to be localized?

<DataGrid
  {...data}
  localeText={{
    MuiTablePagination: {
      labelDisplayedRows: ({ from, to, count }) =>
        `${convertDigits(from)} - ${convertDigits(to)} of more than ${convertDigits(count)}`,
    },
  }}
/>

A proper long term solution still needs to be explored though, which would allow the users to do this switching as needed instead of enforcing on all the users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: table This is the name of the generic UI component, not the React module! i18n internationalization l10n localization
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

7 participants