material-ui-datetimepicker icon indicating copy to clipboard operation
material-ui-datetimepicker copied to clipboard

Changing the locale?

Open neo182 opened this issue 7 years ago • 1 comments

Hi! I just began experimenting with this component. It seems changing the locale of DatePickerDialog does not seem easy. Am I missing something here? Is there any way to accomplish this without adding new features? If not, should not it be a new feature? Neo

neo182 avatar Feb 08 '18 14:02 neo182

I managed to make it work using the following code segment (an example for German):

let DateTimeFormat = null;
if (areIntlLocalesSupported(['de'])) {
    DateTimeFormat = global.Intl.DateTimeFormat;
} else {
    const IntlPolyfill = require('intl');
    DateTimeFormat = IntlPolyfill.DateTimeFormat;
    require('intl/locale-data/jsonp/de');
}

Where areIntlLocalesSupported function comes from the intl-locales-supported package. Additionally, you also need the Intl.js package for the polyfill.

Finally, you can include the following props to the DateTimePicker component:

<DateTimePicker DatePicker={DatePickerDialog}
                TimePicker={TimePickerDialog}
		DateTimeFormat={DateTimeFormat}
		locale='de'
/>

etairi avatar Jul 12 '18 09:07 etairi