fix(i18n): reject format-incompatible translations

Many strings are used directly as printf/ImGui format strings, and translations
are loaded from user/installer-modifiable JSON with no validation. A translated
value that drops or changes a conversion specifier would be passed to printf with
mismatched varargs (undefined behavior) on a wallet screen.

overlayTranslations() now compares each translated value's argument signature
against the English source and keeps English on mismatch. Also adds the
send_status_unconfirmed string used by the deferred-send-result path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-07 14:18:25 -05:00
parent 8f22db5eea
commit e00772db6e
2 changed files with 64 additions and 12 deletions

View File

@@ -7,6 +7,7 @@
#include <string>
#include <unordered_map>
#include <vector>
#include <nlohmann/json_fwd.hpp>
namespace dragonx {
namespace util {
@@ -58,7 +59,12 @@ public:
private:
I18n();
void loadBuiltinEnglish();
// Overlay translated strings onto the English base, but reject any value whose printf
// format-specifier signature differs from the English source (keep English instead).
// Many strings are used directly as printf/ImGui format strings, so a mismatched
// translation (dropped/changed specifier) is undefined behavior — this prevents it.
void overlayTranslations(const nlohmann::json& translations);
std::string current_locale_ = "en";
std::unordered_map<std::string, std::string> strings_;
std::vector<std::pair<std::string, std::string>> available_languages_;