Skip to content

Commit 6242bee

Browse files
jonatackhebasto
andcommitted
Hoist repeated translated strings to RPCConsole struct members
and add missing braces to the touched conditionals. Co-authored-by: Hennadii Stepanov <[email protected]>
1 parent 0f035c1 commit 6242bee

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/qt/rpcconsole.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
474474
const QString list{"<ul><li>" + Join(CONNECTION_TYPE_DOC, QString("</li><li>")) + "</li></ul>"};
475475
ui->peerConnectionTypeLabel->setToolTip(ui->peerConnectionTypeLabel->toolTip().arg(list));
476476
const QString hb_list{"<ul><li>\""
477-
+ tr("To") + "\"" + tr("we selected the peer for high bandwidth relay") + "</li><li>\""
478-
+ tr("From") + "\"" + tr("the peer selected us for high bandwidth relay") + "</li><li>\""
479-
+ tr("No") + "\"" + tr("no high bandwidth relay selected") + "</li></ul>"};
477+
+ ts.to + "\"" + tr("we selected the peer for high bandwidth relay") + "</li><li>\""
478+
+ ts.from + "\"" + tr("the peer selected us for high bandwidth relay") + "</li><li>\""
479+
+ ts.no + "\"" + tr("no high bandwidth relay selected") + "</li></ul>"};
480480
ui->peerHighBandwidthLabel->setToolTip(ui->peerHighBandwidthLabel->toolTip().arg(hb_list));
481481
ui->dataDir->setToolTip(ui->dataDir->toolTip().arg(QString(nonbreaking_hyphen) + "datadir"));
482482
ui->blocksDir->setToolTip(ui->blocksDir->toolTip().arg(QString(nonbreaking_hyphen) + "blocksdir"));
@@ -619,10 +619,10 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
619619

620620
// create peer table context menu actions
621621
QAction* disconnectAction = new QAction(tr("&Disconnect"), this);
622-
QAction* banAction1h = new QAction(tr("Ban for") + " " + tr("1 &hour"), this);
623-
QAction* banAction24h = new QAction(tr("Ban for") + " " + tr("1 &day"), this);
624-
QAction* banAction7d = new QAction(tr("Ban for") + " " + tr("1 &week"), this);
625-
QAction* banAction365d = new QAction(tr("Ban for") + " " + tr("1 &year"), this);
622+
QAction* banAction1h = new QAction(ts.ban_for + " " + tr("1 &hour"), this);
623+
QAction* banAction24h = new QAction(ts.ban_for + " " + tr("1 &day"), this);
624+
QAction* banAction7d = new QAction(ts.ban_for + " " + tr("1 &week"), this);
625+
QAction* banAction365d = new QAction(ts.ban_for + " " + tr("1 &year"), this);
626626

