Skip to content

Commit 7e923d4

Browse files
committed
Make InitError bilingual
1 parent 917ca93 commit 7e923d4

File tree

9 files changed

+74
-73
lines changed

9 files changed

+74
-73
lines changed

src/bitcoind.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static bool AppInit(int argc, char* argv[])
5656
SetupServerArgs(node);
5757
std::string error;
5858
if (!gArgs.ParseParameters(argc, argv, error)) {
59-
return InitError(strprintf("Error parsing command line arguments: %s\n", error));
59+
return InitError(Untranslated(strprintf("Error parsing command line arguments: %s\n", error)));
6060
}
6161

6262
// Process help and version before taking care about datadir
@@ -80,22 +80,22 @@ static bool AppInit(int argc, char* argv[])
8080
try
8181
{
8282
if (!CheckDataDirOption()) {
83-
return InitError(strprintf("Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "")));
83+
return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""))));
8484
}
8585
if (!gArgs.ReadConfigFiles(error, true)) {
86-
return InitError(strprintf("Error reading configuration file: %s\n", error));
86+
return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error)));
8787
}
8888
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
8989
try {
9090
SelectParams(gArgs.GetChainName());
9191
} catch (const std::exception& e) {
92-
return InitError(strprintf("%s\n", e.what()));
92+
return InitError(Untranslated(strprintf("%s\n", e.what())));
9393
}
9494

9595
// Error out when loose non-argument tokens are encountered on command line
9696
for (int i = 1; i < argc; i++) {
9797
if (!IsSwitchChar(argv[i][0])) {
98-
return InitError(strprintf("Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i]));
98+
return InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i])));
9999
}
100100
}
101101

@@ -130,13 +130,13 @@ static bool AppInit(int argc, char* argv[])
130130

131131
// Daemonize
132132
if (daemon(1, 0)) { // don't chdir (1), do close FDs (0)
133-
return InitError(strprintf("daemon() failed: %s\n", strerror(errno)));
133+
return InitError(Untranslated(strprintf("daemon() failed: %s\n", strerror(errno))));
134134
}
135135
#if defined(MAC_OSX)
136136
#pragma GCC diagnostic pop
137137
#endif
138138
#else
139-
return InitError("-daemon is not supported on this operating system\n");
139+
return InitError(Untranslated("-daemon is not supported on this operating system\n"));
140140
#endif // HAVE_DECL_DAEMON
141141
}
142142
// Lock data directory after daemonization

src/init.cpp

Lines changed: 48 additions & 49 deletions
Large diffs are not rendered by default.

