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

Adding localization to Material-UI #1692

Closed
wants to merge 2 commits into from
Closed

Adding localization to Material-UI #1692

wants to merge 2 commits into from

Conversation

nahue
Copy link

@nahue nahue commented Sep 21, 2015

I used react-translate-component and counterpart modules to enable this. If you take a look at master.jsx (from docs module). There are a few simple steps to enable it:

  • Add LocaleManager as a dependency
  • Add LocaleManager.setLocale('en');
  • Add 'muiLocale: LocaleManager.getLocale()' to getChildContext()
  • Add 'muiLocale: React.PropTypes.string' to Master.childContextTypes

if you change setLocale to 'es'.. the datepicker will be in spanish (used that for testing)

locales are available in /src/locales/es.js and en.js (file structure needs work)

Let me know if this works for you!

Material-UI is awesome thanks for the hard work!

@oliviertassinari
Copy link
Member

What do you think about #1658?

@nahue
Copy link
Author

nahue commented Sep 21, 2015

Using momentjs is a good idea.. but i dont like the way of passing locale for each component.. i guess is better to set the locale in the root component's context.

Unless you want to set different locale for each component.. but i dont think so :)

Let me know if i can collaborate with other people.. maybe incorporate my approach into someone else's.

@oliviertassinari
Copy link
Member

I agree with you. Having the locale in the context sounds like a good idea.

For me, the drawback of using momentjs or your approach vs the standardized Intl, is the size of the output you send to the user.
You will probably format date and number outside the material-ui component if you are building a SPA. You don't want the user to load locales twice or more (two 'en' for instance or 'en' and 'es' when they just use 'es')

@nahue
Copy link
Author

nahue commented Sep 21, 2015

Agree. Maybe i could try using react-intl instead of hardcoding locales (seems that this library already manages dates and other strings). Want me to give it a try?

@oliviertassinari
Copy link
Member

@nahue I'm not really sure about adding a dependency to this project.
I think it's better to no to it if we can, react-intl is a simple wrapper about Intl, so I think we can save it.

What do you think about adding a locale and a IntlDateFormater in the context? So that, I can rebase my #1658 PR to use it instead of passing property all the way down to the components that need it?

@nahue
Copy link
Author

nahue commented Sep 21, 2015

Would be nice! im working on a project and i really need i18n on mui components.. @oliviertassinari let me know if you need help!

@tlvenn
Copy link

tlvenn commented Oct 1, 2015

@oliviertassinari , react-intl is much more than a simple wrapper around intl. It's react components on top of http://formatjs.io/ which is built on top of intl. There is a lot of add value provided by FormatJS, thanks to Yahoo hard work.

@nahue
Copy link
Author

nahue commented Oct 6, 2015

Any progress on this matter?

@oliviertassinari
Copy link
Member

@nahue Another PR was merged to adress the Intl support of the DatePicker: #1658.
Feel free to open a new PR if some feature are missing.
Thanks for bringing up the topic.

mnajdova pushed a commit to mnajdova/material-ui that referenced this pull request Nov 10, 2020
* [core] Align internal icons with mono-repository

* rebase

* fix typo
@zannager zannager added the package: material-ui Specific to @mui/material label Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants