Skip to content

Commit

Permalink
Use locale-formatted numbers (e.g. '12,345,678')
Browse files Browse the repository at this point in the history
This covers browser table only; as we migrate to React components,
let's make sure we consistently display numbers the same way.
  • Loading branch information
Igor Afanasyev authored and iafan committed Oct 17, 2016
1 parent 576019b commit 8b09914
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pootle/static/js/browser/components/ColoredNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ColoredNumber = React.createClass({
return <span className="zero">0</span>;
}

return <span>{this.props.n}</span>;
return <span>{this.props.n.toLocaleString()}</span>;
},
});

Expand Down
2 changes: 1 addition & 1 deletion pootle/static/js/browser/components/NumberPill.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const NumberPill = React.createClass({
className="stats-data"
href={this.props.url}
>
{this.props.n}
{this.props.n.toLocaleString()}
</a>
);
},
Expand Down
10 changes: 7 additions & 3 deletions pootle/static/js/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import StatsCollapsed from './browser/components/StatsCollapsed';
import msg from './msg';


function formattedValue(n) {
return n ? n.toLocaleString() : 0;
}

function nicePercentage(part, total, noTotalDefault) {
const percentage = total ? part / total * 100 : noTotalDefault;
if (percentage > 99 && percentage < 100) {
Expand All @@ -35,7 +39,7 @@ function nicePercentage(part, total, noTotalDefault) {
if (percentage > 0 && percentage < 1) {
return 1;
}
return Math.round(percentage);
return percentage > 0 ? Math.round(percentage) : 0;
}


Expand Down Expand Up @@ -193,7 +197,7 @@ const stats = {
},

updateTranslationStats($tr, total, value, noTotalDefault) {
$tr.find('.stats-number .stats-data').html(value);
$tr.find('.stats-number .stats-data').html(formattedValue(value));
$tr.find('.stats-percentage span').html(
nicePercentage(value, total, noTotalDefault)
);
Expand All @@ -202,7 +206,7 @@ const stats = {

updateAction($action, count) {
$action.toggleClass('non-zero', count > 0);
$action.find('.counter').text(count !== null ? count : '—');
$action.find('.counter').text(formattedValue(count));
},

updateItemStats($td, count) {
Expand Down

2 comments on commit 8b09914

@julen
Copy link
Contributor

@julen julen commented on 8b09914 Oct 25, 2016

Choose a reason for hiding this comment

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

Note this won't provide a consistent experience: the locale used for formatting will be the OS locale, which is potentially (and likely) different from the Zing locale being used. I think we can do much better and I have filed #59.

@iafan
Copy link
Contributor

@iafan iafan commented on 8b09914 Oct 25, 2016

Choose a reason for hiding this comment

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

I provided my reasoning in the ticket.

Please sign in to comment.