From: Noel Ullreich <n.ullreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-widget-toolkit 1/1] translate units in `format_size`
Date: Tue, 4 Apr 2023 12:14:39 +0200 [thread overview]
Message-ID: <20230404101439.34264-3-n.ullreich@proxmox.com> (raw)
In-Reply-To: <20230404101439.34264-1-n.ullreich@proxmox.com>
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 <n.ullreich@proxmox.com>
---
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
prev parent reply other threads:[~2023-04-04 10:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-04 10:14 [pve-devel] [PATCH pve_manager, proxmox-widget-toolkit 0/2] fix 4551: Storage units should be gettextized to be translated Noel Ullreich
2023-04-04 10:14 ` [pve-devel] [PATCH pve_manager 1/1] Translate units Noel Ullreich
2023-04-04 13:18 ` Thomas Lamprecht
2023-04-04 10:14 ` Noel Ullreich [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230404101439.34264-3-n.ullreich@proxmox.com \
--to=n.ullreich@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.