React-dates: Month name not updating on language change

Created on 12 Feb 2017  路  8Comments  路  Source: airbnb/react-dates

When I change my moment.locale() the days of the calendar update but month names don't unless I completely re-render my page. Is there something special about the way that calendar months are handled that I'm missing?

screen shot 2017-02-12 at 15 43 26

bug pull request wanted

Most helpful comment

If anyone is still struggling to get the month names to translate when switching back and forth between different locales, I came up with a workaround. Add the following as a prop to DateRangePicker:

// `language` being the desired locale
renderMonthElement={({ month }) => moment(month).locale(language).format('MMMM YYYY')}

The moment objects internal to the component don't seem to get updated when changing moment's locale (even a re-render doesn't fix it). Hope it helps!

All 8 comments

It seems we should probably be caching and checking the moment locale in shouldComponentUpdate (and anything else stateful about the moment singleton) on all our components.

@oldo how do you change the moment.locale()?
I'm trying a way to do it as well, but I don't find how .-.

Thank you @majapw, it is easier than I have thought (-;

If anyone is still struggling to get the month names to translate when switching back and forth between different locales, I came up with a workaround. Add the following as a prop to DateRangePicker:

// `language` being the desired locale
renderMonthElement={({ month }) => moment(month).locale(language).format('MMMM YYYY')}

The moment objects internal to the component don't seem to get updated when changing moment's locale (even a re-render doesn't fix it). Hope it helps!

Workaround from @ian-rudge works! 馃殌

But I am having same issue with month representation in the input. Any workaround for that?

a medal of honor to @ian-rudge

@ian-rudge You are awesome
Thanks :)

Was this page helpful?
0 / 5 - 0 ratings