From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 084AF93576 for ; Thu, 6 Apr 2023 13:38:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DCF42840C for ; Thu, 6 Apr 2023 13:38:10 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 6 Apr 2023 13:38:10 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1EC6C45EB3 for ; Thu, 6 Apr 2023 13:38:10 +0200 (CEST) From: Noel Ullreich To: pve-devel@lists.proxmox.com Date: Thu, 6 Apr 2023 13:38:06 +0200 Message-Id: <20230406113806.52027-3-n.ullreich@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230406113806.52027-1-n.ullreich@proxmox.com> References: <20230406113806.52027-1-n.ullreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.067 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-widget-toolkit v2 1/1] fix 4551: ui: translate byte unit in `format_size` X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Apr 2023 11:38:41 -0000 Some languages translate byte units like 'GiB' or write them in their own script. By `gettext`ing the units in the `format_size` function, we can translate the units for (almost) all of the web interface. Signed-off-by: Noel Ullreich --- src/Utils.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Utils.js b/src/Utils.js index 5e1a6f3..529e552 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -688,21 +688,23 @@ utilities: { }, format_size: function(size, useSI) { - let units = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; + let unitsSI = [gettext('B'), gettext('KB'), gettext('MB'), gettext('GB'), + gettext('TB'), gettext('PB'), gettext('EB'), gettext('ZB'), gettext('YB')]; + let unitsIEC = [gettext('B'), gettext('KiB'), gettext('MiB'), gettext('GiB'), + gettext('TiB'), gettext('PiB'), gettext('EiB'), gettext('ZiB'), gettext('YiB')]; let order = 0; + let commaDigits = 2; const baseValue = useSI ? 1000 : 1024; - while (size >= baseValue && order < units.length) { + while (size >= baseValue && order < unitsSI.length) { size = size / baseValue; order++; } - let unit = units[order], commaDigits = 2; + let unit = useSI ? unitsSI[order] : unitsIEC[order]; if (order === 0) { commaDigits = 0; - } else if (!useSI) { - unit += 'i'; } - return `${size.toFixed(commaDigits)} ${unit}B`; + return `${size.toFixed(commaDigits)} ${unit}`; }, SizeUnits: { -- 2.30.2