2017-06-22 17 views
0

antd DatePickerで月名を翻訳することはできますか? モーメントは現在のロケールda_DKに設定されていますが、名前は変更されません。localization exampleを見ましたが、月名は含まれていません。DatePickerで月名をローカライズ

それは可能ですか?

これは、関連するコードです:

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> 
+0

antdはmonthnameの月名を使用しますが、ロケールを設定して ''を使用しましたか?あなたのコードを投稿してください – Kossel

+0

私は関連コードを追加しました。 –

+0

'antd'には現在デンマーク語が含まれていません - https://github.com/ant-design/ant-design/tree/master/components/date-picker/locale –

答えて

0

あなたは以下で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

(悲しいことに、ボルゲンのすべての季節を見ても私のデンマーク語は存在しないのです。 )あなたは上記の翻訳を残しています...)

+0

私の見解では、I以外の何もしていません。瞬間のドキュメントを見て、私はこれが問題になると考えています: "2.8.0以降、グローバルロケールを変更しても既存のインスタンスには影響しません" –

+1

あなたが' _.merge(デフォルト、{... ')でロケールをマッチングしているように見えません。' 'antd.locales.da = {"ロケール ":" da "、...'あなたはデモのリンクを試しましたか?それはデンマーク語の月を示しています –

+0

Oooh、あなたは正しいです: 'locale:" da "'を私のconst 'da'に追加すると違いが生じたので、antdはDatePickerでその定数を使用する必要があります –

関連する問題