Merge bitcoin-core/gui#221: qt, refactor: rpcconsole translatable string fixes and improvements

6242beeb067139c01dd27c63ebcd24df5808cb15 Hoist repeated translated strings to RPCConsole struct members (Jon Atack)
0f035c12fb0a5c5f98fc2b9907d475c08018df36 RPCConsole::updateDetailWidget: convert strings to translated strings (Jon Atack)

Pull request description:

  - fixups from #206 review feedback (thanks!), see commit message for details
  - hoists repeatedly used translatable strings to the `RPCConsole` class for reuse

ACKs for top commit:
  hebasto:
    re-ACK 6242beeb067139c01dd27c63ebcd24df5808cb15
  Talkless:
    tACK 6242beeb067139c01dd27c63ebcd24df5808cb15, tested on Debian Sid with Qt 5.15.2. I see "Ban for.." translated to my native language as before, "To/From/Yes/No" are not but that's expected, as `.ts` files are not updated.
  jarolrod:
    ACK 6242beeb067139c01dd27c63ebcd24df5808cb15

Tree-SHA512: 20a296511c5ac03a816766237fa2731b0360dedebf1bea02711eb21d7e4eae2a63a051fe48f4726052edc3e6318952f01fef920cd4b22a8196c39c23d8e5cc3a
This commit is contained in:
MarcoFalke 2021-03-07 18:56:13 +01:00 committed by Konstantin Akimov
parent 0d1faa203e
commit 63b18006a3
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
2 changed files with 28 additions and 23 deletions

View File

