diff --git a/src/internal_time_ago.js b/src/internal_time_ago.js index f34062f..ff7ea3c 100644 --- a/src/internal_time_ago.js +++ b/src/internal_time_ago.js @@ -1,4 +1,6 @@ -export function time_ago(time) { +import {useI18n} from "vue-i18n"; + +export function time_ago(time) { const time_date = new Date(time) const now_date = new Date(Date.now()) const ago = now_date - time_date @@ -19,28 +21,54 @@ function internal_time_ago(time) { default: time = +new Date(); } - + + const {t} = useI18n(); + const I18nseconds = t('time.seconds'); + const I18nminuteago = t('time.1minuteago'); + const I181minutefromnow = t('time.1minutefromnow'); + const I181minutes = t('time.minutes'); + const I1811hourago = t('time.1hourago'); + const I1811hourfromnow = t('time.1hourfromnow'); + const I18n1hours = t('time.hours'); + const I18nyesterday = t('time.yesterday'); + const I18ntomorrow = t('time.tomorrow'); + const I18ndays = t('time.days'); + const I18nlastweek = t('time.lastweek'); + const I18nnextweek = t('time.nextweek'); + const I18nweeks = t('time.weeks'); + const I18nlastmonth = t('time.lastmonth'); + const I18nnextmonth = t('time.nextmonth'); + const I18nmonths = t('time.months'); + const I18nlastyear = t('time.lastyear'); + const I18nnextyear = t('time.nextyear'); + const I18nyears = t('time.years'); + const I18nlastcentury = t('time.lastcentury'); + const I18nnextcentury = t('time.nextcentury'); + const I18ncenturies = t('time.centuries'); + const I18nago = t('time.ago'); + + const time_formats = [ - [60, 'seconds', 1], // 60 - [120, '1 minute ago', '1 minute from now'], // 60*2 - [3600, 'minutes', 60], // 60*60, 60 - [7200, '1 hour ago', '1 hour from now'], // 60*60*2 - [86400, 'hours', 3600], // 60*60*24, 60*60 - [172800, 'Yesterday', 'Tomorrow'], // 60*60*24*2 - [604800, 'days', 86400], // 60*60*24*7, 60*60*24 - [1209600, 'Last week', 'Next week'], // 60*60*24*7*4*2 - [2419200, 'weeks', 604800], // 60*60*24*7*4, 60*60*24*7 - [4838400, 'Last month', 'Next month'], // 60*60*24*7*4*2 - [29030400, 'months', 2419200], // 60*60*24*7*4*12, 60*60*24*7*4 - [58060800, 'Last year', 'Next year'], // 60*60*24*7*4*12*2 - [2903040000, 'years', 29030400], // 60*60*24*7*4*12*100, 60*60*24*7*4*12 - [5806080000, 'Last century', 'Next century'], // 60*60*24*7*4*12*100*2 - [58060800000, 'centuries', 2903040000] // 60*60*24*7*4*12*100*20, 60*60*24*7*4*12*100 + [60, I18nseconds, 1], // 60 + [120, I18nminuteago, I181minutefromnow], // 60*2 + [3600, I181minutes, 60], // 60*60, 60 + [7200, I1811hourago, I1811hourfromnow], // 60*60*2 + [86400, I18n1hours, 3600], // 60*60*24, 60*60 + [172800, I18nyesterday, I18ntomorrow], // 60*60*24*2 + [604800, I18ndays, 86400], // 60*60*24*7, 60*60*24 + [1209600, I18nlastweek, I18nnextweek], // 60*60*24*7*4*2 + [2419200, I18nweeks, 604800], // 60*60*24*7*4, 60*60*24*7 + [4838400, I18nlastmonth, I18nnextmonth], // 60*60*24*7*4*2 + [29030400, I18nmonths, 2419200], // 60*60*24*7*4*12, 60*60*24*7*4 + [58060800, I18nlastyear, I18nnextyear], // 60*60*24*7*4*12*2 + [2903040000, I18nyears, 29030400], // 60*60*24*7*4*12*100, 60*60*24*7*4*12 + [5806080000, I18nlastcentury, I18nnextcentury], // 60*60*24*7*4*12*100*2 + [58060800000, I18ncenturies, 2903040000] // 60*60*24*7*4*12*100*20, 60*60*24*7*4*12*100 ]; let seconds = time / 1000 - let token = 'ago' + let token = I18nago let list_choice = 1 if (seconds === 0) { diff --git a/src/locales/en.json b/src/locales/en.json index c2ba883..b2ed325 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -73,6 +73,7 @@ "years": "years", "lastcentury": "Last century", "nextcentury": "Next century", - "centuries": "centuries" + "centuries": "centuries", + "ago": "ago" } } \ No newline at end of file diff --git a/src/locales/fr.json b/src/locales/fr.json index 9a34d96..52eb72e 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -53,27 +53,28 @@ }, "time": { "seconds": "secondes", - "1minuteago": "il y a 1 minute", + "1minuteago": "Il y a 1 minute", "1minutefromnow": "dans 1 minute", "minutes": "minutes", - "1hourago": "il y a 1 heure", + "1hourago": "Il y a 1 heure", "1hourfromnow": "dans 1 heure", "hours": "heures", "yesterday": "hier", "tomorrow": "demain", "days": "jours", - "lastweek": "la semaine dernière", - "nextweek": "la semaine prochaine", + "lastweek": "La semaine dernière.", + "nextweek": "La semaine prochaine", "weeks": "semaines", - "lastmonth": "le mois dernier", - "nextmonth": "le mois prochain", + "lastmonth": "Le mois dernier", + "nextmonth": "Le mois prochain", "months": "mois", - "lastyear": "l'année dernière", - "nextyear": "l'année prochaine", + "lastyear": "L'année dernière", + "nextyear": "L'année prochaine", "years": "années", - "lastcentury": "le siècle dernier", - "nextcentury": "le siècle prochain", - "centuries": "siècles" + "lastcentury": "Le siècle dernier", + "nextcentury": "Le siècle prochain", + "centuries": "siècles", + "ago": "" } } \ No newline at end of file diff --git a/src/views/messages/Message.vue b/src/views/messages/Message.vue index 0421865..45aec19 100644 --- a/src/views/messages/Message.vue +++ b/src/views/messages/Message.vue @@ -19,9 +19,10 @@