From 2c18640386eb23aa287e1e390ffb8a424c34a382 Mon Sep 17 00:00:00 2001 From: Wulf Weich Date: Wed, 25 Apr 2018 10:26:49 +0200 Subject: [PATCH] gui: Localize number formatting (fixes #4896) (#4902) --- gui/default/index.html | 26 +++++++++---------- gui/default/syncthing/app.js | 12 --------- gui/default/syncthing/core/binaryFilter.js | 8 +++--- .../syncthing/core/localeNumberFilter.js | 9 +++++++ gui/default/syncthing/core/metricFilter.js | 8 +++--- gui/default/syncthing/core/naturalFilter.js | 6 ----- 6 files changed, 30 insertions(+), 39 deletions(-) create mode 100644 gui/default/syncthing/core/localeNumberFilter.js delete mode 100644 gui/default/syncthing/core/naturalFilter.js diff --git a/gui/default/index.html b/gui/default/index.html index e49d8ffc4..5af082b9a 100644 --- a/gui/default/index.html +++ b/gui/default/index.html @@ -321,9 +321,9 @@  Global State - -  {{model[folder.id].globalFiles | alwaysNumber}}  -  {{model[folder.id].globalDirectories | alwaysNumber}}  + +  {{model[folder.id].globalFiles | alwaysNumber | localeNumber}}  +  {{model[folder.id].globalDirectories | alwaysNumber | localeNumber}}   ~{{model[folder.id].globalBytes | binary}}B @@ -331,9 +331,9 @@  Local State - -  {{model[folder.id].localFiles | alwaysNumber}}  -  {{model[folder.id].localDirectories | alwaysNumber}}  + +  {{model[folder.id].localFiles | alwaysNumber | localeNumber}}  +  {{model[folder.id].localDirectories | alwaysNumber | localeNumber}}   ~{{model[folder.id].localBytes | binary}}B
Reduced by ignore patterns
@@ -355,7 +355,7 @@  Failed Items - {{model[folder.id].pullErrors | alwaysNumber}} items + {{model[folder.id].pullErrors | alwaysNumber | localeNumber}} items @@ -532,9 +532,9 @@  Local State (Total) - -  {{localStateTotal.files | alwaysNumber}}  -  {{localStateTotal.directories| alwaysNumber}}  + +  {{localStateTotal.files | alwaysNumber | localeNumber}}  +  {{localStateTotal.directories| alwaysNumber | localeNumber}}   ~{{localStateTotal.bytes | binary}}B @@ -544,7 +544,7 @@  CPU Utilization - {{system.cpuPercent | alwaysNumber | natural:1}}% + {{system.cpuPercent | alwaysNumber | localeNumber:2}}%  Listeners @@ -635,7 +635,7 @@  Out of Sync Items - {{completion[deviceCfg.deviceID]._needItems | alwaysNumber}} items, ~{{completion[deviceCfg.deviceID]._needBytes | binary}}B + {{completion[deviceCfg.deviceID]._needItems | alwaysNumber | localeNumber}} items, ~{{completion[deviceCfg.deviceID]._needBytes | binary}}B @@ -784,6 +784,7 @@ + @@ -791,7 +792,6 @@ - diff --git a/gui/default/syncthing/app.js b/gui/default/syncthing/app.js index ac9c89cb8..d2e1d96c7 100644 --- a/gui/default/syncthing/app.js +++ b/gui/default/syncthing/app.js @@ -82,18 +82,6 @@ function folderList(m) { return l; } -function decimals(val, num) { - var digits, decs; - - if (val === 0) { - return 0; - } - - digits = Math.floor(Math.log(Math.abs(val)) / Math.log(10)); - decs = Math.max(0, num - digits); - return decs; -} - function isEmptyObject(obj) { var name; for (name in obj) { diff --git a/gui/default/syncthing/core/binaryFilter.js b/gui/default/syncthing/core/binaryFilter.js index e9e30e06f..0836bae57 100644 --- a/gui/default/syncthing/core/binaryFilter.js +++ b/gui/default/syncthing/core/binaryFilter.js @@ -6,16 +6,16 @@ angular.module('syncthing.core') } if (input > 1024 * 1024 * 1024) { input /= 1024 * 1024 * 1024; - return input.toFixed(decimals(input, 2)) + ' Gi'; + return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' Gi'; } if (input > 1024 * 1024) { input /= 1024 * 1024; - return input.toFixed(decimals(input, 2)) + ' Mi'; + return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' Mi'; } if (input > 1024) { input /= 1024; - return input.toFixed(decimals(input, 2)) + ' Ki'; + return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' Ki'; } - return Math.round(input) + ' '; + return Math.round(input).toLocaleString(undefined, {maximumFractionDigits: 2}) + ' '; }; }); diff --git a/gui/default/syncthing/core/localeNumberFilter.js b/gui/default/syncthing/core/localeNumberFilter.js new file mode 100644 index 000000000..7f8a04075 --- /dev/null +++ b/gui/default/syncthing/core/localeNumberFilter.js @@ -0,0 +1,9 @@ +angular.module('syncthing.core') + .filter('localeNumber', function () { + return function (input, decimals) { + if (typeof(decimals) !== 'undefined') { + return input.toLocaleString(undefined, {maximumFractionDigits: decimals}); + } + return input.toLocaleString(); + }; + }); \ No newline at end of file diff --git a/gui/default/syncthing/core/metricFilter.js b/gui/default/syncthing/core/metricFilter.js index 8d40e28eb..e371410d8 100644 --- a/gui/default/syncthing/core/metricFilter.js +++ b/gui/default/syncthing/core/metricFilter.js @@ -6,16 +6,16 @@ angular.module('syncthing.core') } if (input > 1000 * 1000 * 1000) { input /= 1000 * 1000 * 1000; - return input.toFixed(decimals(input, 2)) + ' G'; + return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' G'; } if (input > 1000 * 1000) { input /= 1000 * 1000; - return input.toFixed(decimals(input, 2)) + ' M'; + return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' M'; } if (input > 1000) { input /= 1000; - return input.toFixed(decimals(input, 2)) + ' k'; + return input.toLocaleString(undefined, {maximumFractionDigits: 2}) + ' k'; } - return Math.round(input) + ' '; + return Math.round(input).toLocaleString(undefined, {maximumFractionDigits: 2}) + ' '; }; }); diff --git a/gui/default/syncthing/core/naturalFilter.js b/gui/default/syncthing/core/naturalFilter.js deleted file mode 100644 index a1d80fda2..000000000 --- a/gui/default/syncthing/core/naturalFilter.js +++ /dev/null @@ -1,6 +0,0 @@ -angular.module('syncthing.core') - .filter('natural', function () { - return function (input, valid) { - return input.toFixed(decimals(input, valid)); - }; - });