Skip to content

Commit 83d1a68

Browse files
committed
fix(i18n): pt_BR still not working
1 parent 449ab3a commit 83d1a68

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

apps/client/src/widgets/view_widgets/calendar_view.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Calendar, DateSelectArg, DatesSetArg, EventChangeArg, EventDropArg, EventInput, EventSourceFunc, EventSourceFuncArg, EventSourceInput, PluginDef } from "@fullcalendar/core";
1+
import type { Calendar, DateSelectArg, DatesSetArg, EventChangeArg, EventDropArg, EventInput, EventSourceFunc, EventSourceFuncArg, EventSourceInput, LocaleInput, PluginDef } from "@fullcalendar/core";
22
import froca from "../../services/froca.js";
33
import ViewMode, { type ViewModeArgs } from "./view_mode.js";
44
import type FNote from "../../entities/fnote.js";
@@ -15,6 +15,22 @@ import type { EventImpl } from "@fullcalendar/core/internal";
1515
import debounce, { type DebouncedFunction } from "debounce";
1616
import type { TouchBarItem } from "../../components/touch_bar.js";
1717
import type { SegmentedControlSegment } from "electron";
18+
import { LOCALE_IDS } from "@triliumnext/commons";
19+
20+
// Here we hard-code the imports in order to ensure that they are embedded by webpack without having to load all the languages.
21+
const LOCALE_MAPPINGS: Record<LOCALE_IDS, (() => Promise<{ default: LocaleInput }>) | null> = {
22+
de: () => import("@fullcalendar/core/locales/de"),
23+
es: () => import("@fullcalendar/core/locales/es"),
24+
fr: () => import("@fullcalendar/core/locales/fr"),
25+
cn: () => import("@fullcalendar/core/locales/zh-cn"),
26+
tw: () => import("@fullcalendar/core/locales/zh-tw"),
27+
ro: () => import("@fullcalendar/core/locales/ro"),
28+
ru: () => import("@fullcalendar/core/locales/ru"),
29+
ja: () => import("@fullcalendar/core/locales/ja"),
30+
"pt_br": () => import("@fullcalendar/core/locales/pt-br"),
31+
uk: () => import("@fullcalendar/core/locales/uk"),
32+
en: null
33+
};
1834

1935
const TPL = /*html*/`
2036
<div class="calendar-view">
@@ -657,31 +673,11 @@ export default class CalendarView extends ViewMode<{}> {
657673

658674
}
659675

660-
export async function getFullCalendarLocale(locale: string) {
661-
// Here we hard-code the imports in order to ensure that they are embedded by webpack without having to load all the languages.
662-
switch (locale) {
663-
case "de":
664-
return (await import("@fullcalendar/core/locales/de")).default;
665-
case "es":
666-
return (await import("@fullcalendar/core/locales/es")).default;
667-
case "fr":
668-
return (await import("@fullcalendar/core/locales/fr")).default;
669-
case "cn":
670-
return (await import("@fullcalendar/core/locales/zh-cn")).default;
671-
case "tw":
672-
return (await import("@fullcalendar/core/locales/zh-tw")).default;
673-
case "ro":
674-
return (await import("@fullcalendar/core/locales/ro")).default;
675-
case "ru":
676-
return (await import("@fullcalendar/core/locales/ru")).default;
677-
case "ja":
678-
return (await import("@fullcalendar/core/locales/ja")).default;
679-
case "pt_br":
680-
return (await import("@fullcalendar/core/locales/pt-br")).default;
681-
case "uk":
682-
return (await import("@fullcalendar/core/locales/uk")).default;
683-
case "en":
684-
default:
685-
return undefined;
676+
export async function getFullCalendarLocale(locale: LOCALE_IDS) {
677+
const correspondingLocale = LOCALE_MAPPINGS[locale];
678+
if (correspondingLocale) {
679+
return (await correspondingLocale()).default;
680+
} else {
681+
return undefined;
686682
}
687683
}

packages/commons/src/lib/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const UNSORTED_LOCALES: Locale[] = [
1616
{ id: "es", name: "Español", electronLocale: "es" },
1717
{ id: "fr", name: "Français", electronLocale: "fr" },
1818
{ id: "ja", name: "日本語", electronLocale: "ja" },
19-
{ id: "pt-BR", name: "Português (Brasil)", electronLocale: "pt_BR" },
19+
{ id: "pt_br", name: "Português (Brasil)", electronLocale: "pt_BR" },
2020
{ id: "ro", name: "Română", electronLocale: "ro" },
2121
{ id: "ru", name: "Русский", electronLocale: "ru" },
2222
{ id: "tw", name: "繁體中文", electronLocale: "zh_TW" },

0 commit comments

Comments
 (0)