mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
4.3k stars 1.3k forks source link

[question] Dynamic localization #6554

Closed Shinji22 closed 2 years ago

Shinji22 commented 2 years ago

Order ID πŸ’³

45796

Duplicates

Latest version

The problem in depth πŸ”

Hi, We have a multilingual application, which adapts to the user's browser language. Before loading the application, we don't know the language to load for the application, especially for the Datagrid. In your examples (https://mui.com/x/react-data-grid/localization/#api) you show how to load a specific language, but not how to do it dynamically.

I would like to know how to load the translations of the DataGridPro from a language code (from the user's browser, or when the user chooses another language in the application). Something like the example concerning the global translation of MUI (https://mui.com/material-ui/guides/localization/#example). If the chosen language is not translated for the DataGridPro, we would fallback to English.

Thanks in advance,

Your environment 🌎

`npx @mui/envinfo` ``` Don't forget to mention which browser you used. Output from `npx @mui/envinfo` goes here. ```
yaredtsy commented 2 years ago

@Shinji22 do you want something like this https://codesandbox.io/s/hopeful-ptolemy-yjruw2?file=/demo.tsx:733-736?

Shinji22 commented 2 years ago

Yes, exactly what I was looking for. Did i miss something about "import * as locales from "@mui/x-data-grid/locales";" in the documentation? Thanks for your help!