diff --git a/crabfit-frontend/src/components/CalendarField/CalendarField.tsx b/crabfit-frontend/src/components/CalendarField/CalendarField.tsx index 3e46b56..2892269 100644 --- a/crabfit-frontend/src/components/CalendarField/CalendarField.tsx +++ b/crabfit-frontend/src/components/CalendarField/CalendarField.tsx @@ -19,7 +19,7 @@ import { Day, } from './calendarFieldStyle'; -import supportedLocales from 'res/dayjs_locales.json'; +import localeImports from 'res/dayjs_locales'; dayjs.extend(isToday); dayjs.extend(localeData); @@ -90,8 +90,8 @@ const CalendarField = ({ }; useEffect(() => { - if (Array.from(supportedLocales).includes(i18n.language)) { - import(`dayjs/locale/${i18n.language}.js`).then(() => { + if (Object.keys(localeImports).includes(i18n.language)) { + localeImports[i18n.language]().then(() => { dayjs.locale(i18n.language); if (weekStart !== dayjs.Ls[i18n.language].weekStart) { dayjs.updateLocale(i18n.language, { weekStart }); diff --git a/crabfit-frontend/src/pages/Event/Event.tsx b/crabfit-frontend/src/pages/Event/Event.tsx index c12b97f..d7f6674 100644 --- a/crabfit-frontend/src/pages/Event/Event.tsx +++ b/crabfit-frontend/src/pages/Event/Event.tsx @@ -39,7 +39,7 @@ import { useSettingsStore, useRecentsStore } from 'stores'; import logo from 'res/logo.svg'; import timezones from 'res/timezones.json'; -import supportedLocales from 'res/dayjs_locales.json'; +import localeImports from 'res/dayjs_locales'; dayjs.extend(utc); dayjs.extend(timezone); @@ -76,8 +76,8 @@ const Event = (props) => { const [copied, setCopied] = useState(null); useEffect(() => { - if (Array.from(supportedLocales).includes(i18n.language)) { - import(`dayjs/locale/${i18n.language}.js`).then(() => dayjs.locale(i18n.language)); + if (Object.keys(localeImports).includes(i18n.language)) { + localeImports[i18n.language]().then(() => dayjs.locale(i18n.language)); } }, [i18n.language]); diff --git a/crabfit-frontend/src/res/dayjs_locales.js b/crabfit-frontend/src/res/dayjs_locales.js new file mode 100644 index 0000000..51307f3 --- /dev/null +++ b/crabfit-frontend/src/res/dayjs_locales.js @@ -0,0 +1,8 @@ +const locales = { + en: () => import('dayjs/locale/en'), + de: () => import('dayjs/locale/de'), + es: () => import('dayjs/locale/es'), + ko: () => import('dayjs/locale/ko'), +}; + +export default locales;