@lminii/material-react-table 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -234
- package/locales/ja/index.d.mts +0 -3
- package/locales/ja/index.d.ts +0 -3
- package/locales/ja/package.json +0 -6
- package/package.json +147 -147
- package/skills/README.md +81 -81
- package/skills/composable-components/SKILL.md +189 -189
- package/skills/customization/SKILL.md +190 -190
- package/skills/drag-and-drop-ordering/SKILL.md +227 -227
- package/skills/editing/SKILL.md +243 -243
- package/skills/filtering/SKILL.md +213 -213
- package/skills/getting-started/SKILL.md +213 -213
- package/skills/localization/SKILL.md +182 -182
- package/skills/migrate-v3-to-v4/SKILL.md +161 -161
- package/skills/state-and-server-data/SKILL.md +200 -200
- package/skills/virtualization/SKILL.md +203 -203
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: localization
|
|
3
|
-
description: >
|
|
4
|
-
Translate Material React Table V4 with the localization option: import a built-in locale from @lminii/material-react-table/locales/<code>, override individual MRT_Localization strings, write a full custom locale with the language BCP 47 tag, keep {column} placeholders, and pair it with Material UI theme locales and the date pickers adapterLocale. Load for i18n, translating toolbar and menu text, number formatting in pagination, or a locale import that fails to resolve.
|
|
5
|
-
metadata:
|
|
6
|
-
type: framework
|
|
7
|
-
library: '@lminii/material-react-table'
|
|
8
|
-
library_version: '4.0.0'
|
|
9
|
-
framework: react
|
|
10
|
-
requires:
|
|
11
|
-
- getting-started
|
|
12
|
-
sources:
|
|
13
|
-
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/localization.mdx'
|
|
14
|
-
- 'lminii/material-react-table:apps/material-react-table-docs/examples/localization-i18n-de/sandbox/src/TS.tsx'
|
|
15
|
-
- 'lminii/material-react-table:packages/material-react-table/src/locales/en.ts'
|
|
16
|
-
- 'lminii/material-react-table:packages/material-react-table/src/hooks/useMRT_TableOptions.ts'
|
|
17
|
-
- 'lminii/material-react-table:packages/material-react-table/src/types.ts'
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
This skill builds on `getting-started`. Every user-facing string MRT renders comes from one `MRT_Localization` object. The `localization` option takes a partial object that is merged over the English defaults, so a locale file or a handful of overrides both work.
|
|
21
|
-
|
|
22
|
-
## Setup
|
|
23
|
-
|
|
24
|
-
```tsx
|
|
25
|
-
import { MRT_Localization_DE } from '@lminii/material-react-table/locales/de'
|
|
26
|
-
|
|
27
|
-
const table = useMaterialReactTable({
|
|
28
|
-
columns,
|
|
29
|
-
data,
|
|
30
|
-
localization: MRT_Localization_DE,
|
|
31
|
-
})
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Built-in locales, imported from `@lminii/material-react-table/locales/<code>`: `ar`, `az`, `bg`, `cs`, `da`, `de`, `el`, `en`, `es`, `et`, `fa`, `fi`, `fr`, `he`, `hr`, `hu`, `hy`, `id`, `it`, `ja`, `ko`, `mk`, `nl`, `no`, `np`, `pl`, `pt`, `pt-BR`, `ro`, `ru`, `sk`, `sr-Cyrl-RS`, `sr-Latn-RS`, `sv`, `tr`, `uk`, `vi`, `zh-Hans`, `zh-Hant`. Each exports `MRT_Localization_<CODE>` with hyphens replaced by underscores, for example `MRT_Localization_PT_BR` and `MRT_Localization_ZH_HANS`. Column headers, cell content, and your own toolbar buttons are not translated by MRT; those come from your column definitions and render slots.
|
|
35
|
-
|
|
36
|
-
## Core Patterns
|
|
37
|
-
|
|
38
|
-
### Override a few strings
|
|
39
|
-
|
|
40
|
-
```tsx
|
|
41
|
-
const table = useMaterialReactTable({
|
|
42
|
-
columns,
|
|
43
|
-
data,
|
|
44
|
-
localization: {
|
|
45
|
-
...MRT_Localization_DE,
|
|
46
|
-
noRecordsToDisplay: 'Keine Personen gefunden',
|
|
47
|
-
rowsPerPage: 'Personen pro Seite',
|
|
48
|
-
},
|
|
49
|
-
})
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Partial objects are merged over English, so an override object without a base locale still renders every other string. Keep the `localization` object stable (module scope or `useMemo`); MRT memoizes the merge on its identity.
|
|
53
|
-
|
|
54
|
-
### Write a custom locale
|
|
55
|
-
|
|
56
|
-
```tsx
|
|
57
|
-
import { type MRT_Localization } from '@lminii/material-react-table'
|
|
58
|
-
|
|
59
|
-
export const MRT_Localization_GA: MRT_Localization = {
|
|
60
|
-
...MRT_Localization_EN, // start from English so nothing is missing
|
|
61
|
-
language: 'ga', // BCP 47 tag used for number formatting
|
|
62
|
-
actions: 'Gníomhartha',
|
|
63
|
-
filterByColumn: 'Scag de réir {column}',
|
|
64
|
-
sortByColumnAsc: 'Sórtáil de réir {column} in ord ardaitheach',
|
|
65
|
-
noRecordsToDisplay: 'Níl aon taifid le taispeáint',
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
`MRT_Localization` has around 90 keys; `language` is required on the type and feeds `toLocaleString` for the row counts in pagination and the selection banner. Strings such as `filterByColumn`, `sortByColumnAsc`, `dropToGroupBy`, and `filteringByColumn` contain `{column}` placeholders that MRT replaces with the column header, so keep the token verbatim. Fully translated locales are welcome as pull requests to `packages/material-react-table/src/locales`.
|
|
70
|
-
|
|
71
|
-
### Pair with Material UI and the date pickers
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
import { createTheme, ThemeProvider, useTheme } from '@mui/material'
|
|
75
|
-
import { deDE } from '@mui/material/locale'
|
|
76
|
-
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'
|
|
77
|
-
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
|
78
|
-
import { deDE as pickersDeDE } from '@mui/x-date-pickers/locales'
|
|
79
|
-
import 'dayjs/locale/de'
|
|
80
|
-
|
|
81
|
-
const theme = useTheme()
|
|
82
|
-
|
|
83
|
-
<ThemeProvider theme={createTheme(theme, deDE, pickersDeDE)}>
|
|
84
|
-
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="de">
|
|
85
|
-
<MaterialReactTable table={table} />
|
|
86
|
-
</LocalizationProvider>
|
|
87
|
-
</ThemeProvider>
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
MRT's `localization` covers MRT strings only. Material UI's own component text (pagination select labels, accessibility labels) comes from the theme locale, and the date and time filter pickers take their month names and formats from the pickers locale and `adapterLocale`.
|
|
91
|
-
|
|
92
|
-
### Switch locales at runtime
|
|
93
|
-
|
|
94
|
-
```tsx
|
|
95
|
-
const locales = { en: MRT_Localization_EN, de: MRT_Localization_DE, ja: MRT_Localization_JA }
|
|
96
|
-
|
|
97
|
-
const table = useMaterialReactTable({
|
|
98
|
-
columns,
|
|
99
|
-
data,
|
|
100
|
-
localization: locales[currentLanguage],
|
|
101
|
-
})
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
The table re-renders with the new strings; no state is reset.
|
|
105
|
-
|
|
106
|
-
## Common Mistakes
|
|
107
|
-
|
|
108
|
-
### HIGH Importing a locale from the upstream package name
|
|
109
|
-
|
|
110
|
-
Wrong:
|
|
111
|
-
|
|
112
|
-
```tsx
|
|
113
|
-
import { MRT_Localization_ES } from 'material-react-table/locales/es'
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Correct:
|
|
117
|
-
|
|
118
|
-
```tsx
|
|
119
|
-
import { MRT_Localization_ES } from '@lminii/material-react-table/locales/es'
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
The fork publishes locales under its own `exports` map. The upstream path resolves only if the upstream package is also installed, which produces two copies of MRT.
|
|
123
|
-
|
|
124
|
-
Source: `MIGRATION.md`
|
|
125
|
-
|
|
126
|
-
### MEDIUM Custom locale without the language tag
|
|
127
|
-
|
|
128
|
-
Wrong:
|
|
129
|
-
|
|
130
|
-
```tsx
|
|
131
|
-
localization: { actions: 'Ações', cancel: 'Cancelar', rowsPerPage: 'Linhas por página' }
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Correct:
|
|
135
|
-
|
|
136
|
-
```tsx
|
|
137
|
-
localization: { language: 'pt', actions: 'Ações', cancel: 'Cancelar', rowsPerPage: 'Linhas por página' }
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
Without `language`, the English `en` tag from the merged defaults formats row counts, so `1.234` renders as `1,234`.
|
|
141
|
-
|
|
142
|
-
Source: `packages/material-react-table/src/locales/en.ts`
|
|
143
|
-
|
|
144
|
-
### MEDIUM Dropping the {column} placeholder
|
|
145
|
-
|
|
146
|
-
Wrong:
|
|
147
|
-
|
|
148
|
-
```tsx
|
|
149
|
-
localization: { filterByColumn: 'Filtrer' }
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
Correct:
|
|
153
|
-
|
|
154
|
-
```tsx
|
|
155
|
-
localization: { filterByColumn: 'Filtrer par {column}' }
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
MRT substitutes the header into `{column}`; without it the tooltip and placeholder no longer say which column they apply to.
|
|
159
|
-
|
|
160
|
-
Source: `packages/material-react-table/src/locales/en.ts`
|
|
161
|
-
|
|
162
|
-
### LOW Passing an unstable localization object
|
|
163
|
-
|
|
164
|
-
Wrong:
|
|
165
|
-
|
|
166
|
-
```tsx
|
|
167
|
-
localization: { ...MRT_Localization_FR, noRecordsToDisplay: t('empty') }, // new object each render
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Correct:
|
|
171
|
-
|
|
172
|
-
```tsx
|
|
173
|
-
const localization = useMemo(() => ({ ...MRT_Localization_FR, noRecordsToDisplay: t('empty') }), [t])
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
A fresh object every render re-runs the merge and invalidates the memoized table options.
|
|
177
|
-
|
|
178
|
-
Source: `packages/material-react-table/src/hooks/useMRT_TableOptions.ts`
|
|
179
|
-
|
|
180
|
-
## API Discovery
|
|
181
|
-
|
|
182
|
-
`MRT_Localization` in `node_modules/@lminii/material-react-table/dist/index.d.ts` lists every key; `en.ts` in `packages/material-react-table/src/locales` is the reference translation. `ls node_modules/@lminii/material-react-table/locales` shows the shipped locale folders. The Localization guide at `/docs/guides/localization` renders an example per locale.
|
|
1
|
+
---
|
|
2
|
+
name: localization
|
|
3
|
+
description: >
|
|
4
|
+
Translate Material React Table V4 with the localization option: import a built-in locale from @lminii/material-react-table/locales/<code>, override individual MRT_Localization strings, write a full custom locale with the language BCP 47 tag, keep {column} placeholders, and pair it with Material UI theme locales and the date pickers adapterLocale. Load for i18n, translating toolbar and menu text, number formatting in pagination, or a locale import that fails to resolve.
|
|
5
|
+
metadata:
|
|
6
|
+
type: framework
|
|
7
|
+
library: '@lminii/material-react-table'
|
|
8
|
+
library_version: '4.0.0'
|
|
9
|
+
framework: react
|
|
10
|
+
requires:
|
|
11
|
+
- getting-started
|
|
12
|
+
sources:
|
|
13
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/localization.mdx'
|
|
14
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/localization-i18n-de/sandbox/src/TS.tsx'
|
|
15
|
+
- 'lminii/material-react-table:packages/material-react-table/src/locales/en.ts'
|
|
16
|
+
- 'lminii/material-react-table:packages/material-react-table/src/hooks/useMRT_TableOptions.ts'
|
|
17
|
+
- 'lminii/material-react-table:packages/material-react-table/src/types.ts'
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
This skill builds on `getting-started`. Every user-facing string MRT renders comes from one `MRT_Localization` object. The `localization` option takes a partial object that is merged over the English defaults, so a locale file or a handful of overrides both work.
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { MRT_Localization_DE } from '@lminii/material-react-table/locales/de'
|
|
26
|
+
|
|
27
|
+
const table = useMaterialReactTable({
|
|
28
|
+
columns,
|
|
29
|
+
data,
|
|
30
|
+
localization: MRT_Localization_DE,
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Built-in locales, imported from `@lminii/material-react-table/locales/<code>`: `ar`, `az`, `bg`, `cs`, `da`, `de`, `el`, `en`, `es`, `et`, `fa`, `fi`, `fr`, `he`, `hr`, `hu`, `hy`, `id`, `it`, `ja`, `ko`, `mk`, `nl`, `no`, `np`, `pl`, `pt`, `pt-BR`, `ro`, `ru`, `sk`, `sr-Cyrl-RS`, `sr-Latn-RS`, `sv`, `tr`, `uk`, `vi`, `zh-Hans`, `zh-Hant`. Each exports `MRT_Localization_<CODE>` with hyphens replaced by underscores, for example `MRT_Localization_PT_BR` and `MRT_Localization_ZH_HANS`. Column headers, cell content, and your own toolbar buttons are not translated by MRT; those come from your column definitions and render slots.
|
|
35
|
+
|
|
36
|
+
## Core Patterns
|
|
37
|
+
|
|
38
|
+
### Override a few strings
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
const table = useMaterialReactTable({
|
|
42
|
+
columns,
|
|
43
|
+
data,
|
|
44
|
+
localization: {
|
|
45
|
+
...MRT_Localization_DE,
|
|
46
|
+
noRecordsToDisplay: 'Keine Personen gefunden',
|
|
47
|
+
rowsPerPage: 'Personen pro Seite',
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Partial objects are merged over English, so an override object without a base locale still renders every other string. Keep the `localization` object stable (module scope or `useMemo`); MRT memoizes the merge on its identity.
|
|
53
|
+
|
|
54
|
+
### Write a custom locale
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { type MRT_Localization } from '@lminii/material-react-table'
|
|
58
|
+
|
|
59
|
+
export const MRT_Localization_GA: MRT_Localization = {
|
|
60
|
+
...MRT_Localization_EN, // start from English so nothing is missing
|
|
61
|
+
language: 'ga', // BCP 47 tag used for number formatting
|
|
62
|
+
actions: 'Gníomhartha',
|
|
63
|
+
filterByColumn: 'Scag de réir {column}',
|
|
64
|
+
sortByColumnAsc: 'Sórtáil de réir {column} in ord ardaitheach',
|
|
65
|
+
noRecordsToDisplay: 'Níl aon taifid le taispeáint',
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`MRT_Localization` has around 90 keys; `language` is required on the type and feeds `toLocaleString` for the row counts in pagination and the selection banner. Strings such as `filterByColumn`, `sortByColumnAsc`, `dropToGroupBy`, and `filteringByColumn` contain `{column}` placeholders that MRT replaces with the column header, so keep the token verbatim. Fully translated locales are welcome as pull requests to `packages/material-react-table/src/locales`.
|
|
70
|
+
|
|
71
|
+
### Pair with Material UI and the date pickers
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import { createTheme, ThemeProvider, useTheme } from '@mui/material'
|
|
75
|
+
import { deDE } from '@mui/material/locale'
|
|
76
|
+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'
|
|
77
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
|
78
|
+
import { deDE as pickersDeDE } from '@mui/x-date-pickers/locales'
|
|
79
|
+
import 'dayjs/locale/de'
|
|
80
|
+
|
|
81
|
+
const theme = useTheme()
|
|
82
|
+
|
|
83
|
+
<ThemeProvider theme={createTheme(theme, deDE, pickersDeDE)}>
|
|
84
|
+
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="de">
|
|
85
|
+
<MaterialReactTable table={table} />
|
|
86
|
+
</LocalizationProvider>
|
|
87
|
+
</ThemeProvider>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
MRT's `localization` covers MRT strings only. Material UI's own component text (pagination select labels, accessibility labels) comes from the theme locale, and the date and time filter pickers take their month names and formats from the pickers locale and `adapterLocale`.
|
|
91
|
+
|
|
92
|
+
### Switch locales at runtime
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
const locales = { en: MRT_Localization_EN, de: MRT_Localization_DE, ja: MRT_Localization_JA }
|
|
96
|
+
|
|
97
|
+
const table = useMaterialReactTable({
|
|
98
|
+
columns,
|
|
99
|
+
data,
|
|
100
|
+
localization: locales[currentLanguage],
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The table re-renders with the new strings; no state is reset.
|
|
105
|
+
|
|
106
|
+
## Common Mistakes
|
|
107
|
+
|
|
108
|
+
### HIGH Importing a locale from the upstream package name
|
|
109
|
+
|
|
110
|
+
Wrong:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { MRT_Localization_ES } from 'material-react-table/locales/es'
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Correct:
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
import { MRT_Localization_ES } from '@lminii/material-react-table/locales/es'
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The fork publishes locales under its own `exports` map. The upstream path resolves only if the upstream package is also installed, which produces two copies of MRT.
|
|
123
|
+
|
|
124
|
+
Source: `MIGRATION.md`
|
|
125
|
+
|
|
126
|
+
### MEDIUM Custom locale without the language tag
|
|
127
|
+
|
|
128
|
+
Wrong:
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
localization: { actions: 'Ações', cancel: 'Cancelar', rowsPerPage: 'Linhas por página' }
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Correct:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
localization: { language: 'pt', actions: 'Ações', cancel: 'Cancelar', rowsPerPage: 'Linhas por página' }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Without `language`, the English `en` tag from the merged defaults formats row counts, so `1.234` renders as `1,234`.
|
|
141
|
+
|
|
142
|
+
Source: `packages/material-react-table/src/locales/en.ts`
|
|
143
|
+
|
|
144
|
+
### MEDIUM Dropping the {column} placeholder
|
|
145
|
+
|
|
146
|
+
Wrong:
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
localization: { filterByColumn: 'Filtrer' }
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Correct:
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
localization: { filterByColumn: 'Filtrer par {column}' }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
MRT substitutes the header into `{column}`; without it the tooltip and placeholder no longer say which column they apply to.
|
|
159
|
+
|
|
160
|
+
Source: `packages/material-react-table/src/locales/en.ts`
|
|
161
|
+
|
|
162
|
+
### LOW Passing an unstable localization object
|
|
163
|
+
|
|
164
|
+
Wrong:
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
localization: { ...MRT_Localization_FR, noRecordsToDisplay: t('empty') }, // new object each render
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Correct:
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
const localization = useMemo(() => ({ ...MRT_Localization_FR, noRecordsToDisplay: t('empty') }), [t])
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
A fresh object every render re-runs the merge and invalidates the memoized table options.
|
|
177
|
+
|
|
178
|
+
Source: `packages/material-react-table/src/hooks/useMRT_TableOptions.ts`
|
|
179
|
+
|
|
180
|
+
## API Discovery
|
|
181
|
+
|
|
182
|
+
`MRT_Localization` in `node_modules/@lminii/material-react-table/dist/index.d.ts` lists every key; `en.ts` in `packages/material-react-table/src/locales` is the reference translation. `ls node_modules/@lminii/material-react-table/locales` shows the shipped locale folders. The Localization guide at `/docs/guides/localization` renders an example per locale.
|