translate sizes and show speeds in bps

This commit is contained in:
nikk gitanes
2021-07-17 08:35:38 +03:00
parent b850e4b6aa
commit 3b33ace04f
18 changed files with 119 additions and 88 deletions

View File

@@ -205,7 +205,7 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
<LoadingProgress
value={Filled}
fullAmount={bufferSize}
label={`${humanizeSize(bufferSize)} / ${humanizeSize(Filled) || '0 B'}`}
label={`${humanizeSize(bufferSize)} / ${humanizeSize(Filled) || `0 ${t('B')}`}`}
/>
</SectionHeader>

View File

@@ -7,7 +7,7 @@ import {
PhotoSizeSelectSmall as PhotoSizeSelectSmallIcon,
Build as BuildIcon,
} from '@material-ui/icons'
import { getPeerString, humanizeSize } from 'utils/Utils'
import { getPeerString, humanizeSize, humanizeSpeed } from 'utils/Utils'
import { useTranslation } from 'react-i18next'
import { GETTING_INFO, IN_DB, CLOSED, PRELOAD, WORKING } from 'torrentStates'
@@ -21,7 +21,7 @@ export const DownlodSpeedWidget = ({ data }) => {
return (
<StatisticsField
title={t('DownloadSpeed')}
value={humanizeSize(data) || '0 B'}
value={humanizeSpeed(data) || `0 ${t('bps')}`}
iconBg={iconBGColor}
valueBg={valueBGColor}
icon={ArrowDownwardIcon}
@@ -36,7 +36,7 @@ export const UploadSpeedWidget = ({ data }) => {
return (
<StatisticsField
title={t('UploadSpeed')}
value={humanizeSize(data) || '0 B'}
value={humanizeSpeed(data) || `0 ${t('bps')}`}
iconBg={iconBGColor}
valueBg={valueBGColor}
icon={ArrowUpwardIcon}
@@ -51,7 +51,7 @@ export const PeersWidget = ({ data }) => {
return (
<StatisticsField
title={t('Peers')}
value={getPeerString(data) || '[0] 0 / 0'}
value={getPeerString(data) || '0 · 0 / 0'}
iconBg={iconBGColor}
valueBg={valueBGColor}
icon={SwapVerticalCircleIcon}

View File

@@ -5,7 +5,7 @@ import {
Close as CloseIcon,
Delete as DeleteIcon,
} from '@material-ui/icons'
import { getPeerString, humanizeSize, removeRedundantCharacters } from 'utils/Utils'
import { getPeerString, humanizeSize, humanizeSpeed, removeRedundantCharacters } from 'utils/Utils'
import { torrentsHost } from 'utils/Hosts'
import { NoImageIcon } from 'icons'
import DialogTorrentDetailsContent from 'components/DialogTorrentDetailsContent'
@@ -103,7 +103,7 @@ const Torrent = ({ torrent }) => {
<div className='description-statistics-element-wrapper'>
<div className='description-section-name'>{t('Speed')}</div>
<div className='description-statistics-element-value'>
{downloadSpeed > 0 ? humanizeSize(downloadSpeed) : '---'}
{downloadSpeed > 0 ? humanizeSpeed(downloadSpeed) : '---'}
</div>
</div>

View File

@@ -20,6 +20,8 @@
},
"AddFromLink": "Add from Link",
"AddNewTorrent": "Add new torrent",
"B": "B",
"bps": "bps",
"Buffer": "Preload Buffer / Cache",
"BufferNote": "Set Preload Cache Before Play > 32 MB in settings to change preload size",
"Cache": "Cache",
@@ -50,11 +52,17 @@
"Episode": "Episode",
"FromLatestFile": "From Latest File",
"Full": "Full",
"GB": "GB",
"Gbps": "Gbps",
"Host": "Host",
"Info": "Info",
"KB": "KB",
"kbps": "kbps",
"Kilobytes": "Kilobytes",
"LatestFilePlayed": "Latest file played:",
"Links": "Links",
"MB": "MB",
"Mbps": "Mbps",
"Name": "Name",
"NoTorrentsAdded": "No torrents added",
"Offline": "Offline",
@@ -72,6 +80,7 @@
"Save": "Save",
"ScrollDown": "scroll down",
"Season": "Season",
"Sec": "s",
"Seconds": "Seconds",
"SelectSeason": "Select Season",
"SettingsDialog": {
@@ -117,6 +126,8 @@
"SpecialThanks": "Special Thanks",
"Speed": "Speed",
"Support": "Support",
"TB": "TB",
"Tbps": "Tbps",
"ThanksToEveryone": "Thanks to everyone who tested and helped.",
"TorrentAdded": "Added",
"TorrentClosed": "Сlosed",

View File

@@ -20,6 +20,8 @@
},
"AddFromLink": "Добавить",
"AddNewTorrent": "Добавить новый торрент",
"B": "Б",
"bps": "бит/c",
"Buffer": "Предзагрузка / Кеш",
"BufferNote": "Установите Буфер предзагрузки > 32 МБ в настройках для измененения размера предзагрузки",
"Cache": "Кеш",
@@ -50,12 +52,17 @@
"Episode": "Серия",
"FromLatestFile": "C последнего файла",
"Full": "Полный",
"GB": "ГБ",
"Gbps": "Гбит/c",
"Host": "Хост",
"Info": "Инфо",
"KB": "КБ",
"kbps": "кбит/с",
"Kilobytes": "Килобайты",
"LatestFilePlayed": "Последний воспроизведенный файл:",
"Links": "Ссылки",
"MB": "МБ",
"Mbps": "Мбит/c",
"Name": "Название",
"NoTorrentsAdded": "Нет торрентов",
"Offline": "Сервер не доступен",
@@ -73,7 +80,7 @@
"Save": "Сохранить",
"ScrollDown": "прокрутить вниз",
"Season": "Сезон",
"Sec": "Cек.",
"Sec": "c",
"Seconds": "Секунды",
"SelectSeason": "Выбор сезона",
"SettingsDialog": {
@@ -119,6 +126,8 @@
"SpecialThanks": "Отдельное спасибо",
"Speed": "Скорость",
"Support": "Поддержать",
"TB": "ТБ",
"Tbps": "Тбит/с",
"ThanksToEveryone": "Спасибо всем, кто тестировал и помогал!",
"TorrentAdded": "Добавлен",
"TorrentClosed": "Закрыт",

View File

@@ -1,16 +1,27 @@
import axios from 'axios'
import i18n from '../i18n'
import { torrentsHost } from './Hosts'
export function humanizeSize(size) {
if (!size) return ''
const i = Math.floor(Math.log(size) / Math.log(1024))
return `${(size / Math.pow(1024, i)).toFixed(2) * 1} ${['B', 'KB', 'MB', 'GB', 'TB'][i]}`
return `${(size / Math.pow(1024, i)).toFixed(2) * 1} ${
[i18n.t('B'), i18n.t('KB'), i18n.t('MB'), i18n.t('GB'), i18n.t('TB')][i]
}`
}
export function humanizeSpeed(speed) {
if (!speed) return ''
const i = Math.floor(Math.log(speed * 8) / Math.log(1000))
return `${((speed * 8) / Math.pow(1000, i)).toFixed(0) * 1} ${
[i18n.t('bps'), i18n.t('kbps'), i18n.t('Mbps'), i18n.t('Gbps'), i18n.t('Tbps')][i]
}`
}
export function getPeerString(torrent) {
if (!torrent || !torrent.connected_seeders) return null
return `[${torrent.connected_seeders}] ${torrent.active_peers} / ${torrent.total_peers}`
return `${torrent.connected_seeders} · ${torrent.active_peers} / ${torrent.total_peers}`
}
export const shortenText = (text, sympolAmount) =>