Skip to content

Commit

Permalink
refactor: Use + instead of strformat to concatenate translated & untr…
Browse files Browse the repository at this point in the history
…anslated strings

This change manually removes two strprintf(Untranslated...) calls. All
remaining calls are removed in the next scripted-diff commit.

Removing these calls makes code more consistent and makes it easier to
implement compile-time checking enforcing that format strings contain valid
specifiers, by avoiding the need for the Untranslated() function to be involved
in formatting.

Additionally, using + and += instead of strprintf here makes code a little
shorter, and more type-safe because + unlike strprintf only works on strings of
the same type, making it less likely english strings and bilingual strings will
be unintentionally combined.
  • Loading branch information
ryanofsky committed Dec 4, 2024
1 parent 831d2bf commit 006e4d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/node/interface_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool InitError(const bilingual_str& str, const std::vector<std::string>& details
// functions which provide error details are ones that run during early init
// before the GUI uiInterface is registered, so there's no point passing
// main messages and details separately to uiInterface yet.
return InitError(details.empty() ? str : strprintf(Untranslated("%s:\n%s"), str, MakeUnorderedList(details)));
return InitError(details.empty() ? str : str + Untranslated(strprintf(":\n%s", MakeUnorderedList(details))));
}

void InitWarning(const bilingual_str& str)
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6142,7 +6142,7 @@ SnapshotCompletionResult ChainstateManager::MaybeCompleteSnapshotValidation()

auto rename_result = m_snapshot_chainstate->InvalidateCoinsDBOnDisk();
if (!rename_result) {
user_error = strprintf(Untranslated("%s\n%s"), user_error, util::ErrorString(rename_result));
user_error += Untranslated("\n") + util::ErrorString(rename_result);
}

GetNotifications().fatalError(user_error);
Expand Down

0 comments on commit 006e4d1

Please sign in to comment.