Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Widget away text translations #9097

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/javascript/widget/i18n/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"IN_A_FEW_MINUTES": "Typically replies in a few minutes",
"IN_A_FEW_HOURS": "Typically replies in a few hours",
"IN_A_DAY": "Typically replies in a day",
"BACK_IN": "We will be back online"
"WILL_BE_BACK": "We will be back online {time}",
"BACK_IN": "We will be back online in {time}",
"BACK_AT": "We will be back online at {time}",
"BACK_ON": "We will be back online on {day}",
"BACK_IN_SOME_TIME": "We will be back online in some time"
},
"DAY_NAMES": [
"Sunday",
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/widget/mixins/availability.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
if (workingHoursEnabled) {
return this.isOnline
? this.replyTimeStatus
: `${this.$t('REPLY_TIME.BACK_IN')} ${this.timeLeftToBackInOnline}`;
: this.timeLeftToBackInOnline;
}
return this.isOnline
? this.replyTimeStatus
Expand Down
35 changes: 18 additions & 17 deletions app/javascript/widget/mixins/nextAvailabilityTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ export default {
},
exactTimeInAmPm() {
return `${
this.timeSlot.day === this.currentDay ? `at ${this.timeSlot.from}` : ''
this.timeSlot.day === this.currentDay
? this.$t('REPLY_TIME.BACK_AT', {
time: this.timeSlot.from,
})
: ''
}`;
},
hoursAndMinutesLeft() {
Expand All @@ -121,24 +125,14 @@ export default {

if (hoursLeft > 0) {
const roundedUpHoursLeft = minutesLeft > 0 ? hoursLeft + 1 : hoursLeft;
const hourRelative = generateRelativeTime(
roundedUpHoursLeft,
'hour',
this.languageCode
);
timeLeftChars.push(`${hourRelative}`);
timeLeftChars.push(`${roundedUpHoursLeft} hours`);
}

if (minutesLeft > 0 && hoursLeft === 0) {
const roundedUpMinLeft =
Math.ceil(minutesLeft / MINUTE_ROUNDING_FACTOR) *
MINUTE_ROUNDING_FACTOR;
const minRelative = generateRelativeTime(
roundedUpMinLeft,
'minutes',
this.languageCode
);
timeLeftChars.push(`${minRelative}`);
timeLeftChars.push(`${roundedUpMinLeft} minutes`);
}

return timeLeftChars.join(' ');
Expand All @@ -149,9 +143,11 @@ export default {
return this.exactTimeInAmPm;
}
if (hoursLeft > 0 || minutesLeft > 0) {
return this.hoursAndMinutesLeft;
return this.$t('REPLY_TIME.BACK_IN', {
time: this.hoursAndMinutesLeft,
});
}
return 'in some time';
return this.$t('REPLY_TIME.BACK_IN_SOME_TIME');
},
timeLeftToBackInOnline() {
if (
Expand All @@ -163,14 +159,19 @@ export default {
'days',
this.languageCode
);
return `${hourRelative}`;
return this.$t('REPLY_TIME.WILL_BE_BACK', {
time: hourRelative,
});
}
if (
this.dayDiff >= 1 &&
this.presentHour >= this.currentDayTimings.closeHour
) {
return `on ${this.dayNameOfNextWorkingDay}`;
return this.$t('REPLY_TIME.BACK_ON', {
day: this.dayNameOfNextWorkingDay,
});
}

return this.hoursAndMinutesToBack;
},
},
Expand Down
32 changes: 27 additions & 5 deletions app/javascript/widget/mixins/specs/nextAvailabilityTime.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { createWrapper } from '@vue/test-utils';
import nextAvailabilityTimeMixin from '../nextAvailabilityTime';
import Vue from 'vue';
import i18n from 'widget/i18n';
import VueI18n from 'vue-i18n';
Vue.use(VueI18n);
const i18nConfig = new VueI18n({
locale: 'en',
messages: i18n,
});

describe('nextAvailabilityTimeMixin', () => {
const chatwootWebChannel = {
Expand Down Expand Up @@ -383,6 +390,7 @@ describe('nextAvailabilityTimeMixin', () => {
const Component = {
render() {},
mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
};
jest
.useFakeTimers('modern')
Expand Down Expand Up @@ -410,13 +418,16 @@ describe('nextAvailabilityTimeMixin', () => {
chatwootWebChannel.workingHours[4].open_hour = 18;
chatwootWebChannel.workingHours[4].open_minutes = 0;
chatwootWebChannel.workingHours[4].close_hour = 23;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('in 30 minutes');
expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online in 30 minutes'
);
});

it('should return in 3 hours', () => {
const Component = {
render() {},
mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
};
jest
.useFakeTimers('modern')
Expand All @@ -441,13 +452,16 @@ describe('nextAvailabilityTimeMixin', () => {
'Saturday',
];
chatwootWebChannel.workingHours[4].open_hour = 19;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('in 2 hours');
expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online in 2 hours'
);
});

it('should return at 10:00 AM', () => {
const Component = {
render() {},
mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
};
jest
.useFakeTimers('modern')
Expand All @@ -472,13 +486,16 @@ describe('nextAvailabilityTimeMixin', () => {
'Saturday',
];
chatwootWebChannel.workingHours[4].open_hour = 10;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('at 10:00 AM');
expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online at 10:00 AM'
);
});

it('should return tomorrow', () => {
const Component = {
render() {},
mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
};
jest
.useFakeTimers('modern')
Expand All @@ -504,13 +521,16 @@ describe('nextAvailabilityTimeMixin', () => {
];
chatwootWebChannel.workingHours[4].open_hour = 9;
chatwootWebChannel.workingHours[4].close_hour = 16;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('tomorrow');
expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online tomorrow'
);
});

it('should return on Saturday', () => {
const Component = {
render() {},
mixins: [nextAvailabilityTimeMixin],
i18n: i18nConfig,
};
jest
.useFakeTimers('modern')
Expand Down Expand Up @@ -538,6 +558,8 @@ describe('nextAvailabilityTimeMixin', () => {
chatwootWebChannel.workingHours[4].open_hour = 9;
chatwootWebChannel.workingHours[4].close_hour = 16;
chatwootWebChannel.workingHours[5].closed_all_day = true;
expect(wrapper.vm.timeLeftToBackInOnline).toBe('on Saturday');
expect(wrapper.vm.timeLeftToBackInOnline).toBe(
'We will be back online on Saturday'
);
});
});