From 83d1a68879f32ed7aa17b3f9a9e300c1a1c6b02e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 25 Aug 2025 23:32:20 +0300 Subject: [PATCH] fix(i18n): pt_BR still not working --- .../src/widgets/view_widgets/calendar_view.ts | 50 +++++++++---------- packages/commons/src/lib/i18n.ts | 2 +- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/apps/client/src/widgets/view_widgets/calendar_view.ts b/apps/client/src/widgets/view_widgets/calendar_view.ts index 8da330ed8..ff32474f1 100644 --- a/apps/client/src/widgets/view_widgets/calendar_view.ts +++ b/apps/client/src/widgets/view_widgets/calendar_view.ts @@ -1,4 +1,4 @@ -import type { Calendar, DateSelectArg, DatesSetArg, EventChangeArg, EventDropArg, EventInput, EventSourceFunc, EventSourceFuncArg, EventSourceInput, PluginDef } from "@fullcalendar/core"; +import type { Calendar, DateSelectArg, DatesSetArg, EventChangeArg, EventDropArg, EventInput, EventSourceFunc, EventSourceFuncArg, EventSourceInput, LocaleInput, PluginDef } from "@fullcalendar/core"; import froca from "../../services/froca.js"; import ViewMode, { type ViewModeArgs } from "./view_mode.js"; import type FNote from "../../entities/fnote.js"; @@ -15,6 +15,22 @@ import type { EventImpl } from "@fullcalendar/core/internal"; import debounce, { type DebouncedFunction } from "debounce"; import type { TouchBarItem } from "../../components/touch_bar.js"; import type { SegmentedControlSegment } from "electron"; +import { LOCALE_IDS } from "@triliumnext/commons"; + +// Here we hard-code the imports in order to ensure that they are embedded by webpack without having to load all the languages. +const LOCALE_MAPPINGS: Record Promise<{ default: LocaleInput }>) | null> = { + de: () => import("@fullcalendar/core/locales/de"), + es: () => import("@fullcalendar/core/locales/es"), + fr: () => import("@fullcalendar/core/locales/fr"), + cn: () => import("@fullcalendar/core/locales/zh-cn"), + tw: () => import("@fullcalendar/core/locales/zh-tw"), + ro: () => import("@fullcalendar/core/locales/ro"), + ru: () => import("@fullcalendar/core/locales/ru"), + ja: () => import("@fullcalendar/core/locales/ja"), + "pt_br": () => import("@fullcalendar/core/locales/pt-br"), + uk: () => import("@fullcalendar/core/locales/uk"), + en: null +}; const TPL = /*html*/`
@@ -657,31 +673,11 @@ export default class CalendarView extends ViewMode<{}> { } -export async function getFullCalendarLocale(locale: string) { - // 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 "ru": - return (await import("@fullcalendar/core/locales/ru")).default; - case "ja": - return (await import("@fullcalendar/core/locales/ja")).default; - case "pt_br": - return (await import("@fullcalendar/core/locales/pt-br")).default; - case "uk": - return (await import("@fullcalendar/core/locales/uk")).default; - case "en": - default: - return undefined; +export async function getFullCalendarLocale(locale: LOCALE_IDS) { + const correspondingLocale = LOCALE_MAPPINGS[locale]; + if (correspondingLocale) { + return (await correspondingLocale()).default; + } else { + return undefined; } } diff --git a/packages/commons/src/lib/i18n.ts b/packages/commons/src/lib/i18n.ts index ff435de78..d40f5ecc5 100644 --- a/packages/commons/src/lib/i18n.ts +++ b/packages/commons/src/lib/i18n.ts @@ -16,7 +16,7 @@ const UNSORTED_LOCALES: Locale[] = [ { id: "es", name: "Español", electronLocale: "es" }, { id: "fr", name: "Français", electronLocale: "fr" }, { id: "ja", name: "日本語", electronLocale: "ja" }, - { id: "pt-BR", name: "Português (Brasil)", electronLocale: "pt_BR" }, + { id: "pt_br", name: "Português (Brasil)", electronLocale: "pt_BR" }, { id: "ro", name: "Română", electronLocale: "ro" }, { id: "ru", name: "Русский", electronLocale: "ru" }, { id: "tw", name: "繁體中文", electronLocale: "zh_TW" },