diff --git a/client/src/utils/PortugueseUtils.ts b/client/src/utils/PortugueseUtils.ts new file mode 100644 index 0000000..e3b9eb7 --- /dev/null +++ b/client/src/utils/PortugueseUtils.ts @@ -0,0 +1,69 @@ +/** + * Translates a time ago message from English to Brazilian Portuguese. + * + * @param {string} textValue The text message to be translated. + * @param {number} numberValue The number value to be used in the message. + * @returns The message translated. + */ +function translateTimeAgoPtBr(textValue: string, numberValue: number): string { + if (textValue.includes('year')) { + return textValue.includes('s ') + ? `${numberValue} anos atrás` + : `${numberValue} ano atrás`; + } + else if (textValue.includes('month')) { + return textValue.includes('s ') + ? `${numberValue} meses atrás` + : `${numberValue} mês atrás`; + } + else if (textValue.includes('days')) { + return textValue.includes('s ') + ? `${numberValue} dias atrás` + : `${numberValue} dia atrás`; + } + else if (textValue.includes('hour')) { + return textValue.includes('s ') + ? `${numberValue} horas atrás` + : `${numberValue} hora atrás`; + } + else if (textValue.includes('minutes')) { + return textValue.includes('s ') + ? `${numberValue} minutos atrás` + : `${numberValue} minuto atrás`; + } + else if (textValue.includes('seconds')) { + return textValue.includes('s ') + ? `${numberValue} segundos atrás` + : `${numberValue} segundo atrás`; + } + + return 'Momentos atrás'; +} + +/** + * Translates a time left message from English to Brazilian Portuguese. + * + * @param {string} textValue The text message to be translated. + * @param {number} numberValue The number value to be used in the message. + * @returns The message translated. + */ +function translateTimeLeftPtBr(textValue: string, numberValue: number): string { + if (textValue.includes('year')) { + return textValue.includes('s ') + ? `${numberValue} anos restantes` + : `${numberValue} ano restante`; + } + else if (textValue.includes('month')) { + return textValue.includes('s ') + ? `${numberValue} meses restantes` + : `${numberValue} mês restante`; + } + else if (textValue.includes('day')) { + return textValue.includes('s ') + ? `${numberValue} dias restantes` + : `${numberValue} dia restante`; + } + return textValue; +} + +export { translateTimeAgoPtBr, translateTimeLeftPtBr }; diff --git a/client/src/utils/RussianUtils.ts b/client/src/utils/RussianUtils.ts new file mode 100644 index 0000000..0e40fa8 --- /dev/null +++ b/client/src/utils/RussianUtils.ts @@ -0,0 +1,36 @@ +function translateTimeAgoRu(textValue: string, numberValue: number): string { + if (textValue.includes('year')) { + return textValue.includes('s ') + ? `${numberValue} года назад` + : `${numberValue} год назад`; + } + else if (textValue.includes('month')) { + return textValue.includes('s ') + ? `${numberValue} месяца назад` + : `${numberValue} месяц назад`; + } + else if (textValue.includes('days')) { + return textValue.includes('s ') + ? `${numberValue} дня назад` + : `${numberValue} день назад`; + } + else if (textValue.includes('hour')) { + return textValue.includes('s ') + ? `${numberValue} часа назад` + : `${numberValue} час назад`; + } + else if (textValue.includes('minutes')) { + return textValue.includes('s ') + ? `${numberValue} минуты назад` + : `${numberValue} минуту назад`; + } + else if (textValue.includes('seconds')) { + return textValue.includes('s ') + ? `${numberValue} секунд назад` + : `${numberValue} секунду назад`; + } + + return 'Несколько минут назад'; +} + +export { translateTimeAgoRu }; diff --git a/client/src/utils/SpanishUtils.ts b/client/src/utils/SpanishUtils.ts new file mode 100644 index 0000000..c03b2db --- /dev/null +++ b/client/src/utils/SpanishUtils.ts @@ -0,0 +1,69 @@ +/** + * Translates a time ago message from English to Spanish. + * + * @param {string} textValue The text message to be translated. + * @param {number} numberValue The number value to be used in the message. + * @returns The message translated. + */ +function translateTimeAgoEs(textValue: string, numberValue: number): string { + if (textValue.includes('year')) { + return textValue.includes('s ') + ? `Hace ${numberValue} años` + : `Hace ${numberValue} año`; + } + else if (textValue.includes('month')) { + return textValue.includes('s ') + ? `Hace ${numberValue} meses` + : `Hace ${numberValue} mes`; + } + else if (textValue.includes('days')) { + return textValue.includes('s ') + ? `Hace ${numberValue} días` + : `Hace ${numberValue} día`; + } + else if (textValue.includes('hour')) { + return textValue.includes('s ') + ? `Hace ${numberValue} horas` + : `Hace ${numberValue} hora`; + } + else if (textValue.includes('minutes')) { + return textValue.includes('s ') + ? `Hace ${numberValue} minutos` + : `Hace ${numberValue} minuto`; + } + else if (textValue.includes('seconds')) { + return textValue.includes('s ') + ? `Hace ${numberValue} segundos` + : `Hace ${numberValue} segundo`; + } + + return 'Hace momentos'; +} + +/** + * Translates a time left message from English to Spanish. + * + * @param {string} textValue The text message to be translated. + * @param {number} numberValue The number value to be used in the message. + * @returns The message translated. + */ +function translateTimeLeftEs(textValue: string, numberValue: number): string { + if (textValue.includes('year')) { + return textValue.includes('s ') + ? `Faltan ${numberValue} años` + : `Falta ${numberValue} año`; + } + else if (textValue.includes('month')) { + return textValue.includes('s ') + ? `Faltan ${numberValue} meses` + : `Falta ${numberValue} mes`; + } + else if (textValue.includes('day')) { + return textValue.includes('s ') + ? `Faltan ${numberValue} días` + : `Falta ${numberValue} día`; + } + return textValue; +} + +export { translateTimeAgoEs, translateTimeLeftEs }; diff --git a/client/src/utils/TranslatorUtils.ts b/client/src/utils/TranslatorUtils.ts index 6c1127b..ad1bd84 100644 --- a/client/src/utils/TranslatorUtils.ts +++ b/client/src/utils/TranslatorUtils.ts @@ -1,5 +1,8 @@ import { TaskResponse } from '../types/TaskResponse'; import USER_LANG from '../types/UserLangs'; +import { translateTimeAgoPtBr, translateTimeLeftPtBr } from './PortugueseUtils'; +import { translateTimeAgoRu } from './RussianUtils'; +import { translateTimeAgoEs, translateTimeLeftEs } from './SpanishUtils'; /** * Translates all responses from tasks server API. @@ -26,245 +29,69 @@ function translateTaskResponse(tasks: TaskResponse[], target: string): TaskRespo * @returns {string} The translated message. */ function translateMessage(message: string, target: string): string { - let lang = USER_LANG.ENGLISH; - if (target === USER_LANG.PORTUGUESE) { - lang = USER_LANG.PORTUGUESE; - } - else if (target === USER_LANG.SPANISH) { - lang = USER_LANG.SPANISH; - } - else if (target === USER_LANG.RUSSIAN) { - lang = USER_LANG.RUSSIAN; - } - if (lang === USER_LANG.ENGLISH) { + if (target === USER_LANG.ENGLISH) { return message; } if (message.includes(' ago')) { const firstSpace = message.indexOf(' '); - const numberValue = message.substring(0, firstSpace); + const numberValue = parseInt(message.substring(0, firstSpace)); const textValue = message.substring(firstSpace).trim(); - switch (textValue) { - case 'years ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} anos atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} años`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} года назад`; - } - break; - } - case 'year ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} ano atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} año`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} год назад`; - } - break; - } - case 'months ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} meses atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} meses`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} месяца назад`; - } - // here - break; - } - case 'month ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} mês atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} mes`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} месяц назад`; - } - break; - } - case 'days ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} dias atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} días`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} дня назад`; - } - break; - } - case 'day ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} dia atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} día`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} день назад`; - } - break; - } - case 'hours ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} horas atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} horas`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} часа назад`; - } - break; - } - case 'hour ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} hora atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} hora`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} час назад`; - } - break; - } - case 'minutes ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} minutos atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} minutos`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} минуты назад`; - } - break; - } - case 'minute ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} minuto atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} minuto`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} минуту назад`; - } - break; - } - case 'seconds ago': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} segundos atrás`; - } - else if (lang === USER_LANG.SPANISH) { - return `Hace ${numberValue} segundos`; - } - else if (lang === USER_LANG.RUSSIAN) { - return `${numberValue} секунд назад`; - } - break; - } - case 'Moments ago': { - if (lang === USER_LANG.PORTUGUESE) { - return 'Momentos atrás'; - } - else if (lang === USER_LANG.SPANISH) { - return 'Hace momentos'; - } - else if (lang === USER_LANG.RUSSIAN) { - return 'Несколько минут назад'; - } - } + + if (target === USER_LANG.PORTUGUESE) { + return translateTimeAgoPtBr(textValue, numberValue); } + if (target === USER_LANG.SPANISH) { + return translateTimeAgoEs(textValue, numberValue); + } + + return translateTimeAgoRu(textValue, numberValue); } if (message.includes(' left')) { const firstSpace = message.indexOf(' '); - const numberValue = message.substring(0, firstSpace); + const numberValue = parseInt(message.substring(0, firstSpace)); const textValue = message.substring(firstSpace).trim(); + + if (target === USER_LANG.PORTUGUESE) { + return translateTimeLeftPtBr(textValue, numberValue); + } + if (target === USER_LANG.SPANISH) { + return translateTimeLeftEs(textValue, numberValue); + } switch (textValue) { case 'years left': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} anos restantes`; - } - else if (lang === USER_LANG.SPANISH) { - return `Faltan ${numberValue} años`; - } - else if (lang === USER_LANG.RUSSIAN) { + if (lang === USER_LANG.RUSSIAN) { return `осталось ${numberValue} лет`; } break; } case 'year left': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} ano restante`; - } - else if (lang === USER_LANG.SPANISH) { - return `Falta ${numberValue} año`; - } - else if (lang === USER_LANG.RUSSIAN) { + if (lang === USER_LANG.RUSSIAN) { return `Остался ${numberValue} год`; } break; } case 'months left': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} meses restantes`; - } - else if (lang === USER_LANG.SPANISH) { - return `Faltan ${numberValue} meses`; - } - else if (lang === USER_LANG.RUSSIAN) { + if (lang === USER_LANG.RUSSIAN) { return `осталось ${numberValue} месяцев`; } break; } case 'month left': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} mês restante`; - } - else if (lang === USER_LANG.SPANISH) { - return `Falta ${numberValue} mes`; - } - else if (lang === USER_LANG.RUSSIAN) { + if (lang === USER_LANG.RUSSIAN) { return `Остался ${numberValue} месяц`; } break; } case 'days left': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} dias restantes`; - } - else if (lang === USER_LANG.SPANISH) { - return `Faltan ${numberValue} días`; - } - else if (lang === USER_LANG.RUSSIAN) { + if (lang === USER_LANG.RUSSIAN) { return `осталось ${numberValue} дней`; } break; } case 'day left': { - if (lang === USER_LANG.PORTUGUESE) { - return `${numberValue} dia restante`; - } - else if (lang === USER_LANG.SPANISH) { - return `Falta ${numberValue} día`; - } - else if (lang === USER_LANG.RUSSIAN) { + if (lang === USER_LANG.RUSSIAN) { return `Остался ${numberValue} день`; } break; diff --git a/client/src/views/Landing/styles.scss b/client/src/views/Landing/styles.scss index 8b32613..65369c5 100644 --- a/client/src/views/Landing/styles.scss +++ b/client/src/views/Landing/styles.scss @@ -57,7 +57,6 @@ $dark-text: #343a40; &:hover { font-size: 2.7rem; color: darken($primary-color, 30%); - font-weight: 600; } }