From 22aae94936bb8b285892a7f6d8bf667c852739e3 Mon Sep 17 00:00:00 2001 From: Leopoldthecoder Date: Mon, 7 Aug 2017 10:48:09 +0800 Subject: [PATCH] DatePicker: fix fecha i18n not responsive --- packages/date-picker/src/util/index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/date-picker/src/util/index.js b/packages/date-picker/src/util/index.js index 96d2cadbb..1d9ac9953 100644 --- a/packages/date-picker/src/util/index.js +++ b/packages/date-picker/src/util/index.js @@ -3,12 +3,13 @@ import { t } from 'element-ui/src/locale'; const weeks = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; const months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']; - -dateUtil.i18n = { - dayNamesShort: weeks.map(week => t(`el.datepicker.weeks.${ week }`)), - dayNames: weeks.map(week => t(`el.datepicker.weeks.${ week }`)), - monthNamesShort: months.map(month => t(`el.datepicker.months.${ month }`)), - monthNames: months.map((month, index) => t(`el.datepicker.month${ index + 1 }`)) +const getI18nSettings = () => { + return { + dayNamesShort: weeks.map(week => t(`el.datepicker.weeks.${ week }`)), + dayNames: weeks.map(week => t(`el.datepicker.weeks.${ week }`)), + monthNamesShort: months.map(month => t(`el.datepicker.months.${ month }`)), + monthNames: months.map((month, index) => t(`el.datepicker.month${ index + 1 }`)) + }; }; const newArray = function(start, end) { @@ -36,11 +37,11 @@ export const isDate = function(date) { export const formatDate = function(date, format) { date = toDate(date); if (!date) return ''; - return dateUtil.format(date, format || 'yyyy-MM-dd'); + return dateUtil.format(date, format || 'yyyy-MM-dd', getI18nSettings()); }; export const parseDate = function(string, format) { - return dateUtil.parse(string, format || 'yyyy-MM-dd'); + return dateUtil.parse(string, format || 'yyyy-MM-dd', getI18nSettings()); }; export const getDayCountOfMonth = function(year, month) {