如何更改KeyboardDatePicker材质ui的语言? [英] How to change the language for KeyboardDatePicker material ui?

查看:62
本文介绍了如何更改KeyboardDatePicker材质ui的语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在网上使用材料ui,并且使用KeyboardDatePicker API,它可以正常工作,但是月份名称和按钮文本以英语显示,我想将其更改为西班牙语.我阅读了API文档,但找不到有关它的信息.

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?

推荐答案

尝试导入西班牙语瞬间语言环境,然后在 MuiPickersUtilsProvider 中使用它:

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>
  );
}

这篇关于如何更改KeyboardDatePicker材质ui的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