Added date computing translations
This commit is contained in:
@@ -66,6 +66,14 @@ export default defineI18nConfig(() => ({
|
|||||||
beforeYesterday: "2 days ago",
|
beforeYesterday: "2 days ago",
|
||||||
fromTo: "From {startDate} to {endDate}",
|
fromTo: "From {startDate} to {endDate}",
|
||||||
while: "During {duration}",
|
while: "During {duration}",
|
||||||
|
xDaysNext: "In {days} days",
|
||||||
|
xMonthsNext: "In {months} month(s)",
|
||||||
|
xYearsNext: "In {years} year(s)",
|
||||||
|
xYearsAndMonthsNext: "In {years} year(s) and {months} month(s)",
|
||||||
|
xDaysAgo: "{days} days ago",
|
||||||
|
xMonthsAgo: "{months} month(s) ago",
|
||||||
|
xYearsAgo: "{years} year(s) ago",
|
||||||
|
xYearsAndMonthsAgo: "{years} year(s) and {months} month(s) ago",
|
||||||
},
|
},
|
||||||
event: {
|
event: {
|
||||||
nameSingular: "Event",
|
nameSingular: "Event",
|
||||||
@@ -210,6 +218,14 @@ export default defineI18nConfig(() => ({
|
|||||||
beforeYesterday: "Avant-hier",
|
beforeYesterday: "Avant-hier",
|
||||||
fromTo: "Du {startDate} au {endDate}",
|
fromTo: "Du {startDate} au {endDate}",
|
||||||
while: "Pendant {duration}",
|
while: "Pendant {duration}",
|
||||||
|
xDaysNext: "Dans {days} jours",
|
||||||
|
xMonthsNext: "Dans {months} mois",
|
||||||
|
xYearsNext: "Dans {years} an(s)",
|
||||||
|
xYearsAndMonthsNext: "Dans {years} an(s) et {months} mois",
|
||||||
|
xDaysAgo: "Il y a {days} jours",
|
||||||
|
xMonthsAgo: "Il y a {months} mois",
|
||||||
|
xYearsAgo: "Il y a {years} an(s)",
|
||||||
|
xYearsAndMonthsAgo: "Il y a {years} an(s) et {months} mois",
|
||||||
},
|
},
|
||||||
event: {
|
event: {
|
||||||
nameSingular: "Évènement",
|
nameSingular: "Évènement",
|
||||||
|
|||||||
@@ -24,6 +24,13 @@ type CalendarCurrentDate = {
|
|||||||
currentDateTitle: ComputedRef<string>
|
currentDateTitle: ComputedRef<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DateDirectionTranslationKeys = {
|
||||||
|
days: string
|
||||||
|
months: string
|
||||||
|
years: string
|
||||||
|
yearsAndMonths: string
|
||||||
|
}
|
||||||
|
|
||||||
export const useCalendar = defineStore("calendar", () => {
|
export const useCalendar = defineStore("calendar", () => {
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
@@ -483,7 +490,19 @@ export const useCalendar = defineStore("calendar", () => {
|
|||||||
const differenceInDays: number = getDifferenceInDays(baseDate, relativeDate)
|
const differenceInDays: number = getDifferenceInDays(baseDate, relativeDate)
|
||||||
let output: string = ""
|
let output: string = ""
|
||||||
let direction: "past" | "present" | "future" = "present"
|
let direction: "past" | "present" | "future" = "present"
|
||||||
let directionPrefix: string = ""
|
const futureKeys: DateDirectionTranslationKeys = {
|
||||||
|
days: "xDaysNext",
|
||||||
|
months: "xMonthsNext",
|
||||||
|
years: "xYearsNext",
|
||||||
|
yearsAndMonths: "xYearsAndMonthsNext",
|
||||||
|
}
|
||||||
|
const pastKeys: DateDirectionTranslationKeys = {
|
||||||
|
days: "xDaysAgo",
|
||||||
|
months: "xMonthsAgo",
|
||||||
|
years: "xYearsAgo",
|
||||||
|
yearsAndMonths: "xYearsAndMonthsAgo",
|
||||||
|
}
|
||||||
|
let directionKeys: DateDirectionTranslationKeys = pastKeys
|
||||||
|
|
||||||
// Check whether it's a past or future date
|
// Check whether it's a past or future date
|
||||||
if (differenceInDays > 0) {
|
if (differenceInDays > 0) {
|
||||||
@@ -493,7 +512,7 @@ export const useCalendar = defineStore("calendar", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (formatting === "complex") {
|
if (formatting === "complex") {
|
||||||
// Handle if it's the same date
|
// Handle if it's the same date
|
||||||
if (direction === "present") {
|
if (direction === "present") {
|
||||||
return t("entity.calendar.date.today")
|
return t("entity.calendar.date.today")
|
||||||
}
|
}
|
||||||
@@ -512,12 +531,10 @@ export const useCalendar = defineStore("calendar", () => {
|
|||||||
|
|
||||||
// Get relevant prefix for the string
|
// Get relevant prefix for the string
|
||||||
if (direction === "future") {
|
if (direction === "future") {
|
||||||
directionPrefix = "Dans "
|
directionKeys = futureKeys
|
||||||
} else if (direction === "past") {
|
} else {
|
||||||
directionPrefix = "Il y a "
|
directionKeys = pastKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
output += directionPrefix
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSameMonth = baseDate.month === relativeDate.month
|
const isSameMonth = baseDate.month === relativeDate.month
|
||||||
@@ -546,11 +563,7 @@ export const useCalendar = defineStore("calendar", () => {
|
|||||||
if (isSameMonth && isSameYear) {
|
if (isSameMonth && isSameYear) {
|
||||||
dateAcc.day = futureDate.day - datePivot.day
|
dateAcc.day = futureDate.day - datePivot.day
|
||||||
|
|
||||||
if (dateAcc.day === 1) {
|
output = t(`entity.calendar.date.${directionKeys.days}`, { days: dateAcc.day })
|
||||||
output += ` ${dateAcc.day} jour`
|
|
||||||
} else {
|
|
||||||
output += ` ${dateAcc.day} jours`
|
|
||||||
}
|
|
||||||
|
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
@@ -559,7 +572,7 @@ export const useCalendar = defineStore("calendar", () => {
|
|||||||
else if (isSameYear) {
|
else if (isSameYear) {
|
||||||
dateAcc.month = futureDate.month - datePivot.month
|
dateAcc.month = futureDate.month - datePivot.month
|
||||||
|
|
||||||
output += ` ${dateAcc.month} mois`
|
output = t(`entity.calendar.date.${directionKeys.months}`, { months: dateAcc.month })
|
||||||
|
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
@@ -602,13 +615,13 @@ export const useCalendar = defineStore("calendar", () => {
|
|||||||
const remainderMonths = dateAcc.month % monthsPerYear.value
|
const remainderMonths = dateAcc.month % monthsPerYear.value
|
||||||
|
|
||||||
if (computedYear >= 1 && remainderMonths) {
|
if (computedYear >= 1 && remainderMonths) {
|
||||||
output += ` ${computedYear} an(s) et ${remainderMonths} mois`
|
output = t(`entity.calendar.date.${directionKeys.yearsAndMonths}`, { years: computedYear, months: remainderMonths })
|
||||||
}
|
}
|
||||||
else if (computedYear >= 1 && !remainderMonths) {
|
else if (computedYear >= 1 && !remainderMonths) {
|
||||||
output += ` ${computedYear} an(s)`;
|
output = t(`entity.calendar.date.${directionKeys.years}`, { years: computedYear })
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
output += ` ${remainderMonths} mois`
|
output = t(`entity.calendar.date.${directionKeys.months}`, { months: remainderMonths })
|
||||||
}
|
}
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|||||||
Reference in New Issue
Block a user