React-dates: DateRangePicker, locale, i18next

Created on 3 Apr 2018  路  7Comments  路  Source: airbnb/react-dates

Hi,

I'm using i18next languages to translate dynamically DateRangePicker:
moment.locale(i18n.language);
all days and format are changed with language , but months stay in English.

"react-dates": "16.4.0",
"react": "16.2.0",
"moment": "2.21.0",

question

Most helpful comment

// yarn add moment
// your locale - current -> turkish
// For german -> import deLocale from 'moment/locale/de';
import trLocale from 'moment/locale/tr';
import moment from 'moment';

render() {
// current -> turkish
// for german -> moment.locale('de', deLocale);
moment.locale('tr', trLocale);

return ( <DateRangePicker ........ />);
}

All 7 comments

@wijdench where in your component are you setting the locale? Is the issue that the text remains in English or that the format remains MMMM YYYY? This is how the month title is formatted --- https://github.com/airbnb/react-dates/blob/master/src/components/CalendarMonth.jsx#L167

Hi,

the issue is that the text remains in english.
i used the locale in render component

  render() {
moment.locale(i18n.language);
return (
<DateRangePicker
  startDate={this.state.startDate} 
  startDateId="start_date_id"
  endDate={this.state.endDate} 
  endDateId="end_date_id"
  onDatesChange={({ startDate, endDate }) => this.setState({ startDate, endDate })} 
  focusedInput={this.state.focusedInput}
  onFocusChange={focusedInput => this.setState({ focusedInput })} 
/>
);
}
// yarn add moment
// your locale - current -> turkish
// For german -> import deLocale from 'moment/locale/de';
import trLocale from 'moment/locale/tr';
import moment from 'moment';

render() {
// current -> turkish
// for german -> moment.locale('de', deLocale);
moment.locale('tr', trLocale);

return ( <DateRangePicker ........ />);
}

Hi,
Is there any updates in this issue.

thanks for your help.

// yarn add moment
// your locale - current -> turkish
// For german -> import deLocale from 'moment/locale/de';
import trLocale from 'moment/locale/tr';
import moment from 'moment';

render() {
// current -> turkish
// for german -> moment.locale('de', deLocale);
moment.locale('tr', trLocale);

return ( <DateRangePicker ........ />);
}

Thanks! Actually just the locale import fixed this for me: import "moment/locale/en-gb"; - I didn't need to set moment.locale("en-gb").

Guys, how change the input text 'Start Date' and 'End Date'?

Guys, how change the input text 'Start Date' and 'End Date'?

https://github.com/airbnb/react-dates#daterangepicker, look at the input related props.

Those could be,startDatePlaceholderText and endDatePlaceholderText.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaronvanston picture aaronvanston  路  3Comments

krissalvador27 picture krissalvador27  路  3Comments

maciej-w picture maciej-w  路  3Comments

arthurvi picture arthurvi  路  3Comments

mrseanbaines picture mrseanbaines  路  3Comments