Skip to content

Commit 917ca93

Browse files
committed
Make ThreadSafe{MessageBox|Question} bilingual
1 parent 23b9fa2 commit 917ca93

File tree

14 files changed

+82
-64
lines changed

14 files changed

+82
-64
lines changed

src/httprpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static bool InitRPCAuthentication()
252252
LogPrintf("No rpcpassword set - using random cookie authentication.\n");
253253
if (!GenerateAuthCookie(&strRPCUserColonPass)) {
254254
uiInterface.ThreadSafeMessageBox(
255-
_("Error: A fatal internal error occurred, see debug.log for details").translated, // Same message as AbortNode
255+
_("Error: A fatal internal error occurred, see debug.log for details"), // Same message as AbortNode
256256
"", CClientUIInterface::MSG_ERROR);
257257
return false;
258258
}

src/httpserver.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
#include <chainparamsbase.h>
88
#include <compat.h>
9-
#include <util/threadnames.h>
10-
#include <util/system.h>
11-
#include <util/strencodings.h>
129
#include <netbase.h>
1310
#include <rpc/protocol.h> // For HTTP status codes
1411
#include <shutdown.h>
1512
#include <sync.h>
1613
#include <ui_interface.h>
14+
#include <util/strencodings.h>
15+
#include <util/system.h>
16+
#include <util/threadnames.h>
17+
#include <util/translation.h>
1718

1819
#include <deque>
1920
#include <memory>
@@ -175,7 +176,7 @@ static bool InitHTTPAllowList()
175176
LookupSubNet(strAllow, subnet);
176177
if (!subnet.IsValid()) {
177178
uiInterface.ThreadSafeMessageBox(
178-
strprintf("Invalid -rpcallowip subnet specification: %s. Valid are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24).", strAllow),
179+
strprintf(Untranslated("Invalid -rpcallowip subnet specification: %s. Valid are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24)."), strAllow),
179180
"", CClientUIInterface::MSG_ERROR);
180181
return false;
181182
}

src/index/base.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <tinyformat.h>
99
#include <ui_interface.h>
1010
#include <util/system.h>
11+
#include <util/translation.h>
1112
#include <validation.h>
1213
#include <warnings.h>
1314

@@ -23,7 +24,7 @@ static void FatalError(const char* fmt, const Args&... args)
2324
SetMiscWarning(strMessage);
2425
LogPrintf("*** %s\n", strMessage);
2526
uiInterface.ThreadSafeMessageBox(
26-
"Error: A fatal internal error occurred, see debug.log for details",
27+
Untranslated("Error: A fatal internal error occurred, see debug.log for details"),
2728
"", CClientUIInterface::MSG_ERROR);
2829
StartShutdown();
2930
}

src/init.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ bool AppInitMain(NodeContext& node)
15421542
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
15431543
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
15441544
};
1545-
std::string strLoadError;
1545+
bilingual_str strLoadError;
15461546

15471547
uiInterface.InitMessage(_("Loading block index...").translated);
15481548

@@ -1573,7 +1573,7 @@ bool AppInitMain(NodeContext& node)
15731573
// From here on out fReindex and fReset mean something different!
15741574
if (!LoadBlockIndex(chainparams)) {
15751575
if (ShutdownRequested()) break;
1576-
strLoadError = _("Error loading block database").translated;
1576+
strLoadError = _("Error loading block database");
15771577
break;
15781578
}
15791579

@@ -1587,7 +1587,7 @@ bool AppInitMain(NodeContext& node)
15871587
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
15881588
// in the past, but is now trying to run unpruned.
15891589
if (fHavePruned && !fPruneMode) {
1590-
strLoadError = _("You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain").translated;
1590+
strLoadError = _("You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain");
15911591
break;
15921592
}
15931593

@@ -1596,7 +1596,7 @@ bool AppInitMain(NodeContext& node)
15961596
// (otherwise we use the one already on disk).
15971597
// This is called again in ThreadImport after the reindex completes.
15981598
if (!fReindex && !LoadGenesisBlock(chainparams)) {
1599-
strLoadError = _("Error initializing block database").translated;
1599+
strLoadError = _("Error initializing block database");
16001600
break;
16011601
}
16021602

@@ -1614,21 +1614,21 @@ bool AppInitMain(NodeContext& node)
16141614

