From 0c452e317db924513553ddc6d3f33fc6a5e8b263 Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 20 Feb 2019 17:33:44 -0300 Subject: [PATCH 1/3] fixed locale pt-br not being used and added extra suport for pt-br --- .../component/src/Localization/Localize.js | 2 +- packages/component/src/Localization/pt-BR.js | 45 ++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/packages/component/src/Localization/Localize.js b/packages/component/src/Localization/Localize.js index 2b9c5793af..92aa866b16 100644 --- a/packages/component/src/Localization/Localize.js +++ b/packages/component/src/Localization/Localize.js @@ -110,7 +110,7 @@ function normalizeLanguage(language) { } else if (language.startsWith('pl')) { return 'pl-PL'; } else if (language.startsWith('pt')) { - if (language === 'pt-BR') { + if (language === 'pt-br') { return 'pt-BR'; } else { return 'pt-PT'; diff --git a/packages/component/src/Localization/pt-BR.js b/packages/component/src/Localization/pt-BR.js index c3e47aff7f..8d51c2736b 100644 --- a/packages/component/src/Localization/pt-BR.js +++ b/packages/component/src/Localization/pt-BR.js @@ -1,3 +1,44 @@ +function xMinutesAgo(dateStr) { + const date = new Date(dateStr); + const dateTime = date.getTime(); + + if (isNaN(dateTime)) { + return dateStr; + } + + const now = Date.now(); + const deltaInMs = now - dateTime; + const deltaInMinutes = Math.floor(deltaInMs / 60000); + const deltaInHours = Math.floor(deltaInMs / 3600000); + + if (deltaInMinutes < 1) { + return 'Agora a pouco'; + } else if (deltaInMinutes === 1) { + return 'Um minuto atrás'; + } else if (deltaInHours < 1) { + return `${ deltaInMinutes } minutos atrás`; + } else if (deltaInHours === 1) { + return `Uma hora atrás`; + } else if (deltaInHours < 5) { + return `${ deltaInHours } horas atrás`; + } else if (deltaInHours <= 24) { + return `Hoje`; + } else if (deltaInHours <= 48) { + return `Ontem`; + } else if (window.Intl) { + return new Intl.DateTimeFormat('pt-BR').format(date); + } else { + return date.toLocaleString('pt-BR', { + day: '2-digit', + hour: '2-digit', + hour12: false, + minute: '2-digit', + month: '2-digit', + year: 'numeric', + }); + } +} + export default { // FAILED_CONNECTION_NOTIFICATION: '', // Do not localize {Retry}; it is a placeholder for "Retry". English translation should be, "Send failed. Retry." @@ -18,6 +59,6 @@ export default { 'Total': 'Total', 'Type your message': 'Digite sua mensagem', 'Upload file': 'Subir arquivo', - 'VAT': 'VAT' - // 'X minutes ago': + 'VAT': 'VAT', + 'X minutes ago': xMinutesAgo } From ed5c6ab912f7ee4e68b4ad854dc373bfc0b84f68 Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 20 Feb 2019 18:00:15 -0300 Subject: [PATCH 2/3] translating missing values pt-br --- packages/component/src/Localization/pt-BR.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/component/src/Localization/pt-BR.js b/packages/component/src/Localization/pt-BR.js index 8d51c2736b..6b0f0077f4 100644 --- a/packages/component/src/Localization/pt-BR.js +++ b/packages/component/src/Localization/pt-BR.js @@ -40,21 +40,21 @@ function xMinutesAgo(dateStr) { } export default { - // FAILED_CONNECTION_NOTIFICATION: '', + FAILED_CONNECTION_NOTIFICATION: 'Não foi possível conectar', // Do not localize {Retry}; it is a placeholder for "Retry". English translation should be, "Send failed. Retry." SEND_FAILED_KEY: 'não pude enviar, {Retry}.', - // SLOW_CONNECTION_NOTIFICATION: '', + SLOW_CONNECTION_NOTIFICATION: 'A conexão está levando mais tempo que o normal.', 'Chat': 'Bate-papo', - // 'Download file': '', - // 'Microphone off': '', - // 'Microphone on': '', + 'Download file': 'Baixar arquivo', + 'Microphone off': 'Microfone desligado', + 'Microphone on': 'Microfone ligado', 'Listening…': 'Ouvindo…', 'retry': 'repetir', 'Retry': '{retry}', // Please alter this value if 'Retry' at the beginning of a sentence is written differently than at the end of a sentence. 'Send': 'Enviar', 'Sending': 'enviando', 'Speak': 'Falar', - // 'Starting…': '', + 'Starting…': 'Iniciando…', 'Tax': 'Imposto', 'Total': 'Total', 'Type your message': 'Digite sua mensagem', From b5fd81203ee5aadb33cbc518bd1b3bc54effedac Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 20 Feb 2019 18:31:39 -0300 Subject: [PATCH 3/3] update CHANGELOG and LOCALIZATION --- CHANGELOG.md | 1 + LOCALIZATION.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71455a4a8a..f2fead305f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - `core`: Reworked logic on connect/disconnect for reliability on handling corner cases, by [@compulim](https://github.com/compulim) in PR [#1649](https://github.com/Microsoft/BotFramework-WebChat/pull/1649) - `core`: Fix [#1521](https://github.com/Microsoft/BotFramework-WebChat/issues/1521). Add connectivity status component and update localization, by [@corinagum](https://github.com/corinagum) in PR [#1679](https://github.com/Microsoft/BotFramework-WebChat/pull/1679) - `core`: Fix [#1057](https://github.com/Microsoft/BotFramework-WebChat/issues/1057). Fixed suggested actions destined for other recipients should not show up, by [@compulim](https://github.com/compulim) in PR [#1706](https://github.com/Microsoft/BotFramework-WebChat/pull/1706) +- `component`: Fixed pt-br locale not being selected, added `X minutes ago` and missing translations, by [@pedropacheco92](https://github.com/pedropacheco92) in PR [#1745](https://github.com/Microsoft/BotFramework-WebChat/pull/1745) ### Removed - `botAvatarImage` and `userAvatarImage` props, as they are moved inside `styleOptions`, in PR [#1486](https://github.com/Microsoft/BotFramework-WebChat/pull/1486) diff --git a/LOCALIZATION.md b/LOCALIZATION.md index 4c3b2d0135..635464159f 100644 --- a/LOCALIZATION.md +++ b/LOCALIZATION.md @@ -21,7 +21,7 @@ If you want to help to translate Web Chat to different language, please submit a | nb-no | @taarskog | | nl-nl | @iMicknl | | pl-pl | @peterblazejewicz | -| pt-br | @rcarubbi | +| pt-br | @rcarubbi, @pedropacheco92 | | pt-pt | | | ru-ru | @odysseus1973 | | sv-se | |