Skip to content

Commit e21f970

Browse files
authored
UX: pass the current locale to FullCalendar (#458)
* UX: pass the current locale to FullCalendar * DEV: acceptance test
1 parent 6c65902 commit e21f970

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

assets/javascripts/discourse/initializers/discourse-calendar.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ function loadFullCalendar() {
2121
);
2222
}
2323

24+
function getCurrentBcp47Locale() {
25+
return I18n.currentLocale().replace("_", "-");
26+
}
27+
28+
function getCalendarButtonsText() {
29+
return {
30+
today: I18n.t("discourse_calendar.toolbar_button.today"),
31+
month: I18n.t("discourse_calendar.toolbar_button.month"),
32+
week: I18n.t("discourse_calendar.toolbar_button.week"),
33+
day: I18n.t("discourse_calendar.toolbar_button.day"),
34+
list: I18n.t("discourse_calendar.toolbar_button.list"),
35+
};
36+
}
37+
2438
let eventPopper;
2539
const EVENT_POPOVER_ID = "event-popover";
2640

@@ -124,7 +138,10 @@ function initializeDiscourseCalendar(api) {
124138
loadFullCalendar().then(() => {
125139
let fullCalendar = new window.FullCalendar.Calendar(
126140
categoryEventNode,
127-
{}
141+
{
142+
locale: getCurrentBcp47Locale(),
143+
buttonText: getCalendarButtonsText(),
144+
}
128145
);
129146
const loadEvents = ajax(
130147
`/discourse-post-event/events.json?category_id=${browsedCategory.id}`
@@ -284,6 +301,8 @@ function initializeDiscourseCalendar(api) {
284301
return new window.FullCalendar.Calendar($calendar[0], {
285302
timeZone,
286303
timeZoneImpl: "moment-timezone",
304+
locale: getCurrentBcp47Locale(),
305+
buttonText: getCalendarButtonsText(),
287306
nextDayThreshold: "06:00:00",
288307
displayEventEnd: true,
289308
height: 650,

config/locales/client.en.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ en:
299299
ve: "Venezuela"
300300
vi: "Virgin Islands (U.S.)"
301301
za: "South Africa"
302+
toolbar_button:
303+
today: "Today"
304+
month: "Month"
305+
week: "Week"
306+
day: "Day"
307+
list: "List"
302308
group_timezones:
303309
search: "Search..."
304310
group_availability: "%{group} availability"

test/javascripts/acceptance/category-events-calendar-test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
1+
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
22
import { test } from "qunit";
33
import { visit } from "@ember/test-helpers";
4+
import I18n from "discourse-i18n";
45

56
acceptance("Discourse Calendar - Category Events Calendar", function (needs) {
67
needs.user();
@@ -75,4 +76,18 @@ acceptance("Discourse Calendar - Category Events Calendar", function (needs) {
7576
.exists("Events calendar div exists.");
7677
assert.dom(".fc-view-container").exists("FullCalendar is loaded.");
7778
});
79+
80+
test("uses current locale to display calendar weekday names", async (assert) => {
81+
I18n.locale = "pt_BR";
82+
83+
await visit("/c/bug/1");
84+
85+
assert.deepEqual(
86+
[...queryAll(".fc-day-header span")].map((el) => el.innerText),
87+
["dom.", "seg.", "ter.", "qua.", "qui.", "sex.", "sáb."],
88+
"Week days are translated in the calendar header"
89+
);
90+
91+
I18n.locale = "en";
92+
});
7893
});

0 commit comments

Comments
 (0)