2017-10-25 39 views
4

DayPickerInputコンポーネントをフォームの日付フィールドに使用し、曜日と月を別の言語(ヘブライ語)で表示したいとします。 ライブラリのAPIでは、基本コンポーネント(DayPicker)の言語を変更する非常に簡単な方法を見つけましたが、この方法はDayPickerInputでは機能しません。反応日ピッカーの言語を変更するDayPickerInputコンポーネント

選択した日付の言語(フィールド自体)は変更できますが、ピッカーの表示は変更されません。例えば

、このコードで

import React from "react"; 
import ReactDOM from "react-dom"; 

import DayPicker from "react-day-picker"; 

import MomentLocaleUtils from "react-day-picker/moment"; 

import "react-day-picker/lib/style.css"; 

import "moment/locale/he"; 

function LocalizedExample() { 
    return (
    <div> 
     <p>Hebrew</p> 
     <DayPicker localeUtils={MomentLocaleUtils} locale="he" /> 
    </div> 
); 
} 

ReactDOM.render(<LocalizedExample />, document.getElementById("root")); 

言語の変更としては、所望の、しかし(3行目)は、以下の変化に:

import DayPicker from "react-day-picker/DayPickerInput"; 

言語が英語のままです。

これを行う方法はありますか?

答えて

2

DayPickerInputdayPickerPropsと呼ばれる支柱を有する。私はあなたがそれを使う必要があると思う。

import { DayPickerInput } from 'react-day-picker'; 

<DayPickerInput dayPickerProps={{localeUtils: MomentLocaleUtils, locale:"he"}} /> 
2

あなたはdayPickerPropsとしてlocalelocaleUtilsを渡す必要がありますように見える:

import "react-day-picker/lib/style.css"; 

import "moment/locale/he"; 

function LocalizedExample() { 
    const dayPickerProps = { 
    localeUtils: MomentLocaleUtils, 
    locale: "he" 
    } 
    return (
    <div> 
     <p>Hebrew</p> 
     <DayPicker dayPickerProps={dayPickerProps} /> 
    </div> 
); 
} 

ReactDOM.render(<LocalizedExample />, document.getElementById("root")); 
関連する問題