diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index 43ee43c577..eb0926d0d0 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -367,11 +367,9 @@ void PopupMultiChoice::HandleClick(UI::EventParams &e) { restoreFocus_ = HasFocus(); - auto category = GetI18NCategory(category_); - std::vector 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")); diff --git a/Common/UI/PopupScreens.h b/Common/UI/PopupScreens.h index abd8ba39f1..35bafbb316 100644 --- a/Common/UI/PopupScreens.h +++ b/Common/UI/PopupScreens.h @@ -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 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 hidden_; + std::set untranslated_; std::map icons_; std::function preOpenCallback_; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index a771f7eaa1..e5257a4ed3 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -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);