在反应日期的渲染方法下使用 moment.locale('de') 以显示德语翻译,但收到低于意外输出但在刷新时一次又一次地呈现正确的翻译
问问题
365 次
2 回答
0
您需要使用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;
于 2019-10-01T09:33:27.430 回答
0
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>
);
}
}
localelang 是一个 prop,其值为 i18next.language 从使用此日期组件的组件传递
于 2019-10-01T09:47:06.933 回答