From 557748970adf0b220884fbb7d0be48324ea5d124 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 14 Jul 2024 16:48:31 +0200 Subject: [PATCH] Added localization support to parts of the application --- es-app/src/guis/GuiScraperMenu.cpp | 4 +- es-app/src/guis/GuiScraperMulti.cpp | 68 ++++++++++++------------ es-app/src/guis/GuiScraperSearch.cpp | 47 ++++++++-------- es-app/src/guis/GuiScraperSingle.cpp | 26 ++++----- es-core/src/components/BusyComponent.cpp | 3 +- 5 files changed, 77 insertions(+), 71 deletions(-) diff --git a/es-app/src/guis/GuiScraperMenu.cpp b/es-app/src/guis/GuiScraperMenu.cpp index 2b81f2508..f4ad8372e 100644 --- a/es-app/src/guis/GuiScraperMenu.cpp +++ b/es-app/src/guis/GuiScraperMenu.cpp @@ -768,8 +768,8 @@ void GuiScraperMenu::openOfflineGenerator(GuiSettings* settings) _("OK"), nullptr, "", nullptr, "", nullptr, nullptr, false, true, (mRenderer->getIsVerticalOrientation() ? - 0.78f : - 0.48f * (1.778f / mRenderer->getScreenAspectRatio())))); + 0.80f : + 0.50f * (1.778f / mRenderer->getScreenAspectRatio())))); return; } diff --git a/es-app/src/guis/GuiScraperMulti.cpp b/es-app/src/guis/GuiScraperMulti.cpp index 0775ec090..167312f16 100644 --- a/es-app/src/guis/GuiScraperMulti.cpp +++ b/es-app/src/guis/GuiScraperMulti.cpp @@ -22,6 +22,7 @@ #include "components/TextComponent.h" #include "guis/GuiMsgBox.h" #include "guis/GuiScraperSearch.h" +#include "utils/LocalizationUtil.h" GuiScraperMulti::GuiScraperMulti( const std::pair, std::map>& searches, @@ -48,11 +49,11 @@ GuiScraperMulti::GuiScraperMulti( mQueueCountPerSystem[(*it).first] = std::make_pair(0, (*it).second); // Set up grid. - mTitle = std::make_shared("SCRAPING IN PROGRESS", Font::get(FONT_SIZE_LARGE), + mTitle = std::make_shared(_("SCRAPING IN PROGRESS"), Font::get(FONT_SIZE_LARGE), mMenuColorTitle, ALIGN_CENTER); mGrid.setEntry(mTitle, glm::ivec2 {0, 0}, false, true, glm::ivec2 {2, 2}); - mSystem = std::make_shared("SYSTEM", Font::get(FONT_SIZE_MEDIUM), + mSystem = std::make_shared(_("SYSTEM"), Font::get(FONT_SIZE_MEDIUM), mMenuColorPrimary, ALIGN_CENTER); mGrid.setEntry(mSystem, glm::ivec2 {0, 2}, false, true, glm::ivec2 {2, 1}); @@ -105,38 +106,39 @@ GuiScraperMulti::GuiScraperMulti( std::vector> buttons; if (mApproveResults) { - buttons.push_back(std::make_shared("REFINE SEARCH", "refine search", [&] { - // Check whether we should allow a refine of the game name. - if (!mSearchComp->getAcceptedResult()) { - bool allowRefine = false; + buttons.push_back( + std::make_shared(_("REFINE SEARCH"), _("refine search"), [&] { + // Check whether we should allow a refine of the game name. + if (!mSearchComp->getAcceptedResult()) { + bool allowRefine = false; - // Previously refined. - if (mSearchComp->getRefinedSearch()) - allowRefine = true; - // Interactive mode and "Auto-accept single game matches" not enabled. - else if (mSearchComp->getSearchType() != GuiScraperSearch::SEMIAUTOMATIC_MODE) - allowRefine = true; - // Interactive mode with "Auto-accept single game matches" enabled and more - // than one result. - else if (mSearchComp->getSearchType() == GuiScraperSearch::SEMIAUTOMATIC_MODE && - mSearchComp->getScraperResultsSize() > 1) - allowRefine = true; - // Dito but there were no games found, or the search has not been completed. - else if (mSearchComp->getSearchType() == GuiScraperSearch::SEMIAUTOMATIC_MODE && - !mSearchComp->getFoundGame()) - allowRefine = true; + // Previously refined. + if (mSearchComp->getRefinedSearch()) + allowRefine = true; + // Interactive mode and "Auto-accept single game matches" not enabled. + else if (mSearchComp->getSearchType() != GuiScraperSearch::SEMIAUTOMATIC_MODE) + allowRefine = true; + // Interactive mode with "Auto-accept single game matches" enabled and more + // than one result. + else if (mSearchComp->getSearchType() == GuiScraperSearch::SEMIAUTOMATIC_MODE && + mSearchComp->getScraperResultsSize() > 1) + allowRefine = true; + // Dito but there were no games found, or the search has not been completed. + else if (mSearchComp->getSearchType() == GuiScraperSearch::SEMIAUTOMATIC_MODE && + !mSearchComp->getFoundGame()) + allowRefine = true; - if (allowRefine) { - // Copy any search refine that may have been previously entered by opening - // the input screen using the "Y" button shortcut. - mSearchQueue.front().nameOverride = mSearchComp->getNameOverride(); - mSearchComp->openInputScreen(mSearchQueue.front()); - mGrid.resetCursor(); + if (allowRefine) { + // Copy any search refine that may have been previously entered by opening + // the input screen using the "Y" button shortcut. + mSearchQueue.front().nameOverride = mSearchComp->getNameOverride(); + mSearchComp->openInputScreen(mSearchQueue.front()); + mGrid.resetCursor(); + } } - } - })); + })); - buttons.push_back(std::make_shared("SKIP", "skip game", [&] { + buttons.push_back(std::make_shared(_("SKIP"), _("skip game"), [&] { // Skip game, unless the result has already been accepted. if (!mSearchComp->getAcceptedResult()) { skip(); @@ -145,7 +147,7 @@ GuiScraperMulti::GuiScraperMulti( })); } - buttons.push_back(std::make_shared("STOP", "stop", + buttons.push_back(std::make_shared(_("STOP"), _("stop"), std::bind(&GuiScraperMulti::finish, this))); mButtonGrid = MenuComponent::makeButtonGrid(buttons); @@ -308,7 +310,7 @@ void GuiScraperMulti::finish() { std::stringstream ss; if (mTotalSuccessful == 0) { - ss << "NO GAMES WERE SCRAPED"; + ss << _("NO GAMES WERE SCRAPED"); } else { ss << mTotalSuccessful << " GAME" << ((mTotalSuccessful > 1) ? "S" : "") @@ -321,7 +323,7 @@ void GuiScraperMulti::finish() // Pressing either OK or using the back button should delete us. mWindow->pushGui(new GuiMsgBox( - getHelpStyle(), ss.str(), "OK", + getHelpStyle(), ss.str(), _("OK"), [&] { mIsProcessing = false; delete this; diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 8cb42bdb2..b007c9d6f 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -32,6 +32,7 @@ #include "guis/GuiTextEditKeyboardPopup.h" #include "guis/GuiTextEditPopup.h" #include "resources/Font.h" +#include "utils/LocalizationUtil.h" #include "utils/StringUtil.h" GuiScraperSearch::GuiScraperSearch(SearchType type, unsigned int scrapeCount, int rowCount) @@ -103,18 +104,18 @@ GuiScraperSearch::GuiScraperSearch(SearchType type, unsigned int scrapeCount, in if (mScrapeRatings) mMD_Pairs.push_back(MetaDataPair( - std::make_shared("RATING:", font, mdLblColor), mMD_Rating, false)); + std::make_shared(_("RATING:"), font, mdLblColor), mMD_Rating, false)); - mMD_Pairs.push_back(MetaDataPair(std::make_shared("RELEASED:", font, mdLblColor), - mMD_ReleaseDate)); mMD_Pairs.push_back(MetaDataPair( - std::make_shared("DEVELOPER:", font, mdLblColor), mMD_Developer)); + std::make_shared(_("RELEASED:"), font, mdLblColor), mMD_ReleaseDate)); mMD_Pairs.push_back(MetaDataPair( - std::make_shared("PUBLISHER:", font, mdLblColor), mMD_Publisher)); + std::make_shared(_("DEVELOPER:"), font, mdLblColor), mMD_Developer)); + mMD_Pairs.push_back(MetaDataPair( + std::make_shared(_("PUBLISHER:"), font, mdLblColor), mMD_Publisher)); mMD_Pairs.push_back( - MetaDataPair(std::make_shared("GENRE:", font, mdLblColor), mMD_Genre)); - mMD_Pairs.push_back( - MetaDataPair(std::make_shared("PLAYERS:", font, mdLblColor), mMD_Players)); + MetaDataPair(std::make_shared(_("GENRE:"), font, mdLblColor), mMD_Genre)); + mMD_Pairs.push_back(MetaDataPair( + std::make_shared(_("PLAYERS:"), font, mdLblColor), mMD_Players)); // If no rating is being scraped, add a filler to make sure that the fonts keep the same // size so the GUI looks consistent. @@ -428,7 +429,7 @@ void GuiScraperSearch::onSearchDone(std::vector& results) mFoundGame = false; ComponentListRow row; - row.addElement(std::make_shared("NO GAMES FOUND", font, color), true); + row.addElement(std::make_shared(_("NO GAMES FOUND"), font, color), true); if (mSkipCallback) row.makeAcceptInputHandler(mSkipCallback); @@ -578,16 +579,16 @@ void GuiScraperSearch::onSearchError(const std::string& error, if (mScrapeCount > 1) { LOG(LogError) << "GuiScraperSearch: " << Utils::String::replace(error, "\n", ""); - mWindow->pushGui(new GuiMsgBox(getHelpStyle(), Utils::String::toUpper(error), "RETRY", + mWindow->pushGui(new GuiMsgBox(getHelpStyle(), Utils::String::toUpper(error), _("RETRY"), std::bind(&GuiScraperSearch::search, this, mLastSearch), - "SKIP", mSkipCallback, "CANCEL", mCancelCallback, nullptr, - true)); + _("SKIP"), mSkipCallback, _("CANCEL"), mCancelCallback, + nullptr, true)); } else { LOG(LogError) << "GuiScraperSearch: " << Utils::String::replace(error, "\n", ""); - mWindow->pushGui(new GuiMsgBox(getHelpStyle(), Utils::String::toUpper(error), "RETRY", + mWindow->pushGui(new GuiMsgBox(getHelpStyle(), Utils::String::toUpper(error), _("RETRY"), std::bind(&GuiScraperSearch::search, this, mLastSearch), - "CANCEL", mCancelCallback, "", nullptr, nullptr, true)); + _("CANCEL"), mCancelCallback, "", nullptr, nullptr, true)); } } @@ -1028,14 +1029,14 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams& params) searchString = Utils::String::replace(searchString, "_", " "); if (Settings::getInstance()->getBool("VirtualKeyboard")) { - mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), 0.0f, "REFINE SEARCH", - searchString, searchForFunc, false, "SEARCH", - "SEARCH USING REFINED NAME?")); + mWindow->pushGui(new GuiTextEditKeyboardPopup( + getHelpStyle(), 0.0f, _("REFINE SEARCH"), searchString, searchForFunc, false, + _("SEARCH"), _("SEARCH USING REFINED NAME?"))); } else { - mWindow->pushGui(new GuiTextEditPopup(getHelpStyle(), "REFINE SEARCH", searchString, - searchForFunc, false, "SEARCH", - "SEARCH USING REFINED NAME?")); + mWindow->pushGui(new GuiTextEditPopup(getHelpStyle(), _("REFINE SEARCH"), searchString, + searchForFunc, false, _("SEARCH"), + _("SEARCH USING REFINED NAME?"))); } } @@ -1126,15 +1127,15 @@ std::vector GuiScraperSearch::getHelpPrompts() { std::vector prompts; - prompts.push_back(HelpPrompt("y", "refine search")); + prompts.push_back(HelpPrompt("y", _("refine search"))); // Only show the skip prompt during multi-scraping. if (mSkipCallback != nullptr) - prompts.push_back(HelpPrompt("x", "skip")); + prompts.push_back(HelpPrompt("x", _("skip"))); if (mFoundGame && (mRefinedSearch || mSearchType != SEMIAUTOMATIC_MODE || (mSearchType == SEMIAUTOMATIC_MODE && mScraperResults.size() > 1))) - prompts.push_back(HelpPrompt("a", "accept result")); + prompts.push_back(HelpPrompt("a", _("accept result"))); return prompts; } diff --git a/es-app/src/guis/GuiScraperSingle.cpp b/es-app/src/guis/GuiScraperSingle.cpp index 87ca11db5..85b95813d 100644 --- a/es-app/src/guis/GuiScraperSingle.cpp +++ b/es-app/src/guis/GuiScraperSingle.cpp @@ -16,6 +16,7 @@ #include "components/ButtonComponent.h" #include "components/MenuComponent.h" #include "components/TextComponent.h" +#include "utils/LocalizationUtil.h" GuiScraperSingle::GuiScraperSingle(ScraperSearchParams& params, std::function doneFunc, @@ -84,17 +85,18 @@ GuiScraperSingle::GuiScraperSingle(ScraperSearchParams& params, // Buttons std::vector> buttons; - buttons.push_back(std::make_shared("REFINE SEARCH", "refine search", [&] { - // Refine the search, unless the result has already been accepted. - if (!mSearch->getAcceptedResult()) { - // Copy any search refine that may have been previously entered by opening - // the input screen using the "Y" button shortcut. - mSearchParams.nameOverride = mSearch->getNameOverride(); - mSearch->openInputScreen(mSearchParams); - mGrid.resetCursor(); - } - })); - buttons.push_back(std::make_shared("CANCEL", "cancel", [&] { + buttons.push_back( + std::make_shared(_("REFINE SEARCH"), _("refine search"), [&] { + // Refine the search, unless the result has already been accepted. + if (!mSearch->getAcceptedResult()) { + // Copy any search refine that may have been previously entered by opening + // the input screen using the "Y" button shortcut. + mSearchParams.nameOverride = mSearch->getNameOverride(); + mSearch->openInputScreen(mSearchParams); + mGrid.resetCursor(); + } + })); + buttons.push_back(std::make_shared(_("CANCEL"), _("cancel"), [&] { if (mSearch->getSavedNewMedia()) { // If the user aborted the scraping but there was still some media downloaded, // then flag to GuiMetaDataEd that the image and marquee textures need to be @@ -194,7 +196,7 @@ void GuiScraperSingle::update(int deltaTime) std::vector GuiScraperSingle::getHelpPrompts() { std::vector prompts {mGrid.getHelpPrompts()}; - prompts.push_back(HelpPrompt("b", "back (cancel)")); + prompts.push_back(HelpPrompt("b", _("back (cancel)"))); return prompts; } diff --git a/es-core/src/components/BusyComponent.cpp b/es-core/src/components/BusyComponent.cpp index 76acabfcb..e81785f97 100644 --- a/es-core/src/components/BusyComponent.cpp +++ b/es-core/src/components/BusyComponent.cpp @@ -10,13 +10,14 @@ #include "components/AnimatedImageComponent.h" #include "components/ImageComponent.h" +#include "utils/LocalizationUtil.h" BusyComponent::BusyComponent() : mBackground {":/graphics/frame.png"} , mGrid {glm::ivec2 {5, 3}} { mAnimation = std::make_shared(); - mText = std::make_shared("WORKING...", Font::get(FONT_SIZE_MEDIUM), + mText = std::make_shared(_("WORKING..."), Font::get(FONT_SIZE_MEDIUM), mMenuColorPrimary); // Col 0 = animation, col 1 = spacer, col 2 = text.