From cf36a33aea844062a391b989656d91fd56ee10ca Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Wed, 7 Feb 2018 19:46:18 -0800 Subject: [PATCH] localize other displayed numbers --- app/templates/file.js | 5 ++++- app/templates/selectbox.js | 5 ++++- app/utils.js | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/templates/file.js b/app/templates/file.js index 573302eb..d6558de5 100644 --- a/app/templates/file.js +++ b/app/templates/file.js @@ -1,5 +1,6 @@ const html = require('choo/html'); const assets = require('../../common/assets'); +const number = require('../utils').number; function timeLeft(milliseconds, state) { const minutes = Math.floor(milliseconds / 1000 / 60); @@ -40,7 +41,9 @@ module.exports = function(file, state, emit) { ${remainingTime} - ${totalDownloads} / ${downloadLimit} + ${number(totalDownloads)} / ${number( + downloadLimit + )} ${options.map( i => - html`
  • ${i}
  • ` + html`
  • ${number( + i + )}
  • ` )} `; diff --git a/app/utils.js b/app/utils.js index 9fea560c..e6d8d27b 100644 --- a/app/utils.js +++ b/app/utils.js @@ -117,6 +117,14 @@ function percent(ratio) { return `${Math.floor(ratio * 100)}%`; } +function number(n) { + if (LOCALIZE_NUMBERS) { + const locale = document.querySelector('html').lang; + return n.toLocaleString(locale); + } + return n.toString(); +} + function allowedCopy() { const support = !!document.queryCommandSupported; return support ? document.queryCommandSupported('copy') : false; @@ -171,6 +179,7 @@ module.exports = { allowedCopy, bytes, percent, + number, copyToClipboard, arrayToB64, b64ToArray,