When developing with Vite + Moment, the date selector cannot be normally internationalized. It may be that you use the Import ‘Moment/LOCALE/zh-cn’ directly from the translation package introduced from the/local folder to Import ‘Moment /distal/local/zh-cn ‘to introduce translation files from the/different folder
// Import 'Moment/LOCALE/ZH-CN';
Import 'Moment/Dist/Locale/ZH-CN'; // Use Moment/SRC/LOCALE/ZH-CN
The reason, let’s open these two translation packages to compare their differences:
first look at Moment \ LOCALE \ zh-cn.js, we see that this is a UMD version:
// moment \ locale \ zh-cn.js
; (Function (Global, Factory) {
Typeof Exports === 'Object' && Typeof Module! == 'Undefined' && Typeof Require === 'Function'
What's more?
Factory (Require ('../ Moment'))
Intersection
Typeof Define === 'Function' && Define.amd
What's more?
define (['../ Moment'], Factory)
Intersection
Factory (global.moment)
} (this, (function (moment) {'use strict';
//! Moment.js locale configuration
var zhcn = Moment.definelocale ('zh-cn', {
Months: 'January_Elected_Elected _ March_Embly -May _ June _ July_Au August_Sepan _ October _ December _ December (' _ '),
monthsshort: 'January _ February _ March_Elected _ May _ June _ July _ September _ October _ November _ December' .split ('_'),
weekdays: 'Sunday_ Monday_ Tuesday_Wedon _ Thursday_ Thursday _ Saturday' .split ('_'),
weekdaysshort: 'Sunday_ Monday_Sperture _ Thursday _ Thursday _ Friday _ Saturday' .split ('_'),
weekdaysmin: 'day
longdateFormat: {...},
Meridiemparse: /Morning | morning | morning | Noon | Innate /evening /,
Meridiemhour: Function (Hour, Meridiem) {...},
Meridiem: Function (Hour, Minute, Islower) {...},
Calendar: {...},
dayofmonthordinalpars: /\ d {1,2} (day | month | week) /,
Ordinal: Function (Number, Period) {...},
Relativetime: {...},
Week: {...},
});
Return zhcn;
}));
Take a look at Moment \ SRC \ LOCALE \ zh-cn.js, obviously an ESM dependencies:
// moment \ src \ local \ zh-cn.js
Import mom from '../moment';
export default moment.definelocale ('zh-cn', {
Months: 'January_Elected_Elected _ March_Embly -May _ June _ July_Au August_Sepan _ October _ December _ December (' _ '),
monthsshort: 'January _ February _ March_Elected _ May _ June _ July _ September _ October _ November _ December' .split ('_'),
weekdays: 'Sunday_ Monday_ Tuesday_Wedon _ Thursday_ Thursday _ Saturday' .split ('_'),
weekdaysshort: 'Sunday_ Monday_Sperture _ Thursday _ Thursday _ Friday _ Saturday' .split ('_'),
weekdaysmin: 'day
longdateFormat: {...},
Meridiemparse: /Morning | morning | morning | Noon | Innate /evening /,
Meridiemhour: Function (Hour, Meridiem) {...},
Meridiem: Function (Hour, Minute, Islower) {...},
Calendar: {...},
dayofmonthordinalpars: /\ d {1,2} (day | month | week) /,
Ordinal: Function (Number, Period) {...},
Relativetime: {...},
Week: {...},
});
What should I do? Let’s take a look at the solution given by the big brothers:
You understand me … no, do you understand what he meant?