16151615
chainstate->CoinsErrorCatcher().AddReadErrCallback([]() {
16161616
uiInterface.ThreadSafeMessageBox(
1617-
_("Error reading from database, shutting down.").translated,
1617+
_("Error reading from database, shutting down."),
16181618
"", CClientUIInterface::MSG_ERROR);
16191619
});
16201620

16211621
// If necessary, upgrade from older database format.
16221622
// This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
16231623
if (!chainstate->CoinsDB().Upgrade()) {
1624-
strLoadError = _("Error upgrading chainstate database").translated;
1624+
strLoadError = _("Error upgrading chainstate database");
16251625
failed_chainstate_init = true;
16261626
break;
16271627
}
16281628

16291629
// ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
16301630
if (!chainstate->ReplayBlocks(chainparams)) {
1631-
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.").translated;
1631+
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.");
16321632
failed_chainstate_init = true;
16331633
break;
16341634
}
@@ -1640,7 +1640,7 @@ bool AppInitMain(NodeContext& node)
16401640
if (!is_coinsview_empty(chainstate)) {
16411641
// LoadChainTip initializes the chain based on CoinsTip()'s best block
16421642
if (!chainstate->LoadChainTip(chainparams)) {
1643-
strLoadError = _("Error initializing block database").translated;
1643+
strLoadError = _("Error initializing block database");
16441644
failed_chainstate_init = true;
16451645
break; // out of the per-chainstate loop
16461646
}
@@ -1653,7 +1653,7 @@ bool AppInitMain(NodeContext& node)
16531653
}
16541654
} catch (const std::exception& e) {
16551655
LogPrintf("%s\n", e.what());
1656-
strLoadError = _("Error opening block database").translated;
1656+
strLoadError = _("Error opening block database");
16571657
break;
16581658
}
16591659

@@ -1669,7 +1669,7 @@ bool AppInitMain(NodeContext& node)
16691669
if (!chainstate->RewindBlockIndex(chainparams)) {
16701670
strLoadError = _(
16711671
"Unable to rewind the database to a pre-fork state. "
1672-
"You will need to redownload the blockchain").translated;
1672+
"You will need to redownload the blockchain");
16731673
failed_rewind = true;
16741674
break; // out of the per-chainstate loop
16751675
}
@@ -1698,7 +1698,7 @@ bool AppInitMain(NodeContext& node)
16981698
if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) {
16991699
strLoadError = _("The block database contains a block which appears to be from the future. "
17001700
"This may be due to your computer's date and time being set incorrectly. "
1701-
"Only rebuild the block database if you are sure that your computer's date and time are correct").translated;
1701+
"Only rebuild the block database if you are sure that your computer's date and time are correct");
17021702
failed_verification = true;
17031703
break;
17041704
}
@@ -1710,15 +1710,15 @@ bool AppInitMain(NodeContext& node)
17101710
chainparams, &chainstate->CoinsDB(),
17111711
gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
17121712
gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS))) {
1713-
strLoadError = _("Corrupted block database detected").translated;
1713+
strLoadError = _("Corrupted block database detected");
17141714
failed_verification = true;
17151715
break;
17161716
}
17171717
}
17181718
}
17191719
} catch (const std::exception& e) {
17201720
LogPrintf("%s\n", e.what());
1721-
strLoadError = _("Error opening block database").translated;
1721+
strLoadError = _("Error opening block database");
17221722
failed_verification = true;
17231723
break;
17241724
}
@@ -1733,8 +1733,8 @@ bool AppInitMain(NodeContext& node)
17331733
// first suggest a reindex
17341734
if (!fReset) {
17351735
bool fRet = uiInterface.ThreadSafeQuestion(
1736-
strLoadError + ".\n\n" + _("Do you want to rebuild the block database now?").translated,
1737-
strLoadError + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
1736+
strLoadError + Untranslated(".\n\n") + _("Do you want to rebuild the block database now?"),
1737+
strLoadError.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
17381738
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
17391739
if (fRet) {
17401740
fReindex = true;
@@ -1744,7 +1744,7 @@ bool AppInitMain(NodeContext& node)
17441744
return false;
17451745
}
17461746
} else {
1747-
return InitError(strLoadError);
1747+
return InitError(strLoadError.translated);
17481748
}
17491749
}
17501750
}

src/interfaces/node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ class Node
213213

214214
//! Register handler for message box messages.
215215
using MessageBoxFn =
216-
std::function<bool(const std::string& message, const std::string& caption, unsigned int style)>;
216+
std::function<bool(const bilingual_str& message, const std::string& caption, unsigned int style)>;
217217
virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
218218

