Skip to content

Commit 2d8467d

Browse files
authored
feat: add language localization support for converting numbers to local string (#1359)
This explicitly tells the `toLocaleString` function which language to use based on the provided localization instead of relying on the browser language. This allows a correct formatting of numbers within a multi language app.
1 parent a6c227d commit 2d8467d

File tree

43 files changed

+69
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+69
-6
lines changed

apps/material-react-table-docs/pages/docs/guides/localization.mdx

Lines changed: 3 additions & 1 deletion

packages/material-react-table/src/components/toolbar/MRT_TablePagination.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
174174
sx={{ m: '0 4px', minWidth: '8ch' }}
175175
variant="body2"
176176
>{`${
177-
lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString()
178-
}-${lastRowIndex.toLocaleString()} ${
177+
lastRowIndex === 0
178+
? 0
179+
: (firstRowIndex + 1).toLocaleString(localization.language)
180+
}-${lastRowIndex.toLocaleString(localization.language)} ${
179181
localization.of
180-
} ${totalRowCount.toLocaleString()}`}</Typography>
182+
} ${totalRowCount.toLocaleString(localization.language)}`}</Typography>
181183
<Box gap="xs">
182184
{showFirstButton && (
183185
<Tooltip {...tooltipProps} title={localization.goToFirstPage}>

packages/material-react-table/src/components/toolbar/MRT_ToolbarAlertBanner.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export const MRT_ToolbarAlertBanner = <TData extends MRT_RowData>({
6565
selectedRowCount > 0 ? (
6666
<Stack alignItems="center" direction="row" gap="16px">
6767
{localization.selectedCountOfRowCountRowsSelected
68-
?.replace('{selectedCount}', selectedRowCount.toLocaleString())
69-
?.replace('{rowCount}', totalRowCount.toString())}
68+
?.replace('{selectedCount}', selectedRowCount.toLocaleString(localization.language))
69+
?.replace('{rowCount}', totalRowCount.toLocaleString(localization.language))}
7070
<Button
7171
onClick={(event) =>
7272
getMRT_SelectAllHandler({ table })(event, false, true)

packages/material-react-table/src/locales/ar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type MRT_Localization } from '..';
22

33
export const MRT_Localization_AR: MRT_Localization = {
4+
language: 'ar',
45
actions: 'إجراءات',
56
and: 'و',
67
cancel: 'إلغاء',

packages/material-react-table/src/locales/az.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type MRT_Localization } from '..';
22

33
export const MRT_Localization_AZ: MRT_Localization = {
4+
language: 'az',
45
actions: 'Əməliyyatlar',
56
and: 'və',
67
cancel: 'Ləğv Et',

packages/material-react-table/src/locales/bg.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type MRT_Localization } from '..';
22

33
export const MRT_Localization_BG: MRT_Localization = {
4+
language: 'bg',
45
actions: 'Действия',
56
and: 'и',
67
cancel: 'Отказ',

packages/material-react-table/src/locales/cs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type MRT_Localization } from '..';
22

33
export const MRT_Localization_CS: MRT_Localization = {
4+
language: 'cs',
45
actions: 'Akce',
56
and: 'a',
67
cancel: 'Zrušit',

packages/material-react-table/src/locales/da.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type MRT_Localization } from '..';
22

33
export const MRT_Localization_DA: MRT_Localization = {
4+
language: 'da',
45
actions: 'Handlinger',
56
and: 'og',
67
cancel: 'Annuller',

packages/material-react-table/src/locales/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type MRT_Localization } from '..';
22

33
export const MRT_Localization_DE: MRT_Localization = {
4+
language: 'de',
45
actions: 'Aktionen',
56
and: 'und',
67
cancel: 'Abbrechen',

packages/material-react-table/src/locales/el.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type MRT_Localization } from '..';
22

33
export const MRT_Localization_EL: MRT_Localization = {
4+
language: 'el',
45
actions: 'Ενέργειες',
56
and: 'και',
67
cancel: 'Ακύρωση',

0 commit comments

Comments
 (0)