@ -531,9 +531,9 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags
const QString list{"<ul><li>" + Join(CONNECTION_TYPE_DOC, QString("</li><li>")) + "</li></ul>"}; const QString list{"<ul><li>" + Join(CONNECTION_TYPE_DOC, QString("</li><li>")) + "</li></ul>"};
ui->peerConnectionTypeLabel->setToolTip(ui->peerConnectionTypeLabel->toolTip().arg(list)); ui->peerConnectionTypeLabel->setToolTip(ui->peerConnectionTypeLabel->toolTip().arg(list));
const QString hb_list{"<ul><li>\"" const QString hb_list{"<ul><li>\""
+ tr("To") + "\" " + tr("we selected the peer for high bandwidth relay") + "</li><li>\"" + ts.to + "\" " + tr("we selected the peer for high bandwidth relay") + "</li><li>\""
+ tr("From") + "\" " + tr("the peer selected us for high bandwidth relay") + "</li><li>\"" + ts.from + "\" " + tr("the peer selected us for high bandwidth relay") + "</li><li>\""
+ tr("No") + "\" " + tr("no high bandwidth relay selected") + "</li></ul>"}; + ts.no + "\" " + tr("no high bandwidth relay selected") + "</li></ul>"};
ui->peerHighBandwidthLabel->setToolTip(ui->peerHighBandwidthLabel->toolTip().arg(hb_list)); ui->peerHighBandwidthLabel->setToolTip(ui->peerHighBandwidthLabel->toolTip().arg(hb_list));
ui->dataDir->setToolTip(ui->dataDir->toolTip().arg(QString(nonbreaking_hyphen) + "datadir")); ui->dataDir->setToolTip(ui->dataDir->toolTip().arg(QString(nonbreaking_hyphen) + "datadir"));
ui->blocksDir->setToolTip(ui->blocksDir->toolTip().arg(QString(nonbreaking_hyphen) + "blocksdir")); ui->blocksDir->setToolTip(ui->blocksDir->toolTip().arg(QString(nonbreaking_hyphen) + "blocksdir"));
@ -707,10 +707,10 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
// create peer table context menu actions // create peer table context menu actions
QAction* disconnectAction = new QAction(tr("&Disconnect"), this); QAction* disconnectAction = new QAction(tr("&Disconnect"), this);
QAction* banAction1h = new QAction(tr("Ban for") + " " + tr("1 &hour"), this); QAction* banAction1h = new QAction(ts.ban_for + " " + tr("1 &hour"), this);
QAction* banAction24h = new QAction(tr("Ban for") + " " + tr("1 &day"), this); QAction* banAction24h = new QAction(ts.ban_for + " " + tr("1 &day"), this);
QAction* banAction7d = new QAction(tr("Ban for") + " " + tr("1 &week"), this); QAction* banAction7d = new QAction(ts.ban_for + " " + tr("1 &week"), this);
QAction* banAction365d = new QAction(tr("Ban for") + " " + tr("1 &year"), this); QAction* banAction365d = new QAction(ts.ban_for + " " + tr("1 &year"), this);
// create peer table context menu // create peer table context menu
peersTableContextMenu = new QMenu(this); peersTableContextMenu = new QMenu(this);
@ -1301,9 +1301,9 @@ void RPCConsole::updateDetailWidget()
ui->peerLastBlock->setText(TimeDurationField(time_now, stats->nodeStats.m_last_block_time)); ui->peerLastBlock->setText(TimeDurationField(time_now, stats->nodeStats.m_last_block_time));
ui->peerLastTx->setText(TimeDurationField(time_now, stats->nodeStats.m_last_tx_time)); ui->peerLastTx->setText(TimeDurationField(time_now, stats->nodeStats.m_last_tx_time));
QString bip152_hb_settings; QString bip152_hb_settings;
if (stats->nodeStats.m_bip152_highbandwidth_to) bip152_hb_settings += "To"; if (stats->nodeStats.m_bip152_highbandwidth_to) bip152_hb_settings = ts.to;
if (stats->nodeStats.m_bip152_highbandwidth_from) bip152_hb_settings += (bip152_hb_settings == "" ? "From" : "/From"); if (stats->nodeStats.m_bip152_highbandwidth_from) bip152_hb_settings += (bip152_hb_settings.isEmpty() ? ts.from : QLatin1Char('/') + ts.from);
if (bip152_hb_settings == "") bip152_hb_settings = "No"; if (bip152_hb_settings.isEmpty()) bip152_hb_settings = ts.no;
ui->peerHighBandwidth->setText(bip152_hb_settings); ui->peerHighBandwidth->setText(bip152_hb_settings);
ui->peerLastSend->setText(TimeDurationField(time_now, stats->nodeStats.m_last_send)); ui->peerLastSend->setText(TimeDurationField(time_now, stats->nodeStats.m_last_send));
ui->peerLastRecv->setText(TimeDurationField(time_now, stats->nodeStats.m_last_recv)); ui->peerLastRecv->setText(TimeDurationField(time_now, stats->nodeStats.m_last_recv));
@ -1317,7 +1317,7 @@ void RPCConsole::updateDetailWidget()
ui->peerConnectionType->setText(GUIUtil::ConnectionTypeToQString(stats->nodeStats.m_conn_type, /* prepend_direction */ true)); ui->peerConnectionType->setText(GUIUtil::ConnectionTypeToQString(stats->nodeStats.m_conn_type, /* prepend_direction */ true));
ui->peerNetwork->setText(GUIUtil::NetworkToQString(stats->nodeStats.m_network)); ui->peerNetwork->setText(GUIUtil::NetworkToQString(stats->nodeStats.m_network));
if (stats->nodeStats.m_permissionFlags == NetPermissionFlags::None) { if (stats->nodeStats.m_permissionFlags == NetPermissionFlags::None) {
ui->peerPermissions->setText(tr("N/A")); ui->peerPermissions->setText(ts.na);
} else { } else {
QStringList permissions; QStringList permissions;
for (const auto& permission : NetPermissions::ToStrings(stats->nodeStats.m_permissionFlags)) { for (const auto& permission : NetPermissions::ToStrings(stats->nodeStats.m_permissionFlags)) {
@ -1325,11 +1325,11 @@ void RPCConsole::updateDetailWidget()
} }
ui->peerPermissions->setText(permissions.join(" & ")); ui->peerPermissions->setText(permissions.join(" & "));
} }
ui->peerMappedAS->setText(stats->nodeStats.m_mapped_as != 0 ? QString::number(stats->nodeStats.m_mapped_as) : tr("N/A")); ui->peerMappedAS->setText(stats->nodeStats.m_mapped_as != 0 ? QString::number(stats->nodeStats.m_mapped_as) : ts.na);
auto dmn = clientModel->getMasternodeList().first.GetMNByService(stats->nodeStats.addr); auto dmn = clientModel->getMasternodeList().first.GetMNByService(stats->nodeStats.addr);
if (dmn == nullptr) { if (dmn == nullptr) {
ui->peerNodeType->setText(tr("Regular")); ui->peerNodeType->setText(tr("Regular"));
ui->peerPoSeScore->setText(tr("N/A")); ui->peerPoSeScore->setText(ts.na);
} else { } else {
if (stats->nodeStats.verifiedProRegTxHash.IsNull()) { if (stats->nodeStats.verifiedProRegTxHash.IsNull()) {
ui->peerNodeType->setText(tr("Masternode")); ui->peerNodeType->setText(tr("Masternode"));
@ -1343,23 +1343,23 @@ void RPCConsole::updateDetailWidget()
// nodeStateStats couldn't be fetched. // nodeStateStats couldn't be fetched.
if (stats->fNodeStateStatsAvailable) { if (stats->fNodeStateStatsAvailable) {
// Sync height is init to -1 // Sync height is init to -1
if (stats->nodeStateStats.nSyncHeight > -1) if (stats->nodeStateStats.nSyncHeight > -1) {
ui->peerSyncHeight->setText(QString("%1").arg(stats->nodeStateStats.nSyncHeight)); ui->peerSyncHeight->setText(QString("%1").arg(stats->nodeStateStats.nSyncHeight));
else } else {
ui->peerSyncHeight->setText(tr("Unknown")); ui->peerSyncHeight->setText(ts.unknown);
}
// Common height is init to -1 // Common height is init to -1
if (stats->nodeStateStats.nCommonHeight > -1) if (stats->nodeStateStats.nCommonHeight > -1) {
ui->peerCommonHeight->setText(QString("%1").arg(stats->nodeStateStats.nCommonHeight)); ui->peerCommonHeight->setText(QString("%1").arg(stats->nodeStateStats.nCommonHeight));
else } else {
ui->peerCommonHeight->setText(tr("Unknown")); ui->peerCommonHeight->setText(ts.unknown);
}
ui->peerHeight->setText(QString::number(stats->nodeStateStats.m_starting_height)); ui->peerHeight->setText(QString::number(stats->nodeStateStats.m_starting_height));
ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStateStats.m_ping_wait)); ui->peerPingWait->setText(GUIUtil::formatPingTime(stats->nodeStateStats.m_ping_wait));
ui->peerAddrRelayEnabled->setText(stats->nodeStateStats.m_addr_relay_enabled ? "Yes" : "No"); ui->peerAddrRelayEnabled->setText(stats->nodeStateStats.m_addr_relay_enabled ? ts.yes : ts.no);
ui->peerAddrProcessed->setText(QString::number(stats->nodeStateStats.m_addr_processed)); ui->peerAddrProcessed->setText(QString::number(stats->nodeStateStats.m_addr_processed));
ui->peerAddrRateLimited->setText(QString::number(stats->nodeStateStats.m_addr_rate_limited)); ui->peerAddrRateLimited->setText(QString::number(stats->nodeStateStats.m_addr_rate_limited));
ui->peerRelayTxes->setText(stats->nodeStateStats.m_relay_txs ? "Yes" : "No"); ui->peerRelayTxes->setText(stats->nodeStateStats.m_relay_txs ? ts.yes : ts.no);
} }
ui->peersTabRightPanel->show(); ui->peersTabRightPanel->show();

View File

@ -154,6 +154,11 @@ Q_SIGNALS:
void handleRestart(QStringList args); void handleRestart(QStringList args);
private: private:
struct TranslatedStrings {
const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},
ban_for{tr("Ban for")}, na{tr("N/A")}, unknown{tr("Unknown")};
} const ts;
void startExecutor(); void startExecutor();
void setTrafficGraphRange(TrafficGraphData::GraphRange range); void setTrafficGraphRange(TrafficGraphData::GraphRange range);
/** Build parameter list for restart */ /** Build parameter list for restart */