219219
//! Register handler for question messages.
220-
using QuestionFn = std::function<bool(const std::string& message,
220+
using QuestionFn = std::function<bool(const bilingual_str& message,
221221
const std::string& non_interactive_message,
222222
const std::string& caption,
223223
unsigned int style)>;

src/net.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,26 +2068,25 @@ void CConnman::ThreadMessageHandler()
20682068

20692069

20702070

2071-
bool CConnman::BindListenPort(const CService& addrBind, std::string& strError, NetPermissionFlags permissions)
2071+
bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError, NetPermissionFlags permissions)
20722072
{
2073-
strError = "";
20742073
int nOne = 1;
20752074

20762075
// Create socket for listening for incoming connections
20772076
struct sockaddr_storage sockaddr;
20782077
socklen_t len = sizeof(sockaddr);
20792078
if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len))
20802079
{
2081-
strError = strprintf("Error: Bind address family for %s not supported", addrBind.ToString());
2082-
LogPrintf("%s\n", strError);
2080+
strError = strprintf(Untranslated("Error: Bind address family for %s not supported"), addrBind.ToString());
2081+
LogPrintf("%s\n", strError.original);
20832082
return false;
20842083
}
20852084

20862085
SOCKET hListenSocket = CreateSocket(addrBind);
20872086
if (hListenSocket == INVALID_SOCKET)
20882087
{
2089-
strError = strprintf("Error: Couldn't open socket for incoming connections (socket returned error %s)", NetworkErrorString(WSAGetLastError()));
2090-
LogPrintf("%s\n", strError);
2088+
strError = strprintf(Untranslated("Error: Couldn't open socket for incoming connections (socket returned error %s)"), NetworkErrorString(WSAGetLastError()));
2089+
LogPrintf("%s\n", strError.original);
20912090
return false;
20922091
}
20932092

