From 72ee58e7489d00a8d4df3cdbb4e38d03f0619b64 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 18 Jul 2024 15:07:41 +0200 Subject: [PATCH] Added localization support to parts of the application --- es-app/src/CollectionSystemsManager.cpp | 111 +++++++++++---------- es-app/src/FileData.cpp | 100 +++++++++++-------- es-app/src/guis/GuiGamelistOptions.cpp | 4 +- es-app/src/guis/GuiMenu.cpp | 7 +- es-app/src/guis/GuiScraperSearch.cpp | 2 +- es-app/src/guis/GuiSettings.cpp | 2 +- es-app/src/guis/GuiThemeDownloader.cpp | 2 +- es-app/src/views/ViewController.cpp | 8 +- es-core/src/AsyncHandle.h | 2 +- es-core/src/components/SliderComponent.cpp | 3 +- 10 files changed, 138 insertions(+), 103 deletions(-) diff --git a/es-app/src/CollectionSystemsManager.cpp b/es-app/src/CollectionSystemsManager.cpp index c9d64a6a2..7e2e4c119 100644 --- a/es-app/src/CollectionSystemsManager.cpp +++ b/es-app/src/CollectionSystemsManager.cpp @@ -884,48 +884,51 @@ FileData* CollectionSystemsManager::updateCollectionFolderMetadata(SystemData* s }; switch (gameCount) { case 1: { - desc = "This collection contains 1 game: '"; - desc.append(gamesList[0]->metadata.get("name")) - .append(" [") - .append(caseConversion( - gamesList[0]->getSourceFileData()->getSystem()->getName())) - .append("]'"); + desc = Utils::String::format( + _("This collection contains 1 game: '%s [%s]'"), + gamesList[0]->metadata.get("name").c_str(), + caseConversion(gamesList[0]->getSourceFileData()->getSystem()->getName()) + .c_str()); break; } case 2: { - desc = "This collection contains 2 games: '"; - desc.append(gamesList[0]->metadata.get("name")) - .append(" [") - .append(caseConversion( - gamesList[0]->getSourceFileData()->getSystem()->getName())) - .append("]' and '") - .append(gamesList[1]->metadata.get("name")) - .append(" [") - .append(caseConversion( - gamesList[1]->getSourceFileData()->getSystem()->getName())) - .append("]'"); + desc = Utils::String::format( + _("This collection contains 2 games: '%s [%s]' and '%s [%s]'"), + gamesList[0]->metadata.get("name").c_str(), + caseConversion(gamesList[0]->getSourceFileData()->getSystem()->getName()) + .c_str(), + gamesList[1]->metadata.get("name").c_str(), + caseConversion(gamesList[1]->getSourceFileData()->getSystem()->getName()) + .c_str()); + break; + } + case 3: { + desc = Utils::String::format( + _("This collection contains 3 games: '%s [%s]', '%s [%s]' and '%s [%s]'"), + gamesList[0]->metadata.get("name").c_str(), + caseConversion(gamesList[0]->getSourceFileData()->getSystem()->getName()) + .c_str(), + gamesList[1]->metadata.get("name").c_str(), + caseConversion(gamesList[1]->getSourceFileData()->getSystem()->getName()) + .c_str(), + gamesList[2]->metadata.get("name").c_str(), + caseConversion(gamesList[2]->getSourceFileData()->getSystem()->getName()) + .c_str()); break; } default: { - desc = "This collection contains "; - desc.append(std::to_string(gameCount)) - .append(" games: '") - .append(gamesList[0]->metadata.get("name")) - .append(" [") - .append(caseConversion( - gamesList[0]->getSourceFileData()->getSystem()->getName())) - .append("]', '") - .append(gamesList[1]->metadata.get("name")) - .append(" [") - .append(caseConversion( - gamesList[1]->getSourceFileData()->getSystem()->getName())) - .append("]' and '") - .append(gamesList[2]->metadata.get("name")) - .append(" [") - .append(caseConversion( - gamesList[2]->getSourceFileData()->getSystem()->getName())) - .append("]'"); - desc.append(gameCount == 3 ? "" : ", among others"); + desc = Utils::String::format( + _("This collection contains %i games: '%s [%s]', '%s [%s]' and '%s [%s]', " + "among others"), + gameCount, gamesList[0]->metadata.get("name").c_str(), + caseConversion(gamesList[0]->getSourceFileData()->getSystem()->getName()) + .c_str(), + gamesList[1]->metadata.get("name").c_str(), + caseConversion(gamesList[1]->getSourceFileData()->getSystem()->getName()) + .c_str(), + gamesList[2]->metadata.get("name").c_str(), + caseConversion(gamesList[2]->getSourceFileData()->getSystem()->getName()) + .c_str()); break; } } @@ -933,29 +936,31 @@ FileData* CollectionSystemsManager::updateCollectionFolderMetadata(SystemData* s else { switch (gameCount) { case 1: { - desc = "This collection contains 1 game: '"; - desc.append(gamesList[0]->metadata.get("name")).append("'"); + desc = Utils::String::format(_("This collection contains 1 game: '%s'"), + gamesList[0]->metadata.get("name").c_str()); break; } case 2: { - desc = "This collection contains 2 games: '"; - desc.append(gamesList[0]->metadata.get("name")) - .append("' and '") - .append(gamesList[1]->metadata.get("name")) - .append("'"); + desc = + Utils::String::format(_("This collection contains 2 games: '%s' and '%s'"), + gamesList[0]->metadata.get("name").c_str(), + gamesList[1]->metadata.get("name").c_str()); + break; + } + case 3: { + desc = Utils::String::format( + _("This collection contains 3 games: '%s', '%s' and '%s'"), + gamesList[0]->metadata.get("name").c_str(), + gamesList[1]->metadata.get("name").c_str(), + gamesList[2]->metadata.get("name").c_str()); break; } default: { - desc = "This collection contains "; - desc.append(std::to_string(gameCount)) - .append(" games: '") - .append(gamesList[0]->metadata.get("name")) - .append("', '") - .append(gamesList[1]->metadata.get("name")) - .append("' and '") - .append(gamesList[2]->metadata.get("name")) - .append("'"); - desc.append(gameCount == 3 ? "" : ", among others"); + desc = Utils::String::format( + _("This collection contains %i games: '%s', '%s' and '%s', among others"), + gameCount, gamesList[0]->metadata.get("name").c_str(), + gamesList[1]->metadata.get("name").c_str(), + gamesList[2]->metadata.get("name").c_str()); break; } } diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 2c5765798..d1cc842ac 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -1047,9 +1047,11 @@ void FileData::launchGame() LOG(LogError) << "Raw emulator launch command:"; LOG(LogError) << commandRaw; - window->queueInfoPopup("ERROR: MISSING PRE-COMMAND FIND RULES CONFIGURATION FOR '" + - preCommand.first + "'", - 6000); + window->queueInfoPopup( + Utils::String::format( + _("ERROR: MISSING PRE-COMMAND FIND RULES CONFIGURATION FOR '%s'"), + preCommand.first.c_str()), + 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1071,11 +1073,13 @@ void FileData::launchGame() if (emulatorName == "") window->queueInfoPopup( - "ERROR: COULDN'T FIND PRE-COMMAND, HAS IT BEEN PROPERLY INSTALLED?", 6000); + _("ERROR: COULDN'T FIND PRE-COMMAND, HAS IT BEEN PROPERLY INSTALLED?"), 6000); else - window->queueInfoPopup("ERROR: COULDN'T FIND PRE-COMMAND '" + emulatorName + - "', HAS IT BEEN PROPERLY INSTALLED?", - 6000); + window->queueInfoPopup( + Utils::String::format( + _("ERROR: COULDN'T FIND PRE-COMMAND '%s', HAS IT BEEN PROPERLY INSTALLED?"), + emulatorName.c_str()), + 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); @@ -1170,7 +1174,9 @@ void FileData::launchGame() LOG(LogError) << commandRaw; window->queueInfoPopup( - "ERROR: MISSING EMULATOR FIND RULES CONFIGURATION FOR '" + emulator.first + "'", 6000); + Utils::String::format(_("ERROR: MISSING EMULATOR FIND RULES CONFIGURATION FOR '%s'"), + emulator.first.c_str()), + 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1205,24 +1211,28 @@ void FileData::launchGame() #endif if (isAndroidApp) { if (emulatorName == "" || emulatorName == "%FILEINJECT%") { - window->queueInfoPopup("ERROR: COULDN'T FIND APP, HAS IT BEEN PROPERLY INSTALLED?", - 6000); + window->queueInfoPopup( + _("ERROR: COULDN'T FIND APP, HAS IT BEEN PROPERLY INSTALLED?"), 6000); } else { - window->queueInfoPopup("ERROR: COULDN'T FIND APP '" + emulatorName + - "', HAS IT BEEN PROPERLY INSTALLED?", - 6000); + window->queueInfoPopup( + Utils::String::format( + _("ERROR: COULDN'T FIND APP '%s', HAS IT BEEN PROPERLY INSTALLED?"), + emulatorName.c_str()), + 6000); } } else { if (emulatorName == "") { window->queueInfoPopup( - "ERROR: COULDN'T FIND EMULATOR, HAS IT BEEN PROPERLY INSTALLED?", 6000); + _("ERROR: COULDN'T FIND EMULATOR, HAS IT BEEN PROPERLY INSTALLED?"), 6000); } else { - window->queueInfoPopup("ERROR: COULDN'T FIND EMULATOR '" + emulatorName + - "', HAS IT BEEN PROPERLY INSTALLED?", - 6000); + window->queueInfoPopup( + Utils::String::format( + _("ERROR: COULDN'T FIND EMULATOR '%s', HAS IT BEEN PROPERLY INSTALLED?"), + emulatorName.c_str()), + 6000); } } @@ -1295,8 +1305,9 @@ void FileData::launchGame() LOG(LogError) << commandRaw; window->queueInfoPopup( - "ERROR: COULDN'T FIND EMULATOR CORE FILE '" + - Utils::String::toUpper(Utils::FileSystem::getFileName(coreFile)) + "'", + Utils::String::format( + _("ERROR: COULDN'T FIND EMULATOR CORE FILE '%s'"), + Utils::String::toUpper(Utils::FileSystem::getFileName(coreFile)).c_str()), 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); @@ -1317,7 +1328,7 @@ void FileData::launchGame() LOG(LogError) << "Raw emulator launch command:"; LOG(LogError) << commandRaw; - window->queueInfoPopup("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE", 6000); + window->queueInfoPopup(_("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE"), 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1331,7 +1342,10 @@ void FileData::launchGame() LOG(LogError) << "Raw emulator launch command:"; LOG(LogError) << commandRaw; - window->queueInfoPopup("ERROR: MISSING CORE CONFIGURATION FOR '" + coreEntry + "'", 6000); + window->queueInfoPopup( + Utils::String::format(_("ERROR: MISSING CORE CONFIGURATION FOR '%s'"), + coreEntry.c_str()), + 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1400,7 +1414,7 @@ void FileData::launchGame() LOG(LogError) << "Raw emulator launch command:"; LOG(LogError) << commandRaw; - window->queueInfoPopup("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE", 6000); + window->queueInfoPopup(_("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE"), 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1416,8 +1430,9 @@ void FileData::launchGame() LOG(LogError) << Utils::String::vectorToDelimitedString(emulatorCorePaths, ", "); window->queueInfoPopup( - "ERROR: COULDN'T FIND EMULATOR CORE FILE '" + - Utils::String::toUpper(coreName.substr(0, coreName.size()) + "'"), + Utils::String::format( + _("ERROR: COULDN'T FIND EMULATOR CORE FILE '%s'"), + Utils::String::toUpper(coreName.substr(0, coreName.size())).c_str()), 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); @@ -1464,7 +1479,8 @@ void FileData::launchGame() LOG(LogError) << "Raw emulator launch command:"; LOG(LogError) << commandRaw; - window->queueInfoPopup("ERROR: INVALID %STARTDIR% VARIABLE ENTRY", 6000); + window->queueInfoPopup( + Utils::String::format(_("ERROR: INVALID %s VARIABLE ENTRY"), "%STARTDIR%"), 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1505,9 +1521,11 @@ void FileData::launchGame() LOG(LogError) << "Raw emulator launch command:"; LOG(LogError) << commandRaw; - window->queueInfoPopup("ERROR: DIRECTORY DEFINED BY %STARTDIR% COULD NOT BE " - "CREATED, PERMISSION PROBLEMS?", - 6000); + window->queueInfoPopup( + Utils::String::format(_("ERROR: DIRECTORY DEFINED BY %s COULD NOT BE " + "CREATED, PERMISSION PROBLEMS?"), + "%STARTDIR%"), + 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1563,7 +1581,8 @@ void FileData::launchGame() LOG(LogError) << "Raw emulator launch command:"; LOG(LogError) << commandRaw; - window->queueInfoPopup("ERROR: INVALID %INJECT% VARIABLE ENTRY", 6000); + window->queueInfoPopup( + Utils::String::format(_("ERROR: INVALID %s VARIABLE ENTRY"), "%INJECT%"), 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1675,7 +1694,8 @@ void FileData::launchGame() else { LOG(LogError) << "App or alias file \"" << romPath << "\" doesn't exist or is unreadable"; - window->queueInfoPopup("ERROR: APP OR ALIAS FILE DOESN'T EXIST OR IS UNREADABLE", 6000); + window->queueInfoPopup(_("ERROR: APP OR ALIAS FILE DOESN'T EXIST OR IS UNREADABLE"), + 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1729,7 +1749,7 @@ void FileData::launchGame() desktopFileStream.close(); if (!validFile || !execEntry) { LOG(LogError) << "File is invalid or unreadable"; - window->queueInfoPopup("ERROR: DESKTOP FILE IS INVALID OR UNREADABLE", 6000); + window->queueInfoPopup(_("ERROR: DESKTOP FILE IS INVALID OR UNREADABLE"), 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1737,7 +1757,7 @@ void FileData::launchGame() } else { LOG(LogError) << "Desktop file \"" << romPath << "\" doesn't exist or is unreadable"; - window->queueInfoPopup("ERROR: DESKTOP FILE DOESN'T EXIST OR IS UNREADABLE", 6000); + window->queueInfoPopup(_("ERROR: DESKTOP FILE DOESN'T EXIST OR IS UNREADABLE"), 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1795,7 +1815,8 @@ void FileData::launchGame() LOG(LogError) << "Raw emulator launch command:"; LOG(LogError) << commandRaw; - window->queueInfoPopup("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE", 6000); + window->queueInfoPopup(_("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE"), + 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -1859,8 +1880,8 @@ void FileData::launchGame() LOG(LogError) << "Raw emulator launch command:"; LOG(LogError) << commandRaw; - window->queueInfoPopup("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE", - 6000); + window->queueInfoPopup( + _("ERROR: INVALID ENTRY IN SYSTEMS CONFIGURATION FILE"), 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); return; @@ -2025,10 +2046,11 @@ returnValue = Utils::Platform::launchGameUnix(command, startDirectory, runInBack if (returnValue != 0) { LOG(LogWarning) << "Launch terminated with nonzero return value " << returnValue; - window->queueInfoPopup("ERROR LAUNCHING GAME '" + - Utils::String::toUpper(metadata.get("name")) + "' (ERROR CODE " + - Utils::String::toUpper(std::to_string(returnValue) + ")"), - 6000); + window->queueInfoPopup( + Utils::String::format(_("ERROR LAUNCHING GAME '%s' (ERROR CODE %i)"), + Utils::String::toUpper(metadata.get("name")).c_str(), + returnValue), + 6000); window->setAllowTextScrolling(true); window->setAllowFileAnimation(true); } diff --git a/es-app/src/guis/GuiGamelistOptions.cpp b/es-app/src/guis/GuiGamelistOptions.cpp index 535837cbc..48c61583d 100644 --- a/es-app/src/guis/GuiGamelistOptions.cpp +++ b/es-app/src/guis/GuiGamelistOptions.cpp @@ -259,8 +259,8 @@ GuiGamelistOptions::GuiGamelistOptions(SystemData* system) }); } else { - mMenu.addButton(_("APPLY"), _("APPLY"), [&] { delete this; }); - mMenu.addButton(_("CANCEL"), _("CANCEL"), [&] { + mMenu.addButton(_("APPLY"), _("apply"), [&] { delete this; }); + mMenu.addButton(_("CANCEL"), _("cancel"), [&] { mCancelled = true; delete this; }); diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index d28c9c614..f14b29cd0 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -541,7 +541,12 @@ void GuiMenu::openUIOptions() it != SystemData::sSystemVector.cend(); ++it) { // If required, abbreviate the system name so it doesn't overlap the setting name. float maxNameLength {mSize.x * 0.51f}; - startupSystem->add(Utils::String::toUpper((*it)->getFullName()), (*it)->getName(), + std::string sysName {(*it)->getFullName()}; + if ((*it)->isCollection() && (sysName == "collections" || sysName == "all games" || + sysName == "favorites" || sysName == "last played")) { + sysName = _(sysName.c_str()); + } + startupSystem->add(Utils::String::toUpper(sysName), (*it)->getName(), Settings::getInstance()->getString("StartupSystem") == (*it)->getName(), maxNameLength); } diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index a62f08695..f396822b4 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -558,7 +558,7 @@ void GuiScraperSearch::onSearchError(const std::string& error, { if (fatalError) { LOG(LogWarning) << "GuiScraperSearch: " << Utils::String::replace(error, "\n", ""); - mWindow->pushGui(new GuiMsgBox(getHelpStyle(), Utils::String::toUpper(error), "OK", + mWindow->pushGui(new GuiMsgBox(getHelpStyle(), Utils::String::toUpper(error), _("OK"), mCancelCallback, "", nullptr, "", nullptr, nullptr, true)); return; } diff --git a/es-app/src/guis/GuiSettings.cpp b/es-app/src/guis/GuiSettings.cpp index ecd3235cc..b4fa3ce7d 100644 --- a/es-app/src/guis/GuiSettings.cpp +++ b/es-app/src/guis/GuiSettings.cpp @@ -39,7 +39,7 @@ GuiSettings::GuiSettings(std::string title) , mInvalidateCachedBackground {false} { addChild(&mMenu); - mMenu.addButton(_("BACK"), "back", [this] { delete this; }); + mMenu.addButton(_("BACK"), _("back"), [this] { delete this; }); setSize(Renderer::getScreenWidth(), Renderer::getScreenHeight()); mMenu.setPosition((mSize.x - mMenu.getSize().x) / 2.0f, Renderer::getScreenHeight() * 0.13f); diff --git a/es-app/src/guis/GuiThemeDownloader.cpp b/es-app/src/guis/GuiThemeDownloader.cpp index 0d468f8a2..840998ddc 100644 --- a/es-app/src/guis/GuiThemeDownloader.cpp +++ b/es-app/src/guis/GuiThemeDownloader.cpp @@ -130,7 +130,7 @@ GuiThemeDownloader::GuiThemeDownloader(std::function updateCallback) std::vector> buttons; buttons.push_back( - std::make_shared(_("CLOSE"), _("CLOSE"), [&] { delete this; })); + std::make_shared(_("CLOSE"), _("close"), [&] { delete this; })); mButtons = MenuComponent::makeButtonGrid(buttons); mGrid.setEntry(mButtons, glm::ivec2 {0, 3}, true, false, glm::ivec2 {2, 1}, GridFlags::BORDER_TOP); diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 0d0414a4a..8e7aa28bb 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -158,8 +158,8 @@ void ViewController::legacyAppDataDialog() #endif mWindow->pushGui(new GuiMsgBox( - HelpStyle(), upgradeMessage.c_str(), "OK", [] {}, "", nullptr, "", nullptr, nullptr, true, - true, + HelpStyle(), upgradeMessage.c_str(), _("OK"), [] {}, "", nullptr, "", nullptr, nullptr, + true, true, (mRenderer->getIsVerticalOrientation() ? 0.85f : 0.55f * (1.778f / mRenderer->getScreenAspectRatio())))); @@ -981,7 +981,9 @@ void ViewController::launch(FileData* game) // If the game launch screen has been set as disabled, show a simple info popup // notification instead. mWindow->queueInfoPopup( - "LAUNCHING GAME '" + Utils::String::toUpper(game->metadata.get("name") + "'"), 10000); + Utils::String::format(_("LAUNCHING GAME '%s'"), + Utils::String::toUpper(game->metadata.get("name")).c_str()), + 10000); duration = 1700; } else if (durationString == "brief") { diff --git a/es-core/src/AsyncHandle.h b/es-core/src/AsyncHandle.h index 85d938106..ec0511bff 100644 --- a/es-core/src/AsyncHandle.h +++ b/es-core/src/AsyncHandle.h @@ -53,7 +53,7 @@ public: case ASYNC_DONE: return "done"; default: - return "something impossible has occured; row, row, fight the power"; + return "something impossible has occured"; } } diff --git a/es-core/src/components/SliderComponent.cpp b/es-core/src/components/SliderComponent.cpp index 4fb912647..e7d7dfe29 100644 --- a/es-core/src/components/SliderComponent.cpp +++ b/es-core/src/components/SliderComponent.cpp @@ -10,6 +10,7 @@ #include "Window.h" #include "resources/Font.h" +#include "utils/LocalizationUtil.h" #define MOVE_REPEAT_DELAY 500 #define MOVE_REPEAT_RATE 40 @@ -212,6 +213,6 @@ void SliderComponent::onValueChanged() std::vector SliderComponent::getHelpPrompts() { std::vector prompts; - prompts.push_back(HelpPrompt("left/right", "change value")); + prompts.push_back(HelpPrompt("left/right", _("change value"))); return prompts; }