From f8c3587717410fa1e597385ca6ba67d465267150 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 15 Feb 2025 21:45:53 +0200 Subject: [PATCH] feat(view/calendar): add locale support --- .../app/widgets/view_widgets/calendar_view.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/public/app/widgets/view_widgets/calendar_view.ts b/src/public/app/widgets/view_widgets/calendar_view.ts index ebb987839..3d477b26b 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.ts @@ -84,13 +84,37 @@ export default class CalendarView extends ViewMode { day: t("calendar_view.day"), list: t("calendar_view.list") }, - firstDay: options.getInt("firstDayOfWeek") ?? 0 + firstDay: options.getInt("firstDayOfWeek") ?? 0, + locale: await CalendarView.#getLocale() }); calendar.render(); return this.$root; } + static async #getLocale() { + const locale = options.get("locale"); + + // Here we hard-code the imports in order to ensure that they are embedded by webpack without having to load all the languages. + switch (locale) { + case "de": + return (await import("@fullcalendar/core/locales/de")).default; + case "es": + return (await import("@fullcalendar/core/locales/es")).default; + case "fr": + return (await import("@fullcalendar/core/locales/fr")).default; + case "cn": + return (await import("@fullcalendar/core/locales/zh-cn")).default; + case "tw": + return (await import("@fullcalendar/core/locales/zh-tw")).default; + case "ro": + return (await import("@fullcalendar/core/locales/ro")).default; + case "en": + default: + return undefined; + } + } + async #onEventMoved(e: EventChangeArg) { const startDate = CalendarView.#formatDateToLocalISO(e.event.start); let endDate = CalendarView.#formatDateToLocalISO(e.event.end);