When applying locale like so:
const locale = {
name: 'nl',
todayLabel: {
long: 'Vandaag'
},
week: {
dow: 0 // week starts on sunday
},
months : "januari_februari_maart_april_mei_juni_juli_testing_september_oktober_november_december".split("_"),
monthsShort : "jan_feb_mar_apr_mei_jun_jul_tst_sep_okt_nov_dec".split("_"),
weekdays : "Zondag_Maandag_Dinsdag_Woensdag_Donderdag_Vrijdag_Zaterdag".split("_"),
weekdaysShort : "Zo_Ma_Di_Wo_Do_Vr_Za".split("_")
};
return (
<div>
<InfiniteCalendar
...
locale={locale}
/>
</div>
(I've changed "August" to "testing" and "Aug" to "tst")
The labels of the days of the week get translated correctly. However, the months do not:
(Note that the multiple dates come from my own fork with support for this, note that I didn't change anything related to locales)
When debugging your library I found that the locale is set correctly to moment.js
. E.g.:
index.js
updateLocale(locale) {
locale = this.getLocale(locale);
moment.updateLocale(locale.name, locale);
moment.locale(locale.name);
console.log('logging date format at init');
const date = moment();
console.log(date.format('MMM'));
}
will correctly output tst
But inside List/index.js:
renderMonth = ({index, isScrolling}) => {
let {...} = this.props;
let {date, rows} = this.memoize(months[index]);
console.log('logging date format at list render month');
const date2 = moment();
console.log(date.format('MMM'));
console.log(date2.format('MMM'));
Date2 (the newly created moment) is correct: tst
. However, the original date
coming from this.memoize
will be English (Aug
).
I believe this is because this date comes from another instance of moment.js inside util.js
utils.js
export function getMonth(monthDate) {
let rows = {};
let daysInMonth = monthDate.daysInMonth();
let year = monthDate.year();
let month = monthDate.month();
let week, date, lastWeekVal;
let weekIndex = -1;
for (let i = 0; i < daysInMonth; i++) {
date = moment(new Date(year,month,i+1)); //this moment.js does not have locale applied
....
But I have no apparent solution for now. What do you think is the cause of these different instances of moment? Do we need to re-apply locale every time moment.js is imported?