diff --git a/src/components/topbar/StatusAlerts.vue b/src/components/topbar/StatusAlerts.vue index 45a7ce1ca93..d22fe2c821b 100644 --- a/src/components/topbar/StatusAlerts.vue +++ b/src/components/topbar/StatusAlerts.vue @@ -36,10 +36,21 @@ > {{ $t("common.labels.createAt") }} - {{ formatDate(item.createdAt) }} + {{ + formatDate(item.createdAt).value + ? formatDate(item.createdAt).value + + " " + + $t(formatDate(item.createdAt).key) + : formatDate(item.createdAt).key + }} @@ -67,7 +78,7 @@ export default defineComponent({ : { icon: mdiInformation, color: "info" }; }; - const formatDate = (dateTime: string) => { + const formatDate = (dateTime: any) => { return fromNow(dateTime, true); }; diff --git a/src/locales/de.json b/src/locales/de.json index f0274ba9a5c..353f15a111d 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -25,6 +25,11 @@ "common.labels.admin": "Admin(s)", "common.labels.updateAt": "Aktualisiert:", "common.labels.createAt": "Erstellt:", + "common.labels.minutes": "Vor Minuten", + "common.labels.hour": "Vor einer Stunde", + "common.labels.hours": "Vor Stunden", + "common.labels.day": "vor einem Tag", + "common.labels.days": "vor Tagen", "common.labels.birthdate": "Geburtsdatum", "common.labels.birthday": "Geburtsdatum", "common.labels.classes": "Klasse(n)", diff --git a/src/locales/en.json b/src/locales/en.json index 667edf9edb2..fb48d8d1c03 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -25,6 +25,11 @@ "common.labels.admin": "", "common.labels.updateAt": "Updated:", "common.labels.createAt": "Created:", + "common.labels.minutes": "Minutes ago", + "common.labels.hour": "Hour ago", + "common.labels.hours": "Hours ago", + "common.labels.day": "Day ago", + "common.labels.days": "Days ago", "common.labels.birthdate": "Date of birth", "common.labels.birthday": "Date of Birth", "common.labels.classes": "classes", diff --git a/src/locales/es.json b/src/locales/es.json index 17bcc6b0140..26e399ad227 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -25,6 +25,11 @@ "common.labels.admin": "Admin(s)", "common.labels.updateAt": "Actualizado:", "common.labels.createAt": "Creado:", + "common.labels.minutes": "Minutos", + "common.labels.hour": "Hora", + "common.labels.hours": "Horas", + "common.labels.day": "Dia", + "common.labels.days": "Dias", "common.labels.birthdate": "Fecha de nacimiento", "common.labels.birthday": "Fecha de nacimiento", "common.labels.classes": "clases", diff --git a/src/locales/uk.json b/src/locales/uk.json index c773aba99a8..d07f8c756ff 100644 --- a/src/locales/uk.json +++ b/src/locales/uk.json @@ -26,6 +26,11 @@ "common.labels.birthdate": "Дата народження", "common.labels.updateAt": "Оновлено:", "common.labels.createAt": "Створено:", + "common.labels.minutes": "Кілька хвилин тому", + "common.labels.hour": "Годину тому", + "common.labels.hours": "Кілька годин тому", + "common.labels.day": "День тому", + "common.labels.days": "Кілька днів тому", "common.labels.birthday": "Дата народження", "common.labels.classes": "класи", "common.labels.close": "Закрити", diff --git a/src/plugins/datetime.js b/src/plugins/datetime.js index f4e33e63006..4ef1f76ced7 100644 --- a/src/plugins/datetime.js +++ b/src/plugins/datetime.js @@ -237,10 +237,6 @@ export const createInputDateTime = (date) => { ]; }; -const getPlural = (count, singular, plural) => { - return count === 1 ? singular : plural; -}; - const MINUTES_IN_HOUR = 60; const HOURS_IN_DAY = 24; const MAX_DAYS_BEFORE_SHOWING_FULL_DATE = 7; @@ -258,27 +254,38 @@ export const fromNow = (date, isLocalTimeZone) => { const totalMinutesDiff = Math.abs(current.diff(time, "minute")); if (totalMinutesDiff < MINUTES_IN_HOUR) { - const minuteWord = getPlural(totalMinutesDiff, "minute", "minutes"); - return `${totalMinutesDiff} ${minuteWord} ago`; + return { + key: + totalMinutesDiff === 1 + ? "common.labels.minute" + : "common.labels.minutes", + value: totalMinutesDiff, + }; } const totalHoursDiff = Math.abs(current.diff(time, "hour")); if (totalHoursDiff < HOURS_IN_DAY) { - const hourWord = getPlural(totalHoursDiff, "hour", "hours"); - return `${totalHoursDiff} ${hourWord} ago`; + return { + key: totalHoursDiff === 1 ? "common.labels.hour" : "common.labels.hours", + value: totalHoursDiff, + }; } const totalDaysDiff = Math.abs(current.diff(time, "day")); if (totalDaysDiff < MAX_DAYS_BEFORE_SHOWING_FULL_DATE) { - const dayWord = getPlural(totalDaysDiff, "day", "days"); - return `${totalDaysDiff} ${dayWord} ago`; + return { + key: totalDaysDiff === 1 ? "common.labels.day" : "common.labels.days", + value: totalDaysDiff, + }; } - return time.format("DD.MM.YYYY"); + return { + key: "", + value: time.format("DD.MM.YYYY"), + }; }; - /** * Returns future date difference to current local time * @param {String} date