Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to change FullCalendar locale #491

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"color": "^4.2.1",
"dav": "^1.8.0",
"deep-equal": "^2.1.0",
"get-user-locale": "^2.3.0",
"ical": "^0.8.0",
"ical.js": "^1.5.0",
"luxon": "^2.3.0",
Expand Down
3 changes: 3 additions & 0 deletions src/ui/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface ExtraRenderProps {
firstDay?: number;
initialView?: { desktop: string; mobile: string };
timeFormat24h?: boolean;
locale?: string;
openContextMenuForEvent?: (
event: EventApi,
mouseEvent: MouseEvent
Expand Down Expand Up @@ -220,6 +221,8 @@ export function renderCalendar(
},

longPressDelay: 250,

locale: settings?.locale,
});
cal.render();
return cal;
Expand Down
26 changes: 26 additions & 0 deletions src/ui/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { createElement } from "react";
import { getDailyNoteSettings } from "obsidian-daily-notes-interface";
import ReactModal from "./ReactModal";
import { importCalendars } from "src/calendars/parsing/caldav/import";
import allLocales from "@fullcalendar/core/locales-all";
import { getUserLocales } from "get-user-locale";

export interface FullCalendarSettings {
calendarSources: CalendarInfo[];
Expand All @@ -26,6 +28,7 @@ export interface FullCalendarSettings {
mobile: string;
};
timeFormat24h: boolean;
locale?: string;
}

export const DEFAULT_SETTINGS: FullCalendarSettings = {
Expand All @@ -37,8 +40,14 @@ export const DEFAULT_SETTINGS: FullCalendarSettings = {
mobile: "timeGrid3Days",
},
timeFormat24h: false,
locale: defaultLocale(),
};

function defaultLocale(): string {
const userLocale = getUserLocales()[0].toLowerCase();
return allLocales.find((l) => l.code === userLocale)?.code || "en";
}

const WEEKDAYS = [
"Sunday",
"Monday",
Expand Down Expand Up @@ -231,6 +240,23 @@ export class FullCalendarSettingTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName("Locale")
.setDesc("Choose locale for date formats and language.")
.addDropdown((dropdown) => {
dropdown.addOption("en", "en-us");
allLocales.forEach((locale) => {
dropdown.addOption(locale.code, locale.code);
});
dropdown.setValue(
this.plugin.settings.locale || defaultLocale()
);
dropdown.onChange(async (locale) => {
this.plugin.settings.locale = locale;
await this.plugin.saveSettings();
});
});

containerEl.createEl("h2", { text: "Manage Calendars" });
addCalendarButton(
this.app,
Expand Down
1 change: 1 addition & 0 deletions src/ui/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class CalendarView extends ItemView {
firstDay: this.plugin.settings.firstDay,
initialView: this.plugin.settings.initialView,
timeFormat24h: this.plugin.settings.timeFormat24h,
locale: this.plugin.settings.locale,
openContextMenuForEvent: async (e, mouseEvent) => {
const menu = new Menu();
if (!this.plugin.cache) {
Expand Down