@@ -2111,10 +2110,10 @@ bool CConnman::BindListenPort(const CService& addrBind, std::string& strError, N
21112110
{
21122111
int nErr = WSAGetLastError();
21132112
if (nErr == WSAEADDRINUSE)
2114-
strError = strprintf(_("Unable to bind to %s on this computer. %s is probably already running.").translated, addrBind.ToString(), PACKAGE_NAME);
2113+
strError = strprintf(_("Unable to bind to %s on this computer. %s is probably already running."), addrBind.ToString(), PACKAGE_NAME);
21152114
else
2116-
strError = strprintf(_("Unable to bind to %s on this computer (bind returned error %s)").translated, addrBind.ToString(), NetworkErrorString(nErr));
2117-
LogPrintf("%s\n", strError);
2115+
strError = strprintf(_("Unable to bind to %s on this computer (bind returned error %s)"), addrBind.ToString(), NetworkErrorString(nErr));
2116+
LogPrintf("%s\n", strError.original);
21182117
CloseSocket(hListenSocket);
21192118
return false;
21202119
}
@@ -2123,8 +2122,8 @@ bool CConnman::BindListenPort(const CService& addrBind, std::string& strError, N
21232122
// Listen for incoming connections
21242123
if (listen(hListenSocket, SOMAXCONN) == SOCKET_ERROR)
21252124
{
2126-
strError = strprintf(_("Error: Listening for incoming connections failed (listen returned error %s)").translated, NetworkErrorString(WSAGetLastError()));
2127-
LogPrintf("%s\n", strError);
2125+
strError = strprintf(_("Error: Listening for incoming connections failed (listen returned error %s)"), NetworkErrorString(WSAGetLastError()));
2126+
LogPrintf("%s\n", strError.original);
21282127
CloseSocket(hListenSocket);
21292128
return false;
21302129
}
@@ -2218,7 +2217,7 @@ NodeId CConnman::GetNewNodeId()
22182217
bool CConnman::Bind(const CService &addr, unsigned int flags, NetPermissionFlags permissions) {
22192218
if (!(flags & BF_EXPLICIT) && !IsReachable(addr))
22202219
return false;
2221-
std::string strError;
2220+
bilingual_str strError;
22222221
if (!BindListenPort(addr, strError, permissions)) {
22232222
if ((flags & BF_REPORT_ERROR) && clientInterface) {
22242223
clientInterface->ThreadSafeMessageBox(strError, "", CClientUIInterface::MSG_ERROR);
@@ -2265,7 +2264,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
22652264
if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) {
22662265
if (clientInterface) {
22672266
clientInterface->ThreadSafeMessageBox(
2268-
_("Failed to listen on any port. Use -listen=0 if you want this.").translated,
2267+
_("Failed to listen on any port. Use -listen=0 if you want this."),
22692268
"", CClientUIInterface::MSG_ERROR);
22702269
}
22712270
return false;
@@ -2331,7 +2330,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
23312330
if (connOptions.m_use_addrman_outgoing && !connOptions.m_specified_outgoing.empty()) {
23322331
if (clientInterface) {
23332332
clientInterface->ThreadSafeMessageBox(
2334-
_("Cannot provide specific connections and have addrman find outgoing connections at the same.").translated,
2333+
_("Cannot provide specific connections and have addrman find outgoing connections at the same."),
23352334
"", CClientUIInterface::MSG_ERROR);
23362335
}
23372336
return false;

src/net.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <random.h>
2222
#include <streams.h>
2323
#include <sync.h>
24-
#include <uint256.h>
2524
#include <threadinterrupt.h>
25+
#include <uint256.h>
2626

2727
#include <atomic>
2828
#include <deque>
@@ -39,6 +39,7 @@
3939
class CScheduler;
4040
class CNode;
4141
class BanMan;
42+
struct bilingual_str;
4243

4344
/** Default for -whitelistrelay. */
4445
static const bool DEFAULT_WHITELISTRELAY = true;
@@ -334,7 +335,7 @@ class CConnman
334335
NetPermissionFlags m_permissions;
335336
};
336337

337-
bool BindListenPort(const CService& bindAddr, std::string& strError, NetPermissionFlags permissions);
338+
bool BindListenPort(const CService& bindAddr, bilingual_str& strError, NetPermissionFlags permissions);
338339
bool Bind(const CService& addr, unsigned int flags, NetPermissionFlags permissions);
339340
bool InitBinds(const std::vector<CService>& binds, const std::vector<NetWhitebindPermissions>& whiteBinds);
340341
void ThreadOpenAddedConnections();

src/noui.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
#include <noui.h>
77

8+
#include <logging.h>
89
#include <ui_interface.h>
9-
#include <util/system.h>
10+
#include <util/translation.h>
1011

1112
#include <string>
1213

@@ -18,7 +19,7 @@ boost::signals2::connection noui_ThreadSafeMessageBoxConn;
1819
boost::signals2::connection noui_ThreadSafeQuestionConn;
1920
boost::signals2::connection noui_InitMessageConn;
2021

21-
bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style)
22+
bool noui_ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style)
2223
{
2324
bool fSecure = style & CClientUIInterface::SECURE;
2425
style &= ~CClientUIInterface::SECURE;
@@ -43,15 +44,15 @@ bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& ca
4344
}
4445

4546
if (!fSecure) {
46-
LogPrintf("%s%s\n", strCaption, message);
47+
LogPrintf("%s%s\n", strCaption, message.original);
4748
}
48-
tfm::format(std::cerr, "%s%s\n", strCaption, message);
49+
tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
4950
return false;
5051
}
5152

52-
bool noui_ThreadSafeQuestion(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
53+
bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
5354
{
54-
return noui_ThreadSafeMessageBox(message, caption, style);
55+
return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
5556
}
5657

5758
void noui_InitMessage(const std::string& message)
@@ -66,13 +67,13 @@ void noui_connect()
6667
noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
6768
}
6869

69-
bool noui_ThreadSafeMessageBoxRedirect(const std::string& message, const std::string& caption, unsigned int style)
70+
bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, const std::string& caption, unsigned int style)
7071
{
71-
LogPrintf("%s: %s\n", caption, message);
72+
LogPrintf("%s: %s\n", caption, message.original);
7273
return false;
7374
}
7475

75-
bool noui_ThreadSafeQuestionRedirect(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
76+
bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
7677
{
7778
LogPrintf("%s: %s\n", caption, message);
7879
return false;

src/noui.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
#include <string>
99

10+
struct bilingual_str;
11+
1012
/** Non-GUI handler, which logs and prints messages. */
11-
bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style);
13+
bool noui_ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style);
1214
/** Non-GUI handler, which logs and prints questions. */
13-
bool noui_ThreadSafeQuestion(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style);
15+
bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style);
1416
/** Non-GUI handler, which only logs a message. */
1517
void noui_InitMessage(const std::string& message);
1618

0 commit comments

Comments
 (0)