diff --git a/src/App.vue b/src/App.vue index 52ef75f..7fc49c7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -87,16 +87,19 @@ export default { // Assigns available language for ex 'zh_Hans' when browser header language is 'zh' or 'zh-HK' this.availableJsonTranslation= LocalesArr[LocalesArr.findIndex(locale => locale.includes(lang))]; - if (this.$i18n.messages[this.browserLanguage]) { - this.$store.commit("setLanguage", this.browserLanguage); - } else if (this.browserLanguage.includes("-")) { - if (this.$i18n.messages[lang]) { - this.$store.commit("setLanguage", lang); + if (!this.$store.state.language) { + // Set default language if not set already + if (this.$i18n.messages[this.browserLanguage]) { + this.$store.commit("setLanguage", this.browserLanguage); + } else if (this.browserLanguage.includes("-")) { + if (this.$i18n.messages[lang]) { + this.$store.commit("setLanguage", lang); + } else { + this.$store.commit("setLanguage", this.availableJsonTranslation); + } } else { this.$store.commit("setLanguage", this.availableJsonTranslation); } - } else { - this.$store.commit("setLanguage", this.availableJsonTranslation); } // Set language diff --git a/src/assets/translations/en.json b/src/assets/translations/en.json index 395e316..574c776 100644 --- a/src/assets/translations/en.json +++ b/src/assets/translations/en.json @@ -62,7 +62,8 @@ "user_changed_guest_access_open": "{user} allowed guests to join the room", "reply_image": "Image", "reply_audio_message": "Audio message", - "reply_video": "Video" + "reply_video": "Video", + "time_ago": "Today | Yesterday | {count} days ago" }, "room": { "invitations": "You have no invitations | You have 1 invitation | You have {count} invitations", diff --git a/src/components/Chat.vue b/src/components/Chat.vue index 269f6c0..66bce7a 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -1738,7 +1738,12 @@ export default { }, dayForEvent(event) { - return util.formatDay(event.getTs()); + let dayDiff = util.dayDiffToday(event.getTs()); + if (dayDiff < 7) { + return this.$tc("message.time_ago", dayDiff); + } else { + return util.formatDay(event.getTs()); + } }, showRecordingUI() { diff --git a/src/plugins/utils.js b/src/plugins/utils.js index ab3709f..ef40596 100644 --- a/src/plugins/utils.js +++ b/src/plugins/utils.js @@ -546,19 +546,15 @@ class Util { return t2.diff(t1, 'day'); } - formatDay(timestamp) { + dayDiffToday(timestamp) { var then = dayjs(timestamp).endOf('day'); var now = dayjs().endOf('day'); - const dayDiff = now.diff(then, 'day'); - if (dayDiff < 1) { - return "Today"; - } else if (dayDiff < 2) { - return "Yesterday"; - } else if (dayDiff < 7) { - return "" + dayDiff + " days ago"; - } else { - return then.format('L'); - } + return now.diff(then, 'day'); + } + + formatDay(timestamp) { + var then = dayjs(timestamp).endOf('day'); + return then.format('L'); } formatRecordDuration(ms) {