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

[DataGrid] Implement i18n #196

Closed
oliviertassinari opened this issue Aug 21, 2020 · 4 comments · Fixed by #791
Closed

[DataGrid] Implement i18n #196

oliviertassinari opened this issue Aug 21, 2020 · 4 comments · Fixed by #791
Assignees
Labels
component: data grid This is the name of the generic UI component, not the React module! linked in docs The issue is linked in the docs, so completely skew the upvotes new feature New feature or request

Comments

@oliviertassinari oliviertassinari added component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request labels Aug 21, 2020
@oliviertassinari oliviertassinari changed the title [DataGrid] Implement localization [DataGrid] Implement Localization Sep 1, 2020
@oliviertassinari
Copy link
Member Author

I recall a discussion around a year ago about what would be the best approach to handle localization with large components, e.g mui/material-ui-pickers#1429 (comment). While we use xxxText props when a component needs a few translation keys, I propose we have a single prop, called text as done in mui/material-ui#18872 for the data grid.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Oct 8, 2020

My first comment is about exposing an API to allow customizing the wordings in the data grid. There is a second important dimension to consider: providing out of the box support for popular locales.

We could use the exact same mechanism as the other components. The content could be stored in the main repository. We aim to support the 100 most used locales. The main downside would be about the bloat introduced, but I would argue it's negligible.
At least, there is a tradeoff to consider between the usage simplicity of having all the translations inside a single object and the complexity to cherry-pick the translations for the component used to save a bit of bundle size.

If we decided to host the translations in the repository, we will need to work on the bundling script as it's not set up to support it.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Nov 23, 2020

A proposed plan of action, we do it in two steps. The first step closes this issue, a new issue will need to be open for 2. (so we can have a number of 👍 that isn't skewed by an issue linked in the documentation).

1. i18n

  1. We add a localeText prop to the DataGrid and XGrid components. This is an object that can be globally overridden through the theme with theme.components.MuiDataGrid.defaultProps.localeText.
  2. The prop performs a deep merge with the default translations.
  3. The default translations are in the en_US locale.
  4. We use the context to propagate the prop down to all the components of the grid. This propagation can be implemented with a custom context or the apiRef, to be determined on what we need to optimize. No matter the solution we pick, it needs to propagate everywhere in the data grid. I memo shouldn't prevent the value to be updated.
  5. We document it.

2. l10n

  1. We implement https://next.material-ui.com/guides/localization/.
  2. There is a challenge around where the translated values are hosted, tree-shaked, and used by developers. Maybe like this would be good enough:
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
import { zhCN } from '@material-ui/date-grid/locale'; // for DataGrid
import { zhCN } from '@material-ui/x-grid/locale'; // for XGrid
import { zhCN } from '@material-ui/x/locale'; // for all the X components

const theme = createMuiTheme(
  {
    palette: {
      primary: { main: '#1976d2' },
    },
  },
  zhCN,
);

<ThemeProvider theme={theme}>
  <App />
</ThemeProvider>;

@oliviertassinari oliviertassinari added the linked in docs The issue is linked in the docs, so completely skew the upvotes label Nov 30, 2020
@DanailH DanailH self-assigned this Dec 2, 2020
@oliviertassinari oliviertassinari changed the title [DataGrid] Implement Localization [DataGrid] Implement Internationalization Dec 23, 2020
@oliviertassinari oliviertassinari changed the title [DataGrid] Implement Internationalization [DataGrid] Implement i18n Dec 23, 2020
@oliviertassinari
Copy link
Member Author

oliviertassinari commented Dec 28, 2020

I have created a separate issue for the point 2. l10n: #777 so this one can focus on 1. i18n.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! linked in docs The issue is linked in the docs, so completely skew the upvotes new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants