0

我正在使用 react-dates,并且试图弄清楚如何将月份和工作日名称国际化。我已经想出了如何对输入占位符文本执行此操作,但我找不到如何执行此操作。

我给 react-dates 的当前道具DateRangePicker如下所示:

<DateRangePicker
        startDate={this.state.startDate} // momentPropTypes.momentObj or null,
        endDate={this.state.endDate} // momentPropTypes.momentObj or null,
        onDatesChange={({ startDate, endDate }) => {
            this.setState({ startDate, endDate });
            this.props.onDateChange(this.props.name, startDate, endDate);
          }
        } // PropTypes.func.isRequired,
        focusedInput={this.state.focusedInput} // PropTypes.oneOf([START_DATE, END_DATE]) or null,
        onFocusChange={focusedInput => this.setState({ focusedInput })} // PropTypes.func.isRequired,
        numberOfMonths={1}
        firstDayOfWeek={1}
        minimumNights={0}
        isOutsideRange={(x) => moment().add(1, 'days') < x }
        displayFormat="DD-MM-YYYY"
        showClearDates={true}
        startDatePlaceholderText={this.props.intl.formatMessage({id: 'DATE_PICKER_START_DATE'})}
        endDatePlaceholderText={this.props.intl.formatMessage({id: 'DATE_PICKER_END_DATE'})}
        hideKeyboardShortcutsPanel= {true}
      />

我正在使用react-intl国际化。

这是日历的样子: 日历的图像

基本上我要更改的是月份名称November和工作日名称Mo Tu We Th Fr Sa Su

期望的结果是将它们翻译成芬兰语 ->MarraskuuMa Ti Ke To Pe La Su

4

1 回答 1

1

我设法通过为日期选择器导入带有芬兰语的时刻和一些额外的道具来解决这个问题:

import React, { Component } from "react";
import {DateRangePicker} from 'react-dates';
import { injectIntl, intlShape } from "react-intl";
import moment from 'moment'
import 'moment/locale/fi';
import 'react-dates/initialize';
import 'react-dates/lib/css/_datepicker.css';

.
.
.

<DateRangePicker
    .
    .
    .
    renderMonthText={month => {
      month.locale(this.props.intl.locale)
      return(
        moment(month).format('MMMM YYYY')
      )
    }}
    renderDayContents={day => {
      day.local(this.props.intl.local)
      return(
        moment(day).format('D')
      )
    }}
  />
于 2019-01-24T07:42:16.317 回答