Dynamic import of dayjs locale
This commit is contained in:
parent
a1677094f7
commit
6ed9c1e226
|
|
@ -90,19 +90,18 @@ const CalendarField = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let lang = i18n.language;
|
|
||||||
if (Array.from(supportedLocales).includes(i18n.language)) {
|
if (Array.from(supportedLocales).includes(i18n.language)) {
|
||||||
require(`dayjs/locale/${i18n.language}`);
|
import(`dayjs/locale/${i18n.language}.js`).then(() => {
|
||||||
dayjs.locale(i18n.language);
|
dayjs.locale(i18n.language);
|
||||||
lang = i18n.language;
|
if (weekStart !== dayjs.Ls[i18n.language].weekStart) {
|
||||||
|
dayjs.updateLocale(i18n.language, { weekStart });
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// Fallback
|
// Fallback
|
||||||
lang = 'en';
|
if (weekStart !== dayjs.Ls.en.weekStart) {
|
||||||
}
|
dayjs.updateLocale('en', { weekStart });
|
||||||
if (weekStart !== dayjs.Ls[lang].weekStart) {
|
}
|
||||||
dayjs.updateLocale(lang, {
|
|
||||||
weekStart,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
setDates(calculateMonth(month, year, weekStart));
|
setDates(calculateMonth(month, year, weekStart));
|
||||||
}, [weekStart, month, year, i18n.language]);
|
}, [weekStart, month, year, i18n.language]);
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,7 @@ const Event = (props) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (Array.from(supportedLocales).includes(i18n.language)) {
|
if (Array.from(supportedLocales).includes(i18n.language)) {
|
||||||
require(`dayjs/locale/${i18n.language}`);
|
import(`dayjs/locale/${i18n.language}.js`).then(() => dayjs.locale(i18n.language));
|
||||||
dayjs.locale(i18n.language);
|
|
||||||
}
|
}
|
||||||
}, [i18n.language]);
|
}, [i18n.language]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue