localize file sizes

This commit is contained in:
Danny Coates 2019-03-11 19:28:22 -07:00
parent 163899467d
commit adf9c7b96f
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
3 changed files with 30 additions and 7 deletions

View file

@ -56,7 +56,7 @@ const LOCALIZE_NUMBERS = !!(
typeof navigator === 'object'
);
const UNITS = ['B', 'kB', 'MB', 'GB'];
const UNITS = ['bytes', 'kb', 'mb', 'gb'];
function bytes(num) {
if (num < 1) {
return '0B';
@ -76,7 +76,10 @@ function bytes(num) {
// fall through
}
}
return `${nStr}${UNITS[exponent]}`;
return translate('fileSize', {
num: nStr,
units: translate(UNITS[exponent])
});
}
function percent(ratio) {
@ -256,6 +259,13 @@ function encryptedSize(size, rs = ECE_RECORD_SIZE, tagLength = TAG_LENGTH) {
return 21 + size + chunk_meta * Math.ceil(size / (rs - chunk_meta));
}
let translate = function() {
throw new Error('uninitialized translate function. call setTranslate first');
};
function setTranslate(t) {
translate = t;
}
module.exports = {
fadeOut,
delay,
@ -275,5 +285,6 @@ module.exports = {
secondsToL10nId,
timeLeft,
platform,
encryptedSize
encryptedSize,
setTranslate
};