Skip to content

Commit

Permalink
Added internationalization to status alert.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaellinaresxk committed Sep 26, 2023
1 parent 882e7b5 commit ac94092
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
17 changes: 14 additions & 3 deletions src/components/topbar/StatusAlerts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,21 @@
>
<template v-if="item.timestamp !== item.createdAt">
{{ $t("common.labels.updateAt") }}
{{ formatDate(item.timestamp) }} |
{{
formatDate(item.timestamp).value +
" " +
$t(formatDate(item.timestamp).key)
}}
|
</template>
{{ $t("common.labels.createAt") }}
{{ formatDate(item.createdAt) }}
{{
formatDate(item.createdAt).value
? formatDate(item.createdAt).value +
" " +
$t(formatDate(item.createdAt).key)
: formatDate(item.createdAt).key
}}
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
Expand Down Expand Up @@ -67,7 +78,7 @@ export default defineComponent({
: { icon: mdiInformation, color: "info" };
};
const formatDate = (dateTime: string) => {
const formatDate = (dateTime: any) => {
return fromNow(dateTime, true);
};
Expand Down
5 changes: 5 additions & 0 deletions src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
5 changes: 5 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/locales/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Закрити",
Expand Down
31 changes: 19 additions & 12 deletions src/plugins/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit ac94092

Please sign in to comment.