fix(calendar): missing locale for Russian

This commit is contained in:
Elian Doran 2025-08-12 14:58:39 +03:00
parent b371337ed2
commit 8e4691d4a4
No known key found for this signature in database
2 changed files with 44 additions and 25 deletions

View File

@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { buildNote, buildNotes } from "../../test/easy-froca.js";
import CalendarView from "./calendar_view.js";
import CalendarView, { getFullCalendarLocale } from "./calendar_view.js";
import { LOCALES } from "@triliumnext/commons";
describe("Building events", () => {
it("supports start date", async () => {
@ -174,3 +175,21 @@ describe("Promoted attributes", () => {
});
});
describe("Building locales", () => {
it("every language has a locale defined", async () => {
for (const { id, contentOnly } of LOCALES) {
if (contentOnly) {
continue;
}
const fullCalendarLocale = await getFullCalendarLocale(id);
if (id !== "en") {
expect(fullCalendarLocale, `For locale ${id}`).toBeDefined();
} else {
expect(fullCalendarLocale).toBeUndefined();
}
}
});
});

View File

@ -166,7 +166,7 @@ export default class CalendarView extends ViewMode<{}> {
firstDay: options.getInt("firstDayOfWeek") ?? 0,
weekends: !this.parentNote.hasAttribute("label", "calendar:hideWeekends"),
weekNumbers: this.parentNote.hasAttribute("label", "calendar:weekNumbers"),
locale: await CalendarView.#getLocale(),
locale: await getFullCalendarLocale(options.get("locale")),
height: "100%",
nowIndicator: true,
handleWindowResize: false,
@ -246,29 +246,6 @@ export default class CalendarView extends ViewMode<{}> {
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;
}
}
#onDatesSet(e: DatesSetArg) {
const currentView = e.view.type;
if (currentView === this.lastView) {
@ -679,3 +656,26 @@ 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 "en":
default:
return undefined;
}
}