From 0d317671b0d28828dd60b9f5e694b8260bbb2a6c Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Mon, 3 Feb 2020 15:37:15 -0800 Subject: [PATCH 1/2] fix(date-picker): move l10n customization to createCalendar --- src/components/DatePicker/createCalendar.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/DatePicker/createCalendar.js b/src/components/DatePicker/createCalendar.js index ae400bbd..e8a33ceb 100644 --- a/src/components/DatePicker/createCalendar.js +++ b/src/components/DatePicker/createCalendar.js @@ -3,13 +3,6 @@ import l10n from 'flatpickr/dist/l10n/index.js'; import rangePlugin from 'flatpickr/dist/plugins/rangePlugin'; import { cx } from '../../lib'; -if (l10n.en) { - l10n.en.weekdays.shorthand.forEach((_, index) => { - const shorthand = _.slice(0, 2); - l10n.en.weekdays.shorthand[index] = shorthand === 'Th' ? 'Th' : shorthand.charAt(0); - }); -} - function updateClasses(instance) { const { calendarContainer, days, daysContainer, weekdayContainer, selectedDates } = instance; @@ -48,12 +41,23 @@ function updateMonthNode(instance) { } function createCalendar({ options, base, input, dispatch }) { + let locale = options.locale; + + if (l10n.en) { + l10n.en.weekdays.shorthand.forEach((_, index) => { + const shorthand = _.slice(0, 2); + l10n.en.weekdays.shorthand[index] = shorthand === 'Th' ? 'Th' : shorthand.charAt(0); + }); + + locale = l10n.en; + } + return new flatpickr(base, { ...options, allowInput: true, disableMobile: true, clickOpens: true, - locale: l10n[options.locale], + locale, plugins: [options.mode === 'range' && new rangePlugin({ position: 'left', input })].filter( Boolean ), From ac0c54943c0661ca329f83b2101514e531f0790f Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Mon, 3 Feb 2020 15:39:12 -0800 Subject: [PATCH 2/2] chore(date-picker): only modify if locale is "en" --- src/components/DatePicker/createCalendar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/DatePicker/createCalendar.js b/src/components/DatePicker/createCalendar.js index e8a33ceb..4d0f4d6d 100644 --- a/src/components/DatePicker/createCalendar.js +++ b/src/components/DatePicker/createCalendar.js @@ -43,7 +43,7 @@ function updateMonthNode(instance) { function createCalendar({ options, base, input, dispatch }) { let locale = options.locale; - if (l10n.en) { + if (options.locale === 'en' && l10n && l10n.en) { l10n.en.weekdays.shorthand.forEach((_, index) => { const shorthand = _.slice(0, 2); l10n.en.weekdays.shorthand[index] = shorthand === 'Th' ? 'Th' : shorthand.charAt(0);