Skip to content

Commit 51825ae

Browse files
committed
Merge #18922: gui: Do not translate InitWarning messages in debug.log
78be8d9 util: Drop OpOriginal() and OpTranslated() (Hennadii Stepanov) da16f95 gui: Do not translate InitWarning messages in debug.log (Hennadii Stepanov) 4c9b9a4 util: Enhance Join() (Hennadii Stepanov) fe05dd0 util: Enhance bilingual_str (Hennadii Stepanov) Pull request description: This PR forces the `bitcoin-qt` to write `InitWarning()` messages to the `debug.log` file in untranslated form, i.e., in English. On master (376294c): ``` $ ./src/qt/bitcoin-qt -lang=nl -debug=vladidation -printtoconsole | grep 'vladi' Warning: Niet-ondersteunde logcategorie -debug=vladidation. 2020-05-09T12:39:59Z Warning: Niet-ondersteunde logcategorie -debug=vladidation. 2020-05-09T12:40:02Z Command-line arg: debug="vladidation" ``` With this PR: ``` $ ./src/qt/bitcoin-qt -lang=nl -debug=vladidation -printtoconsole | grep 'vladi' Warning: Unsupported logging category -debug=vladidation. 2020-05-09T12:42:04Z Warning: Unsupported logging category -debug=vladidation. 2020-05-09T12:42:35Z Command-line arg: debug="vladidation" ``` ![Screenshot from 2020-05-09 15-42-31](https://user-images.githubusercontent.com/32963518/81474073-c7a50e00-920b-11ea-8775-c41122dacafe.png) Related to #16218. ACKs for top commit: laanwj: ACK 78be8d9 jonasschnelli: utACK 78be8d9 MarcoFalke: ACK 78be8d9 📢 Tree-SHA512: 48e9ecd23c4dd8ec262e3eb94f8e30944bcc9c6c163245fb837b2e0c484d4d0b4f47f7abc638c14edc27d635d340ba3ee4ba4506b062399e9cf59a1564c98755
2 parents fc895d7 + 78be8d9 commit 51825ae

File tree

10 files changed

+38
-29
lines changed

10 files changed

+38
-29
lines changed

src/init.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ bool AppInitParameterInteraction()
972972

973973
// Warn if unrecognized section name are present in the config file.
974974
for (const auto& section : gArgs.GetUnrecognizedSections()) {
975-
InitWarning(strprintf("%s:%i " + _("Section [%s] is not recognized.").translated, section.m_file, section.m_line, section.m_name));
975+
InitWarning(strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized."), section.m_file, section.m_line, section.m_name));
976976
}
977977

978978
if (!fs::is_directory(GetBlocksDir())) {
@@ -1035,7 +1035,7 @@ bool AppInitParameterInteraction()
10351035
nMaxConnections = std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS, nMaxConnections);
10361036

10371037
if (nMaxConnections < nUserMaxConnections)
1038-
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations.").translated, nUserMaxConnections, nMaxConnections));
1038+
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections));
10391039

10401040
// ********************************************************* Step 3: parameter-to-internal-flags
10411041
if (gArgs.IsArgSet("-debug")) {
@@ -1046,7 +1046,7 @@ bool AppInitParameterInteraction()
10461046
[](std::string cat){return cat == "0" || cat == "none";})) {
10471047
for (const auto& cat : categories) {
10481048
if (!LogInstance().EnableCategory(cat)) {
1049-
InitWarning(strprintf(_("Unsupported logging category %s=%s.").translated, "-debug", cat));
1049+
InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debug", cat));
10501050
}
10511051
}
10521052
}
@@ -1055,7 +1055,7 @@ bool AppInitParameterInteraction()
10551055
// Now remove the logging categories which were explicitly excluded
10561056
for (const std::string& cat : gArgs.GetArgs("-debugexclude")) {
10571057
if (!LogInstance().DisableCategory(cat)) {
1058-
InitWarning(strprintf(_("Unsupported logging category %s=%s.").translated, "-debugexclude", cat));
1058+
InitWarning(strprintf(_("Unsupported logging category %s=%s."), "-debugexclude", cat));
10591059
}
10601060
}
10611061

@@ -1268,7 +1268,7 @@ bool AppInitMain(NodeContext& node)
12681268
LogPrintf("Config file: %s\n", config_file_path.string());
12691269
} else if (gArgs.IsArgSet("-conf")) {
12701270
// Warn if no conf file exists at path provided by user
1271-
InitWarning(strprintf(_("The specified config file %s does not exist\n").translated, config_file_path.string()));
1271+
InitWarning(strprintf(_("The specified config file %s does not exist\n"), config_file_path.string()));
12721272
} else {
12731273
// Not categorizing as "Warning" because it's the default behavior
12741274
LogPrintf("Config file: %s (not found, skipping)\n", config_file_path.string());

src/interfaces/chain.cpp

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

src/interfaces/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class Chain
225225
virtual void initMessage(const std::string& message) = 0;
226226

227227
//! Send init warning.
228-
virtual void initWarning(const std::string& message) = 0;
228+
virtual void initWarning(const bilingual_str& message) = 0;
229229

230230
//! Send init error.
231231
virtual void initError(const bilingual_str& message) = 0;

src/qt/walletcontroller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void CreateWalletActivity::finish()
248248
if (!m_error_message.original.empty()) {
249249
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), QString::fromStdString(m_error_message.translated));
250250
} else if (!m_warning_message.empty()) {
251-
QMessageBox::warning(m_parent_widget, tr("Create wallet warning"), QString::fromStdString(Join(m_warning_message, "\n", OpTranslated)));
251+
QMessageBox::warning(m_parent_widget, tr("Create wallet warning"), QString::fromStdString(Join(m_warning_message, Untranslated("\n")).translated));
252252
}
253253

