Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the language for KeyboardDatePicker material ui?

I am currently using material ui on the web and I use the KeyboardDatePicker API and it works perfectly, but the names of the months and the text of the buttons are shown in English and I want to change them to Spanish. I read the API documentation but I can't find information about it.

Anyone know how to change the language?

like image 957
Ruben Valdivia Perez Avatar asked Nov 03 '19 04:11

Ruben Valdivia Perez


2 Answers

Another solution which worked for me is using date-fns/locale/*. The documentation can be found here.

For example in german:

import {KeyboardDatePicker, MuiPickersUtilsProvider} from "@material-ui/pickers";
import DateFnsUtils from "@date-io/date-fns";
import deLocale from "date-fns/locale/de";


render () {
   return 
   (
      <MuiPickersUtilsProvider utils={DateFnsUtils} locale={deLocale}>
      .
      .
      .
      </MuiPickersUtilsProvider>
   )
}

Result:

enter image description here

like image 66
Moritz Schmidt Avatar answered Nov 15 '22 00:11

Moritz Schmidt


Try importing spanish moment locale and then using it in MuiPickersUtilsProvider:

import React from "react";
import ReactDOM from "react-dom";
import {
  KeyboardDatePicker,
  MuiPickersUtilsProvider
} from "@material-ui/pickers";
import MomentUtils from "@date-io/moment";
import "moment/locale/es";

import "./styles.css";

function App() {
  return (
    <div className="App">
      <MuiPickersUtilsProvider locale="es" utils={MomentUtils}>
        <KeyboardDatePicker />
      </MuiPickersUtilsProvider>
    </div>
  );
}
like image 37
Nicolas Hevia Avatar answered Nov 15 '22 00:11

Nicolas Hevia