From adf9c7b96f51b42b9038dbe60fe7ff3b8c31a7a5 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Mon, 11 Mar 2019 19:28:22 -0700 Subject: [PATCH] localize file sizes --- app/main.js | 2 ++ app/utils.js | 17 ++++++++++++++--- public/locales/en-US/send.ftl | 18 ++++++++++++++---- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/main.js b/app/main.js index b64a5955..fb53fb43 100644 --- a/app/main.js +++ b/app/main.js @@ -17,6 +17,7 @@ import './main.css'; import User from './user'; import { getTranslator } from './locale'; import Archive from './archive'; +import { setTranslate } from './utils'; if (navigator.doNotTrack !== '1' && window.RAVEN_CONFIG) { Raven.config(window.SENTRY_ID, window.RAVEN_CONFIG).install(); @@ -40,6 +41,7 @@ if (process.env.NODE_ENV === 'production') { } const translate = await getTranslator(LOCALE); + setTranslate(translate); window.initialState = { LIMITS, DEFAULTS, diff --git a/app/utils.js b/app/utils.js index 07057190..735e6da9 100644 --- a/app/utils.js +++ b/app/utils.js @@ -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 }; diff --git a/public/locales/en-US/send.ftl b/public/locales/en-US/send.ftl index 270ef0ac..ea1e9ab6 100644 --- a/public/locales/en-US/send.ftl +++ b/public/locales/en-US/send.ftl @@ -73,7 +73,17 @@ fileCount = { $num -> [one] 1 file *[other] { $num } files } -# size is a localized number followed by a unit of bytes, ex. 2.5GB +# byte abbreviation +bytes = B +# kibibyte abbreviation +kb = KB +# mebibyte abbreviation +mb = MB +# gibibyte abbreviation +gb = GB +# localized number and byte abbreviation. example "2.5MB" +fileSize = { $num }{ $units } +# $size is the size of the file, displayed using the fileSize message as format (e.g. "2.5MB") totalSize = Total size: { $size } # the next line after the colon contains a file name copyLinkDescription = Copy the link to share your file: @@ -103,15 +113,15 @@ uploadButton = Upload # the first part of the string 'Drag and drop files or click to send up to 1GB' dragAndDropFiles = Drag and drop files # the second part of the string 'Drag and drop files or click to send up to 1GB' -# size is a localized number followed by a unit of bytes, ex. 2.5GB +# $size is the size of the file, displayed using the fileSize message as format (e.g. "2.5MB") orClickWithSize = or click to send up to { $size } addPassword = Protect with password emailPlaceholder = Enter your email -# size is a localized number followed by a unit of bytes, ex. 2.5GB +# $size is the size of the file, displayed using the fileSize message as format (e.g. "2.5MB") signInSizeBump = Sign in to send up to { $size } signInButton = Sign in/up accountBenefitTitle = Create a { -firefox } Account or sign in -# size is a localized number followed by a unit of bytes, ex. 2.5GB +# $size is the size of the file, displayed using the fileSize message as format (e.g. "2.5MB") accountBenefitLargeFiles = Share files up to { $size } accountBenefitDownloadCount = Share files with more people accountBenefitTimeLimit = { $count ->