Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在react日期上使用moment.locale(';de';)显示德语翻译,但收到以下意外输出_Javascript_Reactjs_Momentjs_React Dates - Fatal编程技术网

Javascript 在react日期上使用moment.locale(';de';)显示德语翻译,但收到以下意外输出

Javascript 在react日期上使用moment.locale(';de';)显示德语翻译,但收到以下意外输出,javascript,reactjs,momentjs,react-dates,Javascript,Reactjs,Momentjs,React Dates,在反应日期的render方法下使用moment.locale('de')显示德语翻译,但收到以下意外输出,但在刷新时,它会一次又一次地呈现正确的翻译 您需要使用moment-with-locale-es6模块,正如名称所说,它与locale一起使用。。。普通模块只有英语 如果没有任何代码示例,很难找出这里出了什么问题 我正在使用一个helper函数返回一个新的moment对象,该对象具有我的i18n模块中设置的当前区域设置,它的工作方式很好 也许有帮助。这是我的助手 import moment

在反应日期的render方法下使用moment.locale('de')显示德语翻译,但收到以下意外输出,但在刷新时,它会一次又一次地呈现正确的翻译

您需要使用
moment-with-locale-es6
模块,正如名称所说,它与locale一起使用。。。普通模块只有英语

如果没有任何代码示例,很难找出这里出了什么问题

我正在使用一个helper函数返回一个新的
moment
对象,该对象具有我的
i18n
模块中设置的当前区域设置,它的工作方式很好

也许有帮助。这是我的助手

import moment from 'moment-with-locales-es6';
import i18n from './i18n';

const momentWithLocale = (...args) => {
  moment.locale(i18n.locale);
  return moment(...args);
};

export default momentWithLocale;

类DateRangeWrapper扩展了React.PureComponent{
render(){
常数{
开始日期,
结束日期,
翁达特桑奇,
聚焦输入,
onFocusChange,
窗口样式,
rangeSelect,
大块的过去日期,
显示格式,
本地语言,
StartDatePlaceholder文本,
EndDatePlaceholder文本,
}=这是道具;
**locale(`${localelang}`)**
返回(
力矩().diff(日)>0:()=>false
}
renderCalendarInfo={
WindowsStyle==='弹出窗口'
? () => (
)
: () => {}
}
displayFormat={displayFormat}
startDatePlaceholderText={startDatePlaceholderText}
endDatePlaceholderText={endDatePlaceholderText}
/>
);
}
}
localelang是一个prop,其值为i18next.language,从使用此日期组件的组件传递


您是导入
moment-with-locale-es6
模块还是导入正常的
moment
模块?您需要使用
moment-with-locale-es6
模块,正如名称所说,它与locale一起使用。。。普通模块只有英语
 class DateRangeWrapper extends React.PureComponent {
  render() {
    const {
      startDate,
      endDate,
      onDatesChange,
      focusedInput,
      onFocusChange,
      windowStyle,
      rangeSelect,
      blockpastDates,
      displayFormat,
      localelang,
      startDatePlaceholderText,
      endDatePlaceholderText,
    } = this.props;
    **moment.locale(`${localelang}`);**
    return (
      <div className="CalendarComponent">
        <div
          className={
            windowStyle === 'Popup'
              ? windowStyle
              : classnames(windowStyle, 'inlineHeight')
          }
        >
          <DateRangePicker
            {...rangeConfig}
            startDate={rangeSelect === 'fromPresent' ? moment() : startDate}
            endDate={endDate}
            onDatesChange={onDatesChange}
            focusedInput={focusedInput}
            onFocusChange={onFocusChange}
            customArrowIcon={<ArrowIcon />}
            navPrev={<CalendarNavIcon direction="prev" />}
            navNext={<CalendarNavIcon direction="next" />}
            isOutsideRange={
              blockpastDates ? day => moment().diff(day) > 0 : () => false
            }
            renderCalendarInfo={
              windowStyle === 'Popup'
                ? () => (
                  <Controls
                    applyText={this.props.applyText}
                    cancelText={this.props.cancelText}
                    onDatePickerApply={this.props.onDatePickerApply}
                    onDatePickerClose={this.props.onDatePickerClose}
                  />
                  )
                : () => {}
            }
            displayFormat={displayFormat}
            startDatePlaceholderText={startDatePlaceholderText}
            endDatePlaceholderText={endDatePlaceholderText}
          />
        </div>
      </div>
    );
  }
}