254254
if (m_wallet_model) Q_EMIT created(m_wallet_model);
@@ -289,7 +289,7 @@ void OpenWalletActivity::finish()
289289
if (!m_error_message.original.empty()) {
290290
QMessageBox::critical(m_parent_widget, tr("Open wallet failed"), QString::fromStdString(m_error_message.translated));
291291
} else if (!m_warning_message.empty()) {
292-
QMessageBox::warning(m_parent_widget, tr("Open wallet warning"), QString::fromStdString(Join(m_warning_message, "\n", OpTranslated)));
292+
QMessageBox::warning(m_parent_widget, tr("Open wallet warning"), QString::fromStdString(Join(m_warning_message, Untranslated("\n")).translated));
293293
}
294294

295295
if (m_wallet_model) Q_EMIT opened(m_wallet_model);

src/ui_interface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ bool InitError(const bilingual_str& str)
5959
return false;
6060
}
6161

62-
void InitWarning(const std::string& str)
62+
void InitWarning(const bilingual_str& str)
6363
{
64-
uiInterface.ThreadSafeMessageBox(Untranslated(str), "", CClientUIInterface::MSG_WARNING);
64+
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
6565
}

src/ui_interface.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ class CClientUIInterface
120120
};
121121

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

126125
/** Show error message **/
127126
bool InitError(const bilingual_str& str);

src/util/string.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,28 @@ NODISCARD inline std::string TrimString(const std::string& str, const std::strin
3030
* @param separator The separator
3131
* @param unary_op Apply this operator to each item in the list
3232
*/
33-
template <typename T, typename UnaryOp>
34-
std::string Join(const std::vector<T>& list, const std::string& separator, UnaryOp unary_op)
33+
template <typename T, typename BaseType, typename UnaryOp>
34+
auto Join(const std::vector<T>& list, const BaseType& separator, UnaryOp unary_op)
35+
-> decltype(unary_op(list.at(0)))
3536
{
36-
std::string ret;
37+
decltype(unary_op(list.at(0))) ret;
3738
for (size_t i = 0; i < list.size(); ++i) {
3839
if (i > 0) ret += separator;
3940
ret += unary_op(list.at(i));
4041
}
4142
return ret;
4243
}
4344

45+
template <typename T>
46+
T Join(const std::vector<T>& list, const T& separator)
47+
{
48+
return Join(list, separator, [](const T& i) { return i; });
49+
}
50+
51+
// Explicit overload needed for c_str arguments, which would otherwise cause a substitution failure in the template above.
4452
inline std::string Join(const std::vector<std::string>& list, const std::string& separator)
4553
{
46-
return Join(list, separator, [](const std::string& i) { return i; });
54+
return Join<std::string>(list, separator);
4755
}
4856

4957
/**

src/util/translation.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@
1616
struct bilingual_str {
1717
std::string original;
1818
std::string translated;
19+
20+
bilingual_str& operator+=(const bilingual_str& rhs)
21+
{
22+
original += rhs.original;
23+
translated += rhs.translated;
24+
return *this;
25+
}
1926
};
2027

21-
inline bilingual_str operator+(const bilingual_str& lhs, const bilingual_str& rhs)
28+
inline bilingual_str operator+(bilingual_str lhs, const bilingual_str& rhs)
2229
{
23-
return bilingual_str{
24-
lhs.original + rhs.original,
25-
lhs.translated + rhs.translated};
30+
lhs += rhs;
31+
return lhs;
2632
}
2733

2834
/** Mark a bilingual_str as untranslated */
2935
inline bilingual_str Untranslated(std::string original) { return {original, original}; }
30-
/** Unary operator to return the original */
31-
inline std::string OpOriginal(const bilingual_str& b) { return b.original; }
32-
/** Unary operator to return the translation */
33-
inline std::string OpTranslated(const bilingual_str& b) { return b.translated; }
3436

3537
namespace tinyformat {
3638
template <typename... Args>

src/wallet/load.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
5656
bilingual_str error_string;
5757
std::vector<bilingual_str> warnings;
5858
bool verify_success = CWallet::Verify(chain, location, salvage_wallet, error_string, warnings);
59-
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", OpTranslated));
59+
if (!warnings.empty()) chain.initWarning(Join(warnings, Untranslated("\n")));
6060
if (!verify_success) {
6161
chain.initError(error_string);
6262
return false;
@@ -73,7 +73,7 @@ bool LoadWallets(interfaces::Chain& chain, const std::vector<std::string>& walle
7373
bilingual_str error;
7474
std::vector<bilingual_str> warnings;
7575
std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile(chain, WalletLocation(walletFile), error, warnings);
76-
if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", OpTranslated));
76+
if (!warnings.empty()) chain.initWarning(Join(warnings, Untranslated("\n")));
7777
if (!pwallet) {
7878
chain.initError(error);
7979
return false;

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,7 +2603,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
26032603

26042604
UniValue obj(UniValue::VOBJ);
26052605
obj.pushKV("name", wallet->GetName());
2606-
obj.pushKV("warning", Join(warnings, "\n", OpOriginal));
2606+
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
26072607

26082608
return obj;
26092609
}
@@ -2743,7 +2743,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
27432743

27442744
UniValue obj(UniValue::VOBJ);
27452745
obj.pushKV("name", wallet->GetName());
2746-
obj.pushKV("warning", Join(warnings, "\n", OpOriginal));
2746+
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
27472747

27482748
return obj;
27492749
}

0 commit comments

Comments
 (0)