Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

javascript - 如何更改KeyboardDatePicker材质ui的语言?(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.

(我目前在网络上使用Material ui,并且使用KeyboardDatePicker API,它可以完美工作,但是月份的名称和按钮的文本以英语显示,我想将其更改为西班牙语。)

I read the API documentation but I can't find information about it.

(我阅读了API文档,但找不到有关它的信息。)

Anyone know how to change the language?

(有人知道如何更改语言吗?)

  ask by Ruben Valdivia Perez translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

(尝试导入西班牙语时刻语言环境,然后在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>
  );
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...