From af67362ad65e699c948020469dd4e2225ad72d22 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 23 Oct 2024 19:34:09 +0300 Subject: [PATCH] server: Translate weekday and month names --- src/services/date_notes.ts | 14 ++++++++++---- translations/en/server.json | 23 +++++++++++++++++++++++ translations/ro/server.json | 23 +++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/services/date_notes.ts b/src/services/date_notes.ts index 465757328..3f355f429 100644 --- a/src/services/date_notes.ts +++ b/src/services/date_notes.ts @@ -9,14 +9,20 @@ import searchService from "../services/search/services/search.js"; import SearchContext from "../services/search/search_context.js"; import hoistedNoteService from "./hoisted_note.js"; import BNote from "../becca/entities/bnote.js"; +import { t } from "i18next"; const CALENDAR_ROOT_LABEL = 'calendarRoot'; const YEAR_LABEL = 'yearNote'; const MONTH_LABEL = 'monthNote'; const DATE_LABEL = 'dateNote'; -const DAYS = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']; -const MONTHS = ['January','February','March','April','May','June','July','August','September','October','November','December']; +const WEEKDAY_TRANSLATION_IDS = [ + "weekdays.sunday", "weekdays.monday", "weekdays.tuesday", "weekdays.wednesday", "weekdays.thursday", "weekdays.friday", "weekdays.saturday", "weekdays.sunday" +]; + +const MONTH_TRANSLATION_IDS = [ + "months.january", "months.february", "months.march", "months.april", "months.may", "months.june", "months.july", "months.august", "months.september", "months.october", "months.november", "months.december" +]; type StartOfWeek = "monday" | "sunday"; @@ -92,7 +98,7 @@ function getYearNote(dateStr: string, _rootNote: BNote | null = null): BNote { function getMonthNoteTitle(rootNote: BNote, monthNumber: string, dateObj: Date) { const pattern = rootNote.getOwnedLabelValue("monthPattern") || "{monthNumberPadded} - {month}"; - const monthName = MONTHS[dateObj.getMonth()]; + const monthName = t(MONTH_TRANSLATION_IDS[dateObj.getMonth()]); return pattern .replace(/{shortMonth3}/g, monthName.slice(0,3)) @@ -138,7 +144,7 @@ function getMonthNote(dateStr: string, _rootNote: BNote | null = null): BNote { function getDayNoteTitle(rootNote: BNote, dayNumber: string, dateObj: Date) { const pattern = rootNote.getOwnedLabelValue("datePattern") || "{dayInMonthPadded} - {weekDay}"; - const weekDay = DAYS[dateObj.getDay()]; + const weekDay = t(WEEKDAY_TRANSLATION_IDS[dateObj.getDay()]); return pattern .replace(/{ordinal}/g, ordinal(parseInt(dayNumber))) diff --git a/translations/en/server.json b/translations/en/server.json index 3d8a46e55..68de4c6f0 100644 --- a/translations/en/server.json +++ b/translations/en/server.json @@ -157,5 +157,28 @@ "clipped-from": "This note was originally clipped from {{- url}}", "child-notes": "Child notes:", "no-content": "This note has no content." + }, + "weekdays": { + "monday": "Monday", + "tuesday": "Tuesday", + "wednesday": "Wednesday", + "thursday": "Thursday", + "friday": "Friday", + "saturday": "Saturday", + "sunday": "Sunday" + }, + "months": { + "january": "January", + "february": "February", + "march": "March", + "april": "April", + "may": "May", + "june": "June", + "july": "July", + "august": "August", + "september": "September", + "october": "October", + "november": "November", + "december": "December" } } diff --git a/translations/ro/server.json b/translations/ro/server.json index b71a9b34d..053823a57 100644 --- a/translations/ro/server.json +++ b/translations/ro/server.json @@ -157,5 +157,28 @@ "clipped-from": "Această notiță a fost decupată inițial de pe {{- url}}", "no-content": "Această notiță nu are conținut.", "parent": "părinte:" + }, + "weekdays": { + "monday": "Luni", + "tuesday": "Marți", + "wednesday": "Miercuri", + "thursday": "Joi", + "friday": "Vineri", + "saturday": "Sâmbătă", + "sunday": "Duminică" + }, + "months": { + "january": "Ianuarie", + "february": "Februarie", + "march": "Martie", + "april": "Aprilie", + "may": "Mai", + "june": "Iunie", + "july": "Iulie", + "august": "August", + "september": "Septembrie", + "october": "Octombrie", + "november": "Noiembrie", + "december": "Decembrie" } }