From 00b8be60f20b0f75918929c9ae569122b229e281 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Wed, 17 Oct 2018 21:43:37 +0200 Subject: humanFileSize: use toLocaleString humanFileSize: add test with locale humanFileSize: use canonical locale humanFileSize: skip test w/o toLocaleString support humanFileSize: stub getCanonicalLocale OC.getCanonicalLocale: cover undefined case humanFileSize: fix getCanonicalLocale stub Signed-off-by: Claas Augner --- core/js/js.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 12c47d546c1..880b986e17b 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -770,6 +770,16 @@ var OCP = {}, return false; }, + /** + * Returns the user's locale as a BCP 47 compliant language tag + * + * @return {String} locale string + */ + getCanonicalLocale: function() { + var locale = this.getLocale(); + return typeof locale === 'string' ? locale.replace(/_/g, '-') : locale; + }, + /** * Returns the user's locale * @@ -1843,6 +1853,9 @@ function humanFileSize(size, skipSmallSizes) { else if(relativeSize.substr(relativeSize.length-2,2)==='.0'){ relativeSize=relativeSize.substr(0,relativeSize.length-2); } + else{ + relativeSize = parseFloat(relativeSize).toLocaleString(OC.getCanonicalLocale()); + } return relativeSize + ' ' + readableFormat; } -- cgit v1.2.3