627627
// create peer table context menu
628628
peersTableContextMenu = new QMenu(this);
@@ -1114,11 +1114,11 @@ void RPCConsole::updateDetailWidget()
11141114
peerAddrDetails += "<br />" + tr("via %1").arg(QString::fromStdString(stats->nodeStats.addrLocal));
11151115
ui->peerHeading->setText(peerAddrDetails);
11161116
ui->peerServices->setText(GUIUtil::formatServicesStr(stats->nodeStats.nServices));
1117-
ui->peerRelayTxes->setText(stats->nodeStats.fRelayTxes ? tr("Yes") : tr("No"));
1117+
ui->peerRelayTxes->setText(stats->nodeStats.fRelayTxes ? ts.yes : ts.no);
11181118
QString bip152_hb_settings;
1119-
if (stats->nodeStats.m_bip152_highbandwidth_to) bip152_hb_settings = tr("To");
1120-
if (stats->nodeStats.m_bip152_highbandwidth_from) bip152_hb_settings += (bip152_hb_settings.isEmpty() ? tr("From") : QLatin1Char('/') + tr("From"));
1121-
if (bip152_hb_settings.isEmpty()) bip152_hb_settings = tr("No");
1119+
if (stats->nodeStats.m_bip152_highbandwidth_to) bip152_hb_settings = ts.to;
1120+
if (stats->nodeStats.m_bip152_highbandwidth_from) bip152_hb_settings += (bip152_hb_settings.isEmpty() ? ts.from : QLatin1Char('/') + ts.from);
1121+
if (bip152_hb_settings.isEmpty()) bip152_hb_settings = ts.no;
11221122
ui->peerHighBandwidth->setText(bip152_hb_settings);
11231123
const int64_t time_now{GetSystemTimeInSeconds()};
11241124
ui->peerConnTime->setText(GUIUtil::formatDurationStr(time_now - stats->nodeStats.nTimeConnected));
@@ -1136,31 +1136,31 @@ void RPCConsole::updateDetailWidget()
11361136
ui->peerConnectionType->setText(GUIUtil::ConnectionTypeToQString(stats->nodeStats.m_conn_type, /* prepend_direction */ true));
11371137
ui->peerNetwork->setText(GUIUtil::NetworkToQString(stats->nodeStats.m_network));
11381138
if (stats->nodeStats.m_permissionFlags == PF_NONE) {
1139-
ui->peerPermissions->setText(tr("N/A"));
1139+
ui->peerPermissions->setText(ts.na);
11401140
} else {
11411141
QStringList permissions;
11421142
for (const auto& permission : NetPermissions::ToStrings(stats->nodeStats.m_permissionFlags)) {
11431143
permissions.append(QString::fromStdString(permission));
11441144
}
11451145
ui->peerPermissions->setText(permissions.join(" & "));
11461146
}
1147-
ui->peerMappedAS->setText(stats->nodeStats.m_mapped_as != 0 ? QString::number(stats->nodeStats.m_mapped_as) : tr("N/A"));
1147+
ui->peerMappedAS->setText(stats->nodeStats.m_mapped_as != 0 ? QString::number(stats->nodeStats.m_mapped_as) : ts.na);
11481148

11491149
// This check fails for example if the lock was busy and
11501150
// nodeStateStats couldn't be fetched.
11511151
if (stats->fNodeStateStatsAvailable) {
11521152
// Sync height is init to -1
1153-
if (stats->nodeStateStats.nSyncHeight > -1)
1153+
if (stats->nodeStateStats.nSyncHeight > -1) {
11541154
ui->peerSyncHeight->setText(QString("%1").arg(stats->nodeStateStats.nSyncHeight));
1155-
else
1156-
ui->peerSyncHeight->setText(tr("Unknown"));
1157-
1155+
} else {
1156+
ui->peerSyncHeight->setText(ts.unknown);
1157+
}
11581158
// Common height is init to -1
1159-
if (stats->nodeStateStats.nCommonHeight > -1)
1159+
if (stats->nodeStateStats.nCommonHeight > -1) {
11601160
ui->peerCommonHeight->setText(QString("%1").arg(stats->nodeStateStats.nCommonHeight));
1161-
else
1162-
ui->peerCommonHeight->setText(tr("Unknown"));
1163-
1161+
} else {
1162+
ui->peerCommonHeight->setText(ts.unknown);
1163+
}
11641164
ui->peerHeight->setText(QString::number(stats->nodeStateStats.m_starting_height));
11651165
ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStateStats.m_ping_wait_usec));
11661166
}

src/qt/rpcconsole.h

+5
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ public Q_SLOTS:
136136
void cmdRequest(const QString &command, const WalletModel* wallet_model);
137137

138138
private:
139+
struct TranslatedStrings {
140+
const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},
141+
ban_for{tr("Ban for")}, na{tr("N/A")}, unknown{tr("Unknown")};
142+
} const ts;
143+
139144
void startExecutor();
140145
void setTrafficGraphRange(int mins);
141146

0 commit comments

Comments
 (0)