更改react antd DatePicker语言

问题描述 投票:0回答:1

如何将 antd Datepicker 语言设置为法语?

我试过这个:

import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import moment from "moment";
import { DatePicker, Space, ConfigProvider } from "antd";
import frFR from "antd/lib/locale/fr_FR";

function onChange(date, dateString) {
  console.log(date, dateString);
}

ReactDOM.render(
  <Space direction="vertical">
    <ConfigProvider locale={frFR}>
      <DatePicker
        onChange={onChange}
        defaultValue={moment("2015-01-01", "YYYY-MM-DD")}
      />
    </ConfigProvider>
  </Space>,
  document.getElementById("container")
);

预览语言仍为英文。

这是一个运行代码: https://codesandbox.io/s/basic-antd-datepicker-language-n9ue7

javascript reactjs datepicker locale antd
1个回答
5
投票

来自蚂蚁设计文档

import 'moment/locale/zh-cn';
import locale from 'antd/es/date-picker/locale/zh_CN';

<DatePicker locale={locale} />;

https://ant.design/components/date-picker#localization

© www.soinside.com 2019 - 2024. All rights reserved.