src/interfaces/chain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class ChainImpl : public Chain
345345
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
346346
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
347347
void initWarning(const std::string& message) override { InitWarning(message); }
348-
void initError(const std::string& message) override { InitError(message); }
348+
void initError(const bilingual_str& message) override { InitError(message); }
349349
void showProgress(const std::string& title, int progress, bool resume_possible) override
350350
{
351351
::uiInterface.ShowProgress(title, progress, resume_possible);

src/interfaces/chain.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CScheduler;
2121
class Coin;
2222
class uint256;
2323
enum class RBFTransactionState;
24+
struct bilingual_str;
2425
struct CBlockLocator;
2526
struct FeeCalculation;
2627
struct NodeContext;
@@ -227,7 +228,7 @@ class Chain
227228
virtual void initWarning(const std::string& message) = 0;
228229

229230
//! Send init error.
230-
virtual void initError(const std::string& message) = 0;
231+
virtual void initError(const bilingual_str& message) = 0;
231232

232233
//! Send progress indicator.
233234
virtual void showProgress(const std::string& title, int progress, bool resume_possible) = 0;

src/interfaces/node.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <txmempool.h>
2929
#include <ui_interface.h>
3030
#include <util/system.h>
31+
#include <util/translation.h>
3132
#include <validation.h>
3233
#include <warnings.h>
3334

@@ -54,7 +55,7 @@ namespace {
5455
class NodeImpl : public Node
5556
{
5657
public:
57-
void initError(const std::string& message) override { InitError(message); }
58+
void initError(const std::string& message) override { InitError(Untranslated(message)); }
5859
bool parseParameters(int argc, const char* const argv[], std::string& error) override
5960
{
6061
return gArgs.ParseParameters(argc, argv, error);

src/ui_interface.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ void CClientUIInterface::NotifyBlockTip(bool b, const CBlockIndex* i) { return g
5353
void CClientUIInterface::NotifyHeaderTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyHeaderTip(b, i); }
5454
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
5555

56-
57-
bool InitError(const std::string& str)
56+
bool InitError(const bilingual_str& str)
5857
{
59-
uiInterface.ThreadSafeMessageBox(Untranslated(str), "", CClientUIInterface::MSG_ERROR);
58+
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
6059
return false;
6160
}
6261

src/ui_interface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ class CClientUIInterface
120120
};
121121

122122
/** Show warning message **/
123+
// TODO: InitWarning() should take a bilingual_str parameter.
123124
void InitWarning(const std::string& str);
124125

125126
/** Show error message **/
126-
bool InitError(const std::string& str);
127+
bool InitError(const bilingual_str& str);
127128

128129
extern CClientUIInterface uiInterface;
129130

src/wallet/init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool WalletInit::ParameterInteraction() const
9191

9292
if (gArgs.GetBoolArg("-salvagewallet", false)) {
9393
if (is_multiwallet) {
94-
return InitError(strprintf("%s is only allowed with a single wallet file", "-salvagewallet"));
94+
return InitError(strprintf(Untranslated("%s is only allowed with a single wallet file"), "-salvagewallet"));
9595
}
9696
// Rewrite just private keys: rescan to find transactions
9797
if (gArgs.SoftSetBoolArg("-rescan", true)) {
@@ -108,15 +108,15 @@ bool WalletInit::ParameterInteraction() const
108108
// -zapwallettxes implies a rescan
109109
if (zapwallettxes) {
110110
if (is_multiwallet) {
111-
return InitError(strprintf("%s is only allowed with a single wallet file", "-zapwallettxes"));
111+
return InitError(strprintf(Untranslated("%s is only allowed with a single wallet file"), "-zapwallettxes"));
112112
}
113113
if (gArgs.SoftSetBoolArg("-rescan", true)) {
114114
LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> setting -rescan=1\n", __func__);
115115
}
116116
}
117117

118118
if (gArgs.GetBoolArg("-sysperms", false))
119-
return InitError("-sysperms is not allowed in combination with enabled wallet functionality");
119+
return InitError(Untranslated("-sysperms is not allowed in combination with enabled wallet functionality"));
120120

121121
return true;
122122
}

src/wallet/load.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
2020
// The canonical path cleans the path, preventing >1 Berkeley environment instances for the same directory
2121
fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error);
2222
if (error || !fs::exists(wallet_dir)) {
23-
chain.initError(strprintf(_("Specified -walletdir \"%s\" does not exist").translated, wallet_dir.string()));
23+
chain.initError(strprintf(_("Specified -walletdir \"%s\" does not exist"), wallet_dir.string()));
2424
return false;
2525
} else if (!fs::is_directory(wallet_dir)) {
26-
chain.initError(strprintf(_("Specified -walletdir \"%s\" is not a directory").translated, wallet_dir.string()));
26+
chain.initError(strprintf(_("Specified -walletdir \"%s\" is not a directory"), wallet_dir.string()));
2727
return false;
2828
// The canonical path transforms relative paths into absolute ones, so we check the non-canonical version
2929
} else if (!wallet_dir.is_absolute()) {
30-
chain.initError(strprintf(_("Specified -walletdir \"%s\" is a relative path").translated, wallet_dir.string()));
30+
chain.initError(strprintf(_("Specified -walletdir \"%s\" is a relative path"), wallet_dir.string()));
3131
return false;
3232
}
3333
gArgs.ForceSetArg("-walletdir", canonical_wallet_dir.string());
@@ -49,7 +49,7 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
4949
WalletLocation location(wallet_file);
5050

5151
if (!wallet_paths.insert(location.GetPath()).second) {
52-
chain.initError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified.").translated, wallet_file));
52+
chain.initError(strprintf(_("Error loading wallet %s. Duplicate -wallet filename specified."), wallet_file));
5353
return false;
5454
}
5555

@@ -58,7 +58,7 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
5858
bool verify_success = CWallet::Verify(chain, location, salvage_wallet, error_string, warnings);
5959
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", OpTranslated));
6060
if (!verify_success) {
61-
chain.initError(error_string.translated);
61+
chain.initError(error_string);
6262
return false;
6363
}
6464
}
@@ -75,14 +75,14 @@ bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& walle
7575
std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, WalletLocation(walletFile), error, warnings);
7676
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", OpTranslated));
7777
if (!pwallet) {
78-
chain.initError(error.translated);
78+
chain.initError(error);
7979
return false;
8080
}
8181
AddWallet(pwallet);
8282
}
8383
return true;
8484
} catch (const std::runtime_error& e) {
85-
chain.initError(e.what());
85+
chain.initError(Untranslated(e.what()));
8686
return false;
8787
}
8888
}

0 commit comments

Comments
 (0)