fix #4551: ui: translate byte unit in format_size
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>
This commit is contained in:
parent
9dba61e674
commit
01e64778ad
14
src/Utils.js
14
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: {
|
||||
|
Loading…
Reference in New Issue
Block a user