import { i18n } from "@lingui/core"; import { t } from "@lingui/core/macro"; /** Human file size in the UI locale: B, KB or MB with at most one decimal. */ export function formatBytes(size: number): string { const locale = i18n.locale || "en"; if (size < 1024) return t`${size} B`; const format = (value: number) => new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }).format(value); if (size < 1024 * 1024) return t`${format(size / 1024)} KB`; return t`${format(size / (1024 * 1024))} MB`; }