UI: Let PopupMultiChoice mark choices as untranslated

Choices that are just numbers have no translation, so every lookup got
logged as a missing translation - the Graphics settings screen spammed
the log once per frame as long as Frame Skipping was on.

Fixes #21455

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01JvJR8oJNSCimCM9KXVLjfq
This commit is contained in:
Henrik RydgårdandClaude Opus 5 committed 2026-09-04 13:08:21 -06:00
1 parent ceb3fb2a4a
commit f7548ea7e2
3 files changed
+25 -5

No files matched your search

+8 -4
View File
@@ -367,11 +367,9 @@ void PopupMultiChoice::HandleClick(UI::EventParams &e) {
restoreFocus_ = HasFocus();
auto category = GetI18NCategory(category_);
std::vector<std::string> choices;
for (int i = 0; i < numChoices_; i++) {
choices.push_back(category ? std::string(category->T(choices_[i])) : std::string(choices_[i]));
choices.push_back(std::string(TranslateChoice(i)));
}
ListPopupScreen *popupScreen = new ListPopupScreen(ChopTitle(text_), choices, *value_ - minVal_, [this](int num) {ChoiceCallback(num);});
@@ -387,6 +385,12 @@ void PopupMultiChoice::Update() {
UpdateText();
}
std::string_view PopupMultiChoice::TranslateChoice(int index) const {
// Choices like plain numbers have no translation, and looking them up would just spam the log.
const I18NCat category = untranslated_.find(index) != untranslated_.end() ? I18NCat::NONE : category_;
return T(category, choices_[index]);
}
void PopupMultiChoice::UpdateText() {
if (!choices_)
return;
@@ -395,7 +399,7 @@ void PopupMultiChoice::UpdateText() {
valueText_ = "(invalid choice)"; // Shouldn't happen. Should be no need to translate this.
} else {
if (choices_[index]) {
std::string text(T(category_, choices_[index]));
std::string text(TranslateChoice(index));
if (default_ == index) {
auto di = GetI18NCategory(I18NCat::DIALOG);
text = ApplySafeSubstitutions("%1 (%2)", text, di->T("Default"));
+14
View File
@@ -320,6 +320,17 @@ public:
return hidden_.find(c) != hidden_.end();
}
// Marks a choice (index into the choices array) as not needing translation, like a plain number.
// Without this, every lookup of such a choice gets logged as a missing translation.
void SetChoiceUntranslated(int c) {
untranslated_.insert(c);
}
void SetChoicesUntranslated(int first, int last) {
for (int i = first; i <= last; i++) {
untranslated_.insert(i);
}
}
void SetPreOpenCallback(std::function<void(PopupMultiChoice *)> callback) {
preOpenCallback_ = callback;
}
@@ -354,6 +365,8 @@ protected:
private:
void HandleClick(UI::EventParams &e);
std::string_view TranslateChoice(int index) const;
void ChoiceCallback(int num);
virtual bool PostChoiceCallback(int num) { return true; }
@@ -362,6 +375,7 @@ private:
std::string valueText_;
bool restoreFocus_ = false;
std::set<int> hidden_;
std::set<int> untranslated_;
std::map<int, ImageID> icons_;
std::function<void(PopupMultiChoice *)> preOpenCallback_;
+3 -1
View File
@@ -439,6 +439,7 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings)
graphicsSettings->Add(new ItemHeader(gr->T("Frame Rate Control")));
static const char *frameSkip[] = {"Off", "1", "2", "3", "4", "5", "6", "7", "8"};
PopupMultiChoice *frameSkipping = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iFrameSkip, gr->T("Frame Skipping"), frameSkip, 0, ARRAY_SIZE(frameSkip), I18NCat::GRAPHICS, screenManager()));
frameSkipping->SetChoicesUntranslated(1, (int)ARRAY_SIZE(frameSkip) - 1);
frameSkipping->SetEnabledFunc([] {
return !g_Config.bAutoFrameSkip;
});
@@ -512,7 +513,7 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings)
graphicsSettings->Add(new SettingHint(gr->T("RenderDuplicateFrames Tip", "Can make framerate smoother in games that run at lower framerates"), frameDuplication));
if (draw->GetDeviceCaps().setMaxFrameLatencySupported) {
static const char *bufferOptions[] = { "No buffer", "Up to 1", "Up to 2" };
static const char *bufferOptions[] = { "No buffer", "Up to 1" };
PopupMultiChoice *inflightChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iInflightFrames, gr->T("Buffer graphics commands"), bufferOptions, 1, ARRAY_SIZE(bufferOptions), I18NCat::GRAPHICS, screenManager()));
inflightChoice->OnChoice.Handle(this, &GameSettingsScreen::OnInflightFramesChoice);
graphicsSettings->Add(new SettingHint(gr->T("Faster, input lag"), inflightChoice)); // TODO: This hint could use improvement.
@@ -1088,6 +1089,7 @@ void GameSettingsScreen::CreateNetworkingSettings(UI::ViewGroup *networkingSetti
});
static const char *wlanChannels[] = {"Auto", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"};
auto wlanChannelChoice = networkingSettings->Add(new PopupMultiChoice(&g_Config.iWlanAdhocChannel, n->T("WLAN Channel"), wlanChannels, 0, ARRAY_SIZE(wlanChannels), I18NCat::NETWORKING, screenManager()));
wlanChannelChoice->SetChoicesUntranslated(1, (int)ARRAY_SIZE(wlanChannels) - 1);
for (int i = 0; i < 4; i++) {
wlanChannelChoice->HideChoice(i + 2);
wlanChannelChoice->HideChoice(i + 7);