mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-20 13:16:19 +01:00
Fix rate unit displays
This commit is contained in:
parent
88c437562b
commit
712fbb53c7
@ -98,20 +98,21 @@ module.exports = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
i18next.services.formatter.add("rate", (value, lng, options) => {
|
i18next.services.formatter.add("rate", (value, lng, options) => {
|
||||||
if (value === 0) return "0 Bps";
|
|
||||||
|
|
||||||
const bits = options.bits ? value : value / 8;
|
const k = options.binary ? 1024 : 1000;
|
||||||
const k = 1024;
|
const sizes = options.bits ? (options.binary ? BIBIT_UNITS : BIT_UNITS) : (options.binary ? BIBYTE_UNITS : BYTE_UNITS);
|
||||||
|
|
||||||
|
if (value === 0) return `0 ${sizes[0]}/s`;
|
||||||
|
|
||||||
const dm = options.decimals ? options.decimals : 0;
|
const dm = options.decimals ? options.decimals : 0;
|
||||||
const sizes = ["Bps", "KiBps", "MiBps", "GiBps", "TiBps", "PiBps", "EiBps", "ZiBps", "YiBps"];
|
|
||||||
|
|
||||||
const i = Math.floor(Math.log(bits) / Math.log(k));
|
const i = options.binary ? 2 : Math.floor(Math.log(value) / Math.log(k));
|
||||||
|
|
||||||
const formatted = new Intl.NumberFormat(lng, { maximumFractionDigits: dm, minimumFractionDigits: dm }).format(
|
const formatted = new Intl.NumberFormat(lng, { maximumFractionDigits: dm, minimumFractionDigits: dm }).format(
|
||||||
parseFloat(bits / k ** i)
|
parseFloat(value / k ** i)
|
||||||
);
|
);
|
||||||
|
|
||||||
return `${formatted} ${sizes[i]}`;
|
return `${formatted} ${sizes[i]}/s`;
|
||||||
});
|
});
|
||||||
|
|
||||||
i18next.services.formatter.add("percent", (value, lng, options) =>
|
i18next.services.formatter.add("percent", (value, lng, options) =>
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
"bytes": "{{value, bytes}}",
|
"bytes": "{{value, bytes}}",
|
||||||
"bits": "{{value, bytes(bits: true)}}",
|
"bits": "{{value, bytes(bits: true)}}",
|
||||||
"bbytes": "{{value, bytes(binary: true)}}",
|
"bbytes": "{{value, bytes(binary: true)}}",
|
||||||
"bbits": "{{value, bytes(bits: true, binary: true)}}",
|
"bbits": "{{value, bytes(bits: true; binary: true)}}",
|
||||||
"byterate": "{{value, rate}}",
|
"byterate": "{{value, rate(bits: false)}}",
|
||||||
|
"bibyterate": "{{value, rate(bits: false; binary: true)}}",
|
||||||
"bitrate": "{{value, rate(bits: true)}}",
|
"bitrate": "{{value, rate(bits: true)}}",
|
||||||
|
"bibitrate": "{{value, rate(bits: true; binary: true)}}",
|
||||||
"percent": "{{value, percent}}",
|
"percent": "{{value, percent}}",
|
||||||
"number": "{{value, number}}",
|
"number": "{{value, number}}",
|
||||||
"ms": "{{value, number}}"
|
"ms": "{{value, number}}"
|
||||||
|
@ -44,9 +44,9 @@ export default function Component({ service }) {
|
|||||||
return (
|
return (
|
||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block label="qbittorrent.leech" value={t("common.number", { value: leech })} />
|
<Block label="qbittorrent.leech" value={t("common.number", { value: leech })} />
|
||||||
<Block label="qbittorrent.download" value={t("common.bitrate", { value: rateDl })} />
|
<Block label="qbittorrent.download" value={t("common.bibyterate", { value: rateDl, decimals: 1 })} />
|
||||||
<Block label="qbittorrent.seed" value={t("common.number", { value: completed })} />
|
<Block label="qbittorrent.seed" value={t("common.number", { value: completed })} />
|
||||||
<Block label="qbittorrent.upload" value={t("common.bitrate", { value: rateUl })} />
|
<Block label="qbittorrent.upload" value={t("common.bibyterate", { value: rateUl, decimals: 1 })} />
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,9 @@ export default function Component({ service }) {
|
|||||||
<Container service={service}>
|
<Container service={service}>
|
||||||
<Block
|
<Block
|
||||||
label="speedtest.download"
|
label="speedtest.download"
|
||||||
value={t("common.bitrate", { value: speedtestData.data.download * 1024 * 1024 })}
|
value={t("common.bitrate", { value: speedtestData.data.download * 1000 * 1000 })}
|
||||||
/>
|
/>
|
||||||
<Block label="speedtest.upload" value={t("common.bitrate", { value: speedtestData.data.upload * 1024 * 1024 })} />
|
<Block label="speedtest.upload" value={t("common.bitrate", { value: speedtestData.data.upload * 1000 * 1000 })} />
|
||||||
<Block
|
<Block
|
||||||
label="speedtest.ping"
|
label="speedtest.ping"
|
||||||
value={t("common.ms", {
|
value={t("common.ms", {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user