在 DatePicker 中本地化月份名称

Localize month names in DatePicker

antd的DatePicker可以翻译月份吗? Moment 设置为我当前的语言环境 da_DK,但这不会更改名称,我查看了 localization example,但没有包含月份名称。

可能吗?

这是相关代码:

moment.js:

import moment from 'moment';
moment.locale('da-DK');
console.log(moment().format('LLLL')); // This works. Moment displays localized date.

antd:

import { LocaleProvider } from 'antd';
import defaults from 'antd/lib/locale-provider/en_US';

const da = _.merge(defaults, {
  Table: {
    emptyText: 'Ingen data tilgængelig.',
  }
  // month translations here?
});

<LocaleProvider locale={da}>
  <App.... />
</LocaleProvider>

您可以使用以下命令将丹麦语区域设置添加到 antd 全局对象:

const { LocaleProvider, DatePicker, locales, version } = antd;
moment.locale('da');

antd.locales.da = {"locale":"da","Pagination":{"items_per_page":"/ page","jump_to":"Goto","page":"","prev_page":"Previous Page","next_page":"Next Page","prev_5":"Previous 5 Pages","next_5":"Next 5 Pages","prev_3":"Previous 3 Pages","next_3":"Next 3 Pages"},"DatePicker":{"lang":{"placeholder":"Select date","rangePlaceholder":["Start date","End date"],"today":"Today (but in Danish)","now":"Now","backToToday":"Back to today","ok":"Ok","clear":"Clear","month":"Month","year":"Year","timeSelect":"Select time","dateSelect":"Select date","monthSelect":"Choose a month","yearSelect":"Choose a year","decadeSelect":"Choose a decade","yearFormat":"YYYY","dateFormat":"D/M/YYYY","dayFormat":"D","dateTimeFormat":"D/M/YYYY HH:mm:ss","monthBeforeYear":true,"previousMonth":"Previous month (PageUp)","nextMonth":"Next month (PageDown)","previousYear":"Last year (Control + left)","nextYear":"Next year (Control + right)","previousDecade":"Last decade","nextDecade":"Next decade","previousCentury":"Last century","nextCentury":"Next century"},"timePickerLocale":{"placeholder":"Select time"}},"TimePicker":{"placeholder":"Select time"},"Calendar":{"lang":{"placeholder":"Select date","rangePlaceholder":["Start date","End date"],"today":"Today","now":"Now","backToToday":"Back to today","ok":"Ok","clear":"Clear","month":"Month","year":"Year","timeSelect":"Select time","dateSelect":"Select date","monthSelect":"Choose a month","yearSelect":"Choose a year","decadeSelect":"Choose a decade","yearFormat":"YYYY","dateFormat":"D/M/YYYY","dayFormat":"D","dateTimeFormat":"D/M/YYYY HH:mm:ss","monthBeforeYear":true,"previousMonth":"Previous month (PageUp)","nextMonth":"Next month (PageDown)","previousYear":"Last year (Control + left)","nextYear":"Next year (Control + right)","previousDecade":"Last decade","nextDecade":"Next decade","previousCentury":"Last century","nextCentury":"Next century"},"timePickerLocale":{"placeholder":"Select time"}},"Table":{"filterTitle":"Filter menu","filterConfirm":"OK","filterReset":"Reset","emptyText":"No data","selectAll":"Select current page","selectInvert":"Invert current page"},"Modal":{"okText":"OK","cancelText":"Cancel","justOkText":"OK"},"Popconfirm":{"okText":"OK","cancelText":"Cancel"},"Transfer":{"notFoundContent":"Not Found","searchPlaceholder":"Search here","itemUnit":"item","itemsUnit":"items"},"Select":{"notFoundContent":"Not Found"},"Upload":{"uploading":"Uploading...","removeFile":"Remove file","uploadError":"Upload error","previewFile":"Preview file"}};

ReactDOM.render(
  <div>
    <p className="version">antd version: {version}</p>
    <LocaleProvider locale={locales.da}>
      <DatePicker defaultValue={moment()} />   
    </LocaleProvider>
  </div>
, mountNode);

演示 https://codepen.io/anon/pen/bRaGve?editors=0010

(遗憾的是,尽管看了 Borgen 的每个季节,我的丹麦语几乎不存在。我把上面的翻译留给你...)