1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Apply i18n to file size and download speed values

This commit is contained in:
Emir SARI 2024-04-02 21:28:25 +00:00 committed by Juraj Oravec
parent 185e612606
commit 48133ea417
2 changed files with 11 additions and 6 deletions

View File

@ -28,6 +28,7 @@
#include <QMenu> #include <QMenu>
#include <QClipboard> #include <QClipboard>
#include <QLocale>
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QMouseEvent> #include <QMouseEvent>
#include <QTimer> #include <QTimer>
@ -216,18 +217,19 @@ QString DownloadItem::currentSpeedToString(double speed)
return tr("Unknown speed"); return tr("Unknown speed");
} }
QLocale locale;
speed /= 1024; // kB speed /= 1024; // kB
if (speed < 1000) { if (speed < 1000) {
return QString::number(speed, 'f', 0) + QLatin1String(" ") + tr("kB/s"); return tr("%1 kB/s").arg(locale.toString(speed, 'f', 0));
} }
speed /= 1024; //MB speed /= 1024; //MB
if (speed < 1000) { if (speed < 1000) {
return QString::number(speed, 'f', 2) + QLatin1String(" ") + tr("MB/s"); return tr("%1 MB/s").arg(locale.toString(speed, 'f', 2));
} }
speed /= 1024; //GB speed /= 1024; //GB
return QString::number(speed, 'f', 2) + QLatin1String(" ") + tr("GB/s"); return tr("%1 GB/s").arg(locale.toString(speed, 'f', 2));
} }
void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 total) void DownloadItem::updateDownloadInfo(double currSpeed, qint64 received, qint64 total)

View File

@ -32,6 +32,7 @@
#include <QWidget> #include <QWidget>
#include <QApplication> #include <QApplication>
#include <QSslCertificate> #include <QSslCertificate>
#include <QLocale>
#include <QScreen> #include <QScreen>
#include <QUrl> #include <QUrl>
#include <QIcon> #include <QIcon>
@ -378,18 +379,20 @@ QString QzTools::fileSizeToString(qint64 size)
return QObject::tr("Unknown size"); return QObject::tr("Unknown size");
} }
QLocale locale;
double _size = size / 1024.0; // KB double _size = size / 1024.0; // KB
if (_size < 1000) { if (_size < 1000) {
return QString::number(_size > 1 ? _size : 1, 'f', 0) + QLatin1Char(' ') + QObject::tr("KB"); return QObject::tr("%1 kB").arg(locale.toString(_size > 1 ? _size : 1, 'f', 0));
} }
_size /= 1024; // MB _size /= 1024; // MB
if (_size < 1000) { if (_size < 1000) {
return QString::number(_size, 'f', 1) + QLatin1Char(' ') + QObject::tr("MB"); return QObject::tr("%1 MB").arg(locale.toString(_size, 'f', 1));
} }
_size /= 1024; // GB _size /= 1024; // GB
return QString::number(_size, 'f', 2) + QLatin1Char(' ') + QObject::tr("GB"); return QObject::tr("%1 GB").arg(locale.toString(_size, 'f', 2));
} }
QPixmap QzTools::createPixmapForSite(const QIcon &icon, const QString &title, const QString &url) QPixmap QzTools::createPixmapForSite(const QIcon &icon, const QString &title, const QString &url)