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

fixed locale pt-br not being used and added extra suport for pt-br #1745

Merged
merged 4 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/component/src/Localization/Localize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you explain why this is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the first line of this function, the language is setted to lower case, and this condidion was never true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I understand now, thank you!

return 'pt-BR';
} else {
return 'pt-PT';
Expand Down
45 changes: 43 additions & 2 deletions packages/component/src/Localization/pt-BR.js
Original file line number Diff line number Diff line change
@@ -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: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to fill the commented-out lines to finish up this localization file? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

// Do not localize {Retry}; it is a placeholder for "Retry". English translation should be, "Send failed. Retry."
Expand All @@ -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
}