-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[charts] Add a localization provider #17325
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
Conversation
|
Thanks for adding a type label to the PR! 👍 |
|
Please add one type label to categorize the purpose of this PR appropriately:
|
Localization writing tips ✍️Seems you are updating localization 🌍 files. Thank you for contributing to the localization! 🎉 To make your PR perfect, here is a list of elements to check: ✔️
Deploy preview: https://deploy-preview-17325--material-ui-x.netlify.app/ Updated pages: |
CodSpeed Performance ReportMerging #17325 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be called ChartsLocalizationTableNoSnap? It seems like we're using enUS spelling
packages/x-charts/src/ChartsLocalizationProvider/ChartsLocalizationProvider.test.tsx
Outdated
Show resolved
Hide resolved
packages/x-charts/src/ChartsLocalizationProvider/ChartsLocalizationProvider.test.tsx
Outdated
Show resolved
Hide resolved
packages/x-charts/src/ChartsLocalizationProvider/ChartsLocalizationProvider.tsx
Outdated
Show resolved
Hide resolved
packages/x-charts/src/ChartsLocalizationProvider/ChartsLocalizationProvider.tsx
Outdated
Show resolved
Hide resolved
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
How does starting to follow the docs structure for l10n in #17475 feel? |
scripts/l10n.ts
Outdated
| { | ||
| key: 'charts', | ||
| reportName: '📊 Charts', | ||
| constantsRelativePath: 'packages/x-charts/src/constants/defaultLocale.ts', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does aligning all of those to the pickers feel? Propose in #17475
| constantsRelativePath: 'packages/x-charts/src/constants/defaultLocale.ts', | |
| constantsRelativePath: 'packages/x-charts/src/locales/enUS.ts', |
| * | ||
| * - [ChartsLocalizationProvider API](https://mui.com/x/api/charts/charts-localization-provider/) | ||
| */ | ||
| function ChartsLocalizationProvider(inProps: ChartsLocalizationProviderProps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of having a ChartsLocalizationProvider? I mean, why do we need this when we have the ThemeProvider?
I guess this is the unstyled version. But then, why don't we have a LocalizationProvider component that is shared between all components?
So overall, it looks like the best path is to:
- start without
ChartsLocalizationProviderno problem solved today, keep it simple - generalize the pickers's
LocalizationProvider - add support for the generalized
LocalizationProviderin charts
| ```jsx | ||
| import { createTheme, ThemeProvider } from '@mui/material/styles'; | ||
| import { BarChart } from '@mui/x-charts/BarChart'; | ||
| import { frFR } from '@mui/x-charts/locales'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be clearer
| import { frFR } from '@mui/x-charts/locales'; | |
| import { chartsfrFR } from '@mui/x-charts/locales'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would break the logic we use on all packages and their related example.
For now, all packages export locales as follow:
import { xxYY } from '@mui/[packageName]/locales';And for multiple packages, we encourage them to do
import { xxYY as [packageName]XxYY } from '@mui/[packageName]/locales';There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While doing the update, I understood your point. Exporting an object that contained only the localeText content.
I propose to export frFR and frFRLocaleText to be more explicit that chartsfrFR that does not says if the content is made for localText prop of the createTheme()
|
I tried the structure proposed in #17475 I moved the I moved the table of available locales completely at the end of the page because it can grow a lot (like the data grid one ) and then cut the reading experience |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Close #16963
This introduces the localisation for charts. It will be more useful when we introduce the toolbar since buttons and helpers will need some text.
For info, the data grid put its locales in its
apiRefand the pickers in a dedicated context.I went with the picker approach because we have a similar issue: defining the locale once and using it in multiple components and their subcomponent.
Having a dedicated provider allows targeting it in the MUI theme's defaultProps.
Preview: https://deploy-preview-17325--material-ui-x.netlify.app/x/react-charts/localization/