猿问

在反应日期上使用 moment.locale('de') 来显示德语翻译,但收到低于意外的输出

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


MYYA
浏览 374回答 2
2回答

catspeake

您需要使用moment-with-locale-es6模块作为名称所说的语言环境......普通模块只有英文如果没有任何代码示例,很难找出这里出了什么问题。我正在使用一个辅助函数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;

慕容森

&nbsp;class DateRangeWrapper extends React.PureComponent {&nbsp; render() {&nbsp; &nbsp; const {&nbsp; &nbsp; &nbsp; startDate,&nbsp; &nbsp; &nbsp; endDate,&nbsp; &nbsp; &nbsp; onDatesChange,&nbsp; &nbsp; &nbsp; focusedInput,&nbsp; &nbsp; &nbsp; onFocusChange,&nbsp; &nbsp; &nbsp; windowStyle,&nbsp; &nbsp; &nbsp; rangeSelect,&nbsp; &nbsp; &nbsp; blockpastDates,&nbsp; &nbsp; &nbsp; displayFormat,&nbsp; &nbsp; &nbsp; localelang,&nbsp; &nbsp; &nbsp; startDatePlaceholderText,&nbsp; &nbsp; &nbsp; endDatePlaceholderText,&nbsp; &nbsp; } = this.props;&nbsp; &nbsp; **moment.locale(`${localelang}`);**&nbsp; &nbsp; return (&nbsp; &nbsp; &nbsp; <div className="CalendarComponent">&nbsp; &nbsp; &nbsp; &nbsp; <div&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; className={&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; windowStyle === 'Popup'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ? windowStyle&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : classnames(windowStyle, 'inlineHeight')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <DateRangePicker&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {...rangeConfig}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; startDate={rangeSelect === 'fromPresent' ? moment() : startDate}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endDate={endDate}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onDatesChange={onDatesChange}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; focusedInput={focusedInput}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onFocusChange={onFocusChange}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; customArrowIcon={<ArrowIcon />}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; navPrev={<CalendarNavIcon direction="prev" />}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; navNext={<CalendarNavIcon direction="next" />}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isOutsideRange={&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blockpastDates ? day => moment().diff(day) > 0 : () => false&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; renderCalendarInfo={&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; windowStyle === 'Popup'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ? () => (&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <Controls&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; applyText={this.props.applyText}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelText={this.props.cancelText}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onDatePickerApply={this.props.onDatePickerApply}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onDatePickerClose={this.props.onDatePickerClose}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : () => {}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayFormat={displayFormat}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; startDatePlaceholderText={startDatePlaceholderText}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; endDatePlaceholderText={endDatePlaceholderText}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; />&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; );&nbsp; }}localelang 是一个属性,其值为 i18next.language 从使用此日期组件的组件传递
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答