在DatePicker中本地化月份名称

时间:2017-06-22 13:07:40

标签: antd

是否可以在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>

1 个答案:

答案 0 :(得分:1)

您可以使用以下内容将丹麦语言区域添加到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的每个季节,但我的丹麦语几乎不存在。我将上述翻译留给你......)