Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I pass dynamic locale for dateRangePicker When I use 'moment/min/locales' working instead of moment #196

Closed
srivathsa-kavirayuni opened this issue Jan 28, 2019 · 1 comment

Comments

@srivathsa-kavirayuni
Copy link

How can I pass locales dynamically to DateRangePicker to get those formats where as I'm using moment/min/locales for locale changing. when I import 'moment' and trying to change moment.locale() it is not working. So is there any way to change the locale in DateRangePicker.
Here is my code
<DateRangePicker startDate={this.props.startDate} endDate={this.props.endDate} maxDate={moment()} ranges={config(this.props.l)} onEvent={this.handleEvent} opens="left" locale={{ format: dateFormatBasedOnCountry[this.props.langCode.toUpperCase()], cancelLabel: this.props.l('Cancel'), applyLabel: this.props.l('Apply'), customRangeLabel: this.props.l('Custom Range'), }} key={this.state.isTransChanged ? date-range-picker-${this.state.index++} : undefined} // added key to remount // the component for translations >

@Algo87
Copy link

Algo87 commented Jan 9, 2024

Maybe it will be useful for someone

If you need to set local dynemic in react-bootstrap-daterangepicker you can set it in initialSettings.locale like this
const [lang, setLang] = useState(getCookie(authConstants.language) || "en");
initialSettings={{
startDate: period[0], endDate: period[1],
locale: {
locale: moment.locale(lang), // lang
cancelLabel: t("cancel"),
applyLabel: t("apply"),
format: "DD.MM.YYYY"
},
}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants