]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
fix #4551: ui: translate byte unit in `format_size`
authorNoel Ullreich <n.ullreich@proxmox.com>
Thu, 6 Apr 2023 11:38:06 +0000 (13:38 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 1 Jun 2023 14:10:34 +0000 (16:10 +0200)
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 <n.ullreich@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/Utils.js

index ef72630951b64569ca7195faba8e2079e4ff7012..6daba97a098e70d53f2f966259af407fc2d6e634 100644 (file)
@@ -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: {