Browse Source

Avoid concatenation when dealing with translatable strings

Concatenation could be problematic with RTL languages.
adaptive-webui-19844
Gabriele 9 years ago
parent
commit
42c74f9553
  1. 2
      src/gui/properties/peerlistdelegate.h
  2. 51
      src/gui/properties/propertieswidget.cpp
  3. 6
      src/gui/rss/automatedrssdownloader.cpp
  4. 4
      src/gui/torrentcreatordlg.cpp
  5. 10
      src/gui/transferlistdelegate.cpp
  6. 66
      src/webui/www/public/scripts/prop-general.js

2
src/gui/properties/peerlistdelegate.h

@ -62,7 +62,7 @@ public: @@ -62,7 +62,7 @@ public:
QItemDelegate::drawBackground(painter, opt, index);
qreal speed = index.data().toDouble();
if (speed > 0.0)
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed)+tr("/s", "/second (i.e. per second)"));
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
break;
}
case PROGRESS:

51
src/gui/properties/propertieswidget.cpp

@ -358,17 +358,30 @@ void PropertiesWidget::loadDynamicData() { @@ -358,17 +358,30 @@ void PropertiesWidget::loadDynamicData() {
switch(stackedProperties->currentIndex()) {
case PropTabBar::MAIN_TAB: {
wasted->setText(Utils::Misc::friendlyUnit(m_torrent->wastedSize()));
upTotal->setText(Utils::Misc::friendlyUnit(m_torrent->totalUpload()) + " ("+Utils::Misc::friendlyUnit(m_torrent->totalPayloadUpload())+" "+tr("this session")+")");
dlTotal->setText(Utils::Misc::friendlyUnit(m_torrent->totalDownload()) + " ("+Utils::Misc::friendlyUnit(m_torrent->totalPayloadDownload())+" "+tr("this session")+")");
lbl_uplimit->setText(m_torrent->uploadLimit() <= 0 ? QString::fromUtf8(C_INFINITY) : Utils::Misc::friendlyUnit(m_torrent->uploadLimit())+tr("/s", "/second (i.e. per second)"));
lbl_dllimit->setText(m_torrent->downloadLimit() <= 0 ? QString::fromUtf8(C_INFINITY) : Utils::Misc::friendlyUnit(m_torrent->downloadLimit())+tr("/s", "/second (i.e. per second)"));
QString elapsed_txt = Utils::Misc::userFriendlyDuration(m_torrent->activeTime());
if (m_torrent->isSeed())
elapsed_txt += " ("+tr("seeded for %1", "e.g. seeded for 3m10s").arg(Utils::Misc::userFriendlyDuration(m_torrent->seedingTime()))+")";
upTotal->setText(tr("%1 (%2 this session)").arg(Utils::Misc::friendlyUnit(m_torrent->totalUpload()))
.arg(Utils::Misc::friendlyUnit(m_torrent->totalPayloadUpload())));
dlTotal->setText(tr("%1 (%2 this session)").arg(Utils::Misc::friendlyUnit(m_torrent->totalDownload()))
.arg(Utils::Misc::friendlyUnit(m_torrent->totalPayloadDownload())));
lbl_uplimit->setText(m_torrent->uploadLimit() <= 0 ? QString::fromUtf8(C_INFINITY) : Utils::Misc::friendlyUnit(m_torrent->uploadLimit(), true));
lbl_dllimit->setText(m_torrent->downloadLimit() <= 0 ? QString::fromUtf8(C_INFINITY) : Utils::Misc::friendlyUnit(m_torrent->downloadLimit(), true));
QString elapsed_txt;
if (m_torrent->isSeed())
elapsed_txt = tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)")
.arg(Utils::Misc::userFriendlyDuration(m_torrent->activeTime()))
.arg(Utils::Misc::userFriendlyDuration(m_torrent->seedingTime()));
else
elapsed_txt = Utils::Misc::userFriendlyDuration(m_torrent->activeTime());
lbl_elapsed->setText(elapsed_txt);
lbl_connections->setText(QString::number(m_torrent->connectionsCount()) + " (" + tr("%1 max", "e.g. 10 max").arg(QString::number(m_torrent->connectionsLimit())) + ")");
lbl_connections->setText(tr("%1 (%2 max)", "%1 and %2 are numbers, e.g. 3 (10 max)")
.arg(QString::number(m_torrent->connectionsCount()))
.arg(QString::number(m_torrent->connectionsLimit())));
label_eta_val->setText(Utils::Misc::userFriendlyDuration(m_torrent->eta()));
// Update next announce time
@ -378,16 +391,26 @@ void PropertiesWidget::loadDynamicData() { @@ -378,16 +391,26 @@ void PropertiesWidget::loadDynamicData() {
const qreal ratio = m_torrent->realRatio();
shareRatio->setText(ratio > BitTorrent::TorrentHandle::MAX_RATIO ? QString::fromUtf8(C_INFINITY) : Utils::String::fromDouble(ratio, 2));
label_seeds_val->setText(QString::number(m_torrent->seedsCount()) + " " + tr("(%1 total)","e.g. (10 total)").arg(QString::number(m_torrent->totalSeedsCount())));
label_peers_val->setText(QString::number(m_torrent->leechsCount()) + " " + tr("(%1 total)","e.g. (10 total)").arg(QString::number(m_torrent->totalLeechersCount())));
label_seeds_val->setText(tr("%1 (%2 total)", "%1 and %2 are numbers, e.g. 3 (10 total)")
.arg(QString::number(m_torrent->seedsCount()))
.arg(QString::number(m_torrent->totalSeedsCount())));
label_peers_val->setText(tr("%1 (%2 total)", "%1 and %2 are numbers, e.g. 3 (10 total)")
.arg(QString::number(m_torrent->leechsCount()))
.arg(QString::number(m_torrent->totalLeechersCount())));
label_dl_speed_val->setText(Utils::Misc::friendlyUnit(m_torrent->downloadPayloadRate()) + tr("/s", "/second (i.e. per second)") + " "
+ tr("(%1/s avg.)","e.g. (100KiB/s avg.)").arg(Utils::Misc::friendlyUnit(m_torrent->totalDownload() / (1 + m_torrent->activeTime() - m_torrent->finishedTime()))));
label_upload_speed_val->setText(Utils::Misc::friendlyUnit(m_torrent->uploadPayloadRate()) + tr("/s", "/second (i.e. per second)") + " "
+ tr("(%1/s avg.)", "e.g. (100KiB/s avg.)").arg(Utils::Misc::friendlyUnit(m_torrent->totalUpload() / (1 + m_torrent->activeTime()))));
label_dl_speed_val->setText(tr("%1 (%2 avg.)", "%1 and %2 are speed rates, e.g. 200KiB/s (100KiB/s avg.)")
.arg(Utils::Misc::friendlyUnit(m_torrent->downloadPayloadRate(), true))
.arg(m_torrent->totalDownload() / (1 + m_torrent->activeTime() - m_torrent->finishedTime()), true));
label_upload_speed_val->setText(tr("%1 (%2 avg.)", "%1 and %2 are speed rates, e.g. 200KiB/s (100KiB/s avg.)")
.arg(Utils::Misc::friendlyUnit(m_torrent->uploadPayloadRate(), true))
.arg(Utils::Misc::friendlyUnit(m_torrent->totalUpload() / (1 + m_torrent->activeTime())), true));
label_last_complete_val->setText(m_torrent->lastSeenComplete().isValid() ? m_torrent->lastSeenComplete().toString(Qt::DefaultLocaleShortDate) : tr("Never"));
label_completed_on_val->setText(m_torrent->completedTime().isValid() ? m_torrent->completedTime().toString(Qt::DefaultLocaleShortDate) : "");
label_added_on_val->setText(m_torrent->addedTime().toString(Qt::DefaultLocaleShortDate));
if (m_torrent->hasMetadata()) {

6
src/gui/rss/automatedrssdownloader.cpp

@ -258,11 +258,11 @@ void AutomatedRssDownloader::updateRuleDefinitionBox() @@ -258,11 +258,11 @@ void AutomatedRssDownloader::updateRuleDefinitionBox()
ui->comboAddPaused->setCurrentIndex(rule->addPaused());
ui->spinIgnorePeriod->setValue(rule->ignoreDays());
QDateTime dateTime = rule->lastMatch();
QString lMatch = tr("Last match: ");
QString lMatch;
if (dateTime.isValid())
lMatch += QString::number(dateTime.daysTo(QDateTime::currentDateTime())) + tr(" days ago.");
lMatch = tr("Last match: %1 days ago").arg(dateTime.daysTo(QDateTime::currentDateTime()));
else
lMatch += tr("Unknown");
lMatch = tr("Last match: Unknown");
ui->lblLastMatch->setText(lMatch);
updateMustLineValidity();
updateMustNotLineValidity();

4
src/gui/torrentcreatordlg.cpp

@ -121,7 +121,7 @@ void TorrentCreatorDlg::on_createButton_clicked() @@ -121,7 +121,7 @@ void TorrentCreatorDlg::on_createButton_clicked()
Preferences* const pref = Preferences::instance();
QString lastPath = pref->getCreateTorLastSavePath();
QString destination = QFileDialog::getSaveFileName(this, tr("Select destination torrent file"), lastPath, tr("Torrent Files")+QString::fromUtf8(" (*.torrent)"));
QString destination = QFileDialog::getSaveFileName(this, tr("Select destination torrent file"), lastPath, tr("Torrent Files (*.torrent)"));
if (destination.isEmpty())
return;
@ -173,7 +173,7 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path) @@ -173,7 +173,7 @@ void TorrentCreatorDlg::handleCreationSuccess(QString path, QString branch_path)
BitTorrent::Session::instance()->addTorrent(t, params);
}
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+Utils::Fs::toNativePath(path));
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully: %1", "%1 is the path of the torrent").arg(Utils::Fs::toNativePath(path)));
close();
}

10
src/gui/transferlistdelegate.cpp

@ -150,7 +150,7 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem @@ -150,7 +150,7 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
QItemDelegate::drawBackground(painter, opt, index);
const qulonglong speed = index.data().toULongLong();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed)+tr("/s", "/second (.i.e per second)"));
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
break;
}
case TorrentModel::TR_UPLIMIT:
@ -158,15 +158,17 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem @@ -158,15 +158,17 @@ void TransferListDelegate::paint(QPainter * painter, const QStyleOptionViewItem
QItemDelegate::drawBackground(painter, opt, index);
const qlonglong limit = index.data().toLongLong();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? Utils::String::fromDouble(limit/1024., 1) + " " + tr("KiB/s", "KiB/second (.i.e per second)") : QString::fromUtf8(C_INFINITY));
QItemDelegate::drawDisplay(painter, opt, opt.rect, limit > 0 ? Utils::Misc::friendlyUnit(limit, true) : QString::fromUtf8(C_INFINITY));
break;
}
case TorrentModel::TR_TIME_ELAPSED: {
QItemDelegate::drawBackground(painter, opt, index);
QString txt = Utils::Misc::userFriendlyDuration(index.data().toLongLong());
qlonglong seeding_time = index.data(Qt::UserRole).toLongLong();
QString txt;
if (seeding_time > 0)
txt += " ("+tr("seeded for %1", "e.g. seeded for 3m10s").arg(Utils::Misc::userFriendlyDuration(seeding_time))+")";
txt += tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)")
.arg(Utils::Misc::userFriendlyDuration(index.data().toLongLong()))
.arg(Utils::Misc::userFriendlyDuration(seeding_time));
QItemDelegate::drawDisplay(painter, opt, opt.rect, txt);
break;
}

66
src/webui/www/public/scripts/prop-general.js

@ -56,64 +56,102 @@ var loadTorrentData = function() { @@ -56,64 +56,102 @@ var loadTorrentData = function() {
if (data) {
var temp;
// Update Torrent data
temp = friendlyDuration(data.time_elapsed)
if (data.seeding_time > 0)
temp += " (" + "QBT_TR(seeded for %1)QBT_TR".replace("%1", friendlyDuration(data.seeding_time)) + ")";
temp = "QBT_TR(%1 (%2 this session))QBT_TR"
.replace("%1", friendlyDuration(data.time_elapsed))
.replace("%2", friendlyDuration(data.seeding_time))
else
temp = friendlyDuration(data.time_elapsed)
$('time_elapsed').set('html', temp);
$('eta').set('html', friendlyDuration(data.eta));
temp = data.nb_connections + " (" + "QBT_TR(%1 max)QBT_TR".replace("%1", data.nb_connections_limit) + ")";
temp = "QBT_TR(%1 (%2 max))QBT_TR"
.replace("%1", data.nb_connections)
.replace("%2", data.nb_connections_limit)
$('nb_connections').set('html', temp);
temp = friendlyUnit(data.total_downloaded) +
" (" + friendlyUnit(data.total_downloaded_session) +
" QBT_TR(this session)QBT_TR" + ")";
temp = "QBT_TR(%1 (%2 this session))QBT_TR"
.replace("%1", friendlyUnit(data.total_downloaded))
.replace("%2", friendlyUnit(data.total_downloaded_session))
$('total_downloaded').set('html', temp);
temp = friendlyUnit(data.total_uploaded) +
" (" + friendlyUnit(data.total_uploaded_session) +
" QBT_TR(this session)QBT_TR" + ")";
temp = "QBT_TR(%1 (%2 this session))QBT_TR"
.replace("%1", friendlyUnit(data.total_uploaded))
.replace("%2", friendlyUnit(data.total_uploaded_session))
$('total_uploaded').set('html', temp);
temp = friendlyUnit(data.dl_speed, true) + " QBT_TR((%1/s avg.))QBT_TR".replace("%1", friendlyUnit(data.dl_speed_avg));
temp = "QBT_TR(%1 (%2 avg.))QBT_TR"
.replace("%1", friendlyUnit(data.dl_speed, true))
.replace("%2", friendlyUnit(data.dl_speed_avg, true));
$('dl_speed').set('html', temp);
temp = friendlyUnit(data.up_speed, true) + " QBT_TR((%1/s avg.))QBT_TR".replace("%1", friendlyUnit(data.up_speed_avg));
temp = "QBT_TR(%1 (%2 avg.))QBT_TR"
.replace("%1", friendlyUnit(data.up_speed, true))
.replace("%2", friendlyUnit(data.up_speed_avg, true));
$('up_speed').set('html', temp);
temp = (data.dl_limit == -1 ? "∞" : friendlyUnit(data.dl_limit, true));
$('dl_limit').set('html', temp);
temp = (data.up_limit == -1 ? "∞" : friendlyUnit(data.up_limit, true));
$('up_limit').set('html', temp);
$('total_wasted').set('html', friendlyUnit(data.total_wasted));
temp = data.seeds + " QBT_TR((%1 total))QBT_TR".replace("%1", data.seeds_total);
temp = "QBT_TR(%1 (%2 total))QBT_TR"
.replace("%1", data.seeds)
.replace("%2", data.seeds_total);
$('seeds').set('html', temp);
temp = data.peers + " QBT_TR((%1 total))QBT_TR".replace("%1", data.peers_total);
temp = "QBT_TR(%1 (%2 total))QBT_TR"
.replace("%1", data.peers)
.replace("%2", data.peers_total);
$('peers').set('html', temp);
$('share_ratio').set('html', data.share_ratio.toFixed(2));
$('reannounce').set('html', friendlyDuration(data.reannounce));
if (data.last_seen != -1)
temp = new Date(data.last_seen * 1000).toLocaleString();
else
temp = "QBT_TR(Never)QBT_TR";
$('last_seen').set('html', temp);
$('total_size').set('html', friendlyUnit(data.total_size));
if (data.pieces_num != -1)
temp = "QBT_TR(%1 x %2 (have %3))QBT_TR".replace("%1", data.pieces_num).replace("%2", friendlyUnit(data.piece_size)).replace("%3", data.pieces_have);
temp = "QBT_TR(%1 x %2 (have %3))QBT_TR"
.replace("%1", data.pieces_num)
.replace("%2", friendlyUnit(data.piece_size))
.replace("%3", data.pieces_have);
else
temp = "QBT_TR(Unknown)QBT_TR";
$('pieces').set('html', temp);
$('created_by').set('html', data.created_by);
if (data.addition_date != -1)
temp = new Date(data.addition_date * 1000).toLocaleString();
else
temp = "QBT_TR(Unknown)QBT_TR";
$('addition_date').set('html', temp);
if (data.completion_date != -1)
temp = new Date(data.completion_date * 1000).toLocaleString();
else
temp = "";
$('completion_date').set('html', temp);
if (data.creation_date != -1)
temp = new Date(data.creation_date * 1000).toLocaleString();
else
temp = "QBT_TR(Unknown)QBT_TR";
$('creation_date').set('html', temp);
$('save_path').set('html', data.save_path);
$('comment').set('html', parseHtmlLinks(data.comment));
}
else {

Loading…
Cancel
Save