From 14b65cb2e45a5a75237166791fc7f6a1da498542 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 16 Jul 2024 13:56:35 +0200 Subject: [PATCH] Added localization support to parts of the application --- es-app/src/CollectionSystemsManager.cpp | 19 +++++--- .../src/guis/GuiCollectionSystemsOptions.cpp | 28 +++++------ es-app/src/guis/GuiGamelistOptions.cpp | 21 ++++----- es-app/src/guis/GuiThemeDownloader.cpp | 47 +++++++++++-------- es-core/src/InputManager.cpp | 15 +++--- 5 files changed, 72 insertions(+), 58 deletions(-) diff --git a/es-app/src/CollectionSystemsManager.cpp b/es-app/src/CollectionSystemsManager.cpp index 13d0de17f..688f52e07 100644 --- a/es-app/src/CollectionSystemsManager.cpp +++ b/es-app/src/CollectionSystemsManager.cpp @@ -668,18 +668,21 @@ void CollectionSystemsManager::setEditMode(const std::string& collectionName, bo else editButton = "'Y'"; } - mWindow->queueInfoPopup("EDITING '" + Utils::String::toUpper(collectionName) + - "' COLLECTION, ADD/REMOVE GAMES WITH " + editButton, - 10000); + mWindow->queueInfoPopup( + Utils::String::format(_("EDITING '%s' COLLECTION, ADD/REMOVE GAMES WITH %s"), + Utils::String::toUpper(collectionName).c_str(), + editButton.c_str()), + 10000); } } void CollectionSystemsManager::exitEditMode(bool showPopup) { if (showPopup) { - mWindow->queueInfoPopup("FINISHED EDITING '" + Utils::String::toUpper(mEditingCollection) + - "' COLLECTION", - 4000); + mWindow->queueInfoPopup( + Utils::String::format(_("FINISHED EDITING '%s' COLLECTION"), + Utils::String::toUpper(mEditingCollection).c_str()), + 4000); } mIsEditingCustom = false; @@ -1037,7 +1040,9 @@ void CollectionSystemsManager::deleteCustomCollection(const std::string& collect << configFile << "\""; #endif mWindow->queueInfoPopup( - "DELETED COLLECTION '" + Utils::String::toUpper(collectionName) + "'", 5000); + Utils::String::format(_("DELETED COLLECTION '%s'"), + Utils::String::toUpper(collectionName).c_str()), + 5000); } else { LOG(LogError) << "Attempted to delete custom collection \"" + collectionName + "\" " + diff --git a/es-app/src/guis/GuiCollectionSystemsOptions.cpp b/es-app/src/guis/GuiCollectionSystemsOptions.cpp index ef1ec8225..70f2849ac 100644 --- a/es-app/src/guis/GuiCollectionSystemsOptions.cpp +++ b/es-app/src/guis/GuiCollectionSystemsOptions.cpp @@ -29,14 +29,13 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title) // Finish editing custom collection. if (CollectionSystemsManager::getInstance()->isEditing()) { ComponentListRow row; - row.addElement( - std::make_shared( - "FINISH EDITING '" + - Utils::String::toUpper( - CollectionSystemsManager::getInstance()->getEditingCollection()) + - "' COLLECTION", - Font::get(FONT_SIZE_MEDIUM), mMenuColorPrimary), - true); + const std::string editingText {Utils::String::format( + _("FINISH EDITING '%s' COLLECTION"), + Utils::String::toUpper(CollectionSystemsManager::getInstance()->getEditingCollection()) + .c_str())}; + row.addElement(std::make_shared(editingText, Font::get(FONT_SIZE_MEDIUM), + mMenuColorPrimary), + true); row.makeAcceptInputHandler([this] { CollectionSystemsManager::getInstance()->exitEditMode(); mWindow->invalidateCachedBackground(); @@ -261,11 +260,9 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title) std::function deleteCollectionCall = [this, name] { mWindow->pushGui(new GuiMsgBox( getHelpStyle(), - "THIS WILL PERMANENTLY\nDELETE THE COLLECTION\n'" + - Utils::String::toUpper(name) + - "'\n" - "ARE YOU SURE?", - "YES", + Utils::String::format(_("THIS WILL PERMANENTLY DELETE THE COLLECTION\n'%s'"), + Utils::String::toUpper(name).c_str()), + _("PROCEED"), [this, name] { if (CollectionSystemsManager::getInstance()->isEditing()) CollectionSystemsManager::getInstance()->exitEditMode(); @@ -300,7 +297,10 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title) CollectionSystemsManager::getInstance()->deleteCustomCollection(name); return true; }, - "NO", [] { return false; })); + _("CANCEL"), [] { return false; }, "", nullptr, nullptr, false, true, + (mRenderer->getIsVerticalOrientation() ? + 0.43f : + 0.28f * (1.778f / mRenderer->getScreenAspectRatio())))); }; row.makeAcceptInputHandler(deleteCollectionCall); auto customCollection = std::make_shared( diff --git a/es-app/src/guis/GuiGamelistOptions.cpp b/es-app/src/guis/GuiGamelistOptions.cpp index 6831f1ff0..535837cbc 100644 --- a/es-app/src/guis/GuiGamelistOptions.cpp +++ b/es-app/src/guis/GuiGamelistOptions.cpp @@ -174,7 +174,7 @@ GuiGamelistOptions::GuiGamelistOptions(SystemData* system) mSystem->getRootFolder()->getChildren().size() == 0 && !mIsCustomCollectionGroup && !mIsCustomCollection) { row.elements.clear(); - row.addElement(std::make_shared("THIS SYSTEM HAS NO GAMES", + row.addElement(std::make_shared(_("THIS SYSTEM HAS NO GAMES"), Font::get(FONT_SIZE_MEDIUM), mMenuColorPrimary), true); @@ -186,7 +186,7 @@ GuiGamelistOptions::GuiGamelistOptions(SystemData* system) if (CollectionSystemsManager::getInstance()->getEditingCollection() != getGamelist()->getCursor()->getSystem()->getName()) { row.elements.clear(); - row.addElement(std::make_shared("ADD/REMOVE GAMES TO THIS COLLECTION", + row.addElement(std::make_shared(_("ADD/REMOVE GAMES TO THIS COLLECTION"), Font::get(FONT_SIZE_MEDIUM), mMenuColorPrimary), true); @@ -197,15 +197,14 @@ GuiGamelistOptions::GuiGamelistOptions(SystemData* system) if (UIModeController::getInstance()->isUIModeFull() && CollectionSystemsManager::getInstance()->isEditing()) { + const std::string editingText {Utils::String::format( + _("FINISH EDITING '%s' COLLECTION"), + Utils::String::toUpper(CollectionSystemsManager::getInstance()->getEditingCollection()) + .c_str())}; row.elements.clear(); - row.addElement( - std::make_shared( - "FINISH EDITING '" + - Utils::String::toUpper( - CollectionSystemsManager::getInstance()->getEditingCollection()) + - "' COLLECTION", - Font::get(FONT_SIZE_MEDIUM), mMenuColorPrimary), - true); + row.addElement(std::make_shared(editingText, Font::get(FONT_SIZE_MEDIUM), + mMenuColorPrimary), + true); row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::exitEditMode, this)); mMenu.addRow(row); } @@ -254,7 +253,7 @@ GuiGamelistOptions::GuiGamelistOptions(SystemData* system) // Buttons. The logic to apply or cancel settings are handled by the destructor. if ((!mIsCustomCollectionGroup && system->getRootFolder()->getChildren().size() == 0) || system->getName() == "recent") { - mMenu.addButton("CLOSE", "close", [&] { + mMenu.addButton(_("CLOSE"), _("close"), [&] { mCancelled = true; delete this; }); diff --git a/es-app/src/guis/GuiThemeDownloader.cpp b/es-app/src/guis/GuiThemeDownloader.cpp index 37918ae3c..0d468f8a2 100644 --- a/es-app/src/guis/GuiThemeDownloader.cpp +++ b/es-app/src/guis/GuiThemeDownloader.cpp @@ -581,7 +581,9 @@ bool GuiThemeDownloader::renameDirectory(const std::string& path, const std::str if (renameStatus) { mWindow->pushGui(new GuiMsgBox( - getHelpStyle(), "COULDN'T RENAME DIRECTORY \"" + path + "\", PERMISSION PROBLEMS?", + getHelpStyle(), + Utils::String::format(_("COULDN'T RENAME DIRECTORY \"%s\"\nPERMISSION PROBLEMS?"), + path.c_str()), _("OK"), [] { return; }, "", nullptr, "", nullptr, nullptr, true)); return true; } @@ -773,11 +775,12 @@ void GuiThemeDownloader::populateGUI() if (theme.manuallyDownloaded || theme.invalidRepository) { mWindow->pushGui(new GuiMsgBox( getHelpStyle(), - "IT SEEMS AS IF THIS THEME HAS BEEN MANUALLY DOWNLOADED INSTEAD OF VIA " - "THIS THEME DOWNLOADER. A FRESH DOWNLOAD IS REQUIRED AND THE OLD THEME " - "DIRECTORY \"" + - theme.reponame + theme.manualExtension + "\" WILL BE RENAMED TO \"" + - theme.reponame + theme.manualExtension + "_DISABLED\"", + Utils::String::format( + _("IT SEEMS AS IF THIS THEME HAS BEEN MANUALLY DOWNLOADED INSTEAD OF VIA " + "THIS THEME DOWNLOADER. A FRESH DOWNLOAD IS REQUIRED AND THE OLD THEME " + "DIRECTORY \"%s\" WILL BE RENAMED TO \"%s_DISABLED\""), + std::string {theme.reponame + theme.manualExtension}.c_str(), + std::string {theme.reponame + theme.manualExtension}.c_str()), _("PROCEED"), [this, theme] { if (renameDirectory(mThemeDirectory + theme.reponame + @@ -800,12 +803,13 @@ void GuiThemeDownloader::populateGUI() else if (theme.corruptRepository) { mWindow->pushGui(new GuiMsgBox( getHelpStyle(), - "IT SEEMS AS IF THIS THEME REPOSITORY IS CORRUPT, WHICH COULD HAVE BEEN CAUSED " - "BY AN INTERRUPTION OF A PREVIOUS DOWNLOAD OR UPDATE, FOR EXAMPLE IF THE ES-DE " - "PROCESS WAS KILLED. A FRESH DOWNLOAD IS REQUIRED AND THE OLD THEME DIRECTORY " - "\"" + - theme.reponame + theme.manualExtension + "\" WILL BE RENAMED TO \"" + - theme.reponame + theme.manualExtension + "_CORRUPT_DISABLED\"", + Utils::String::format( + _("IT SEEMS AS IF THIS THEME REPOSITORY IS CORRUPT, WHICH COULD HAVE BEEN " + "CAUSED BY AN INTERRUPTION OF A PREVIOUS DOWNLOAD OR UPDATE, FOR EXAMPLE " + "IF THE ES-DE PROCESS WAS KILLED. A FRESH DOWNLOAD IS REQUIRED AND THE " + "OLD THEME DIRECTORY \"%s\" WILL BE RENAMED TO \"%s_CORRUPT_DISABLED\""), + std::string {theme.reponame + theme.manualExtension}.c_str(), + std::string {theme.reponame + theme.manualExtension}.c_str()), _("PROCEED"), [this, theme] { if (renameDirectory(mThemeDirectory + theme.reponame + @@ -828,11 +832,13 @@ void GuiThemeDownloader::populateGUI() else if (theme.shallowRepository) { mWindow->pushGui(new GuiMsgBox( getHelpStyle(), - "IT SEEMS AS IF THIS IS A SHALLOW REPOSITORY WHICH MEANS THAT IT HAS BEEN " - "DOWNLOADED USING SOME OTHER TOOL THAN THIS THEME DOWNLOADER. A FRESH DOWNLOAD " - "IS REQUIRED AND THE OLD THEME DIRECTORY \"" + - theme.reponame + theme.manualExtension + "\" WILL BE RENAMED TO \"" + - theme.reponame + theme.manualExtension + "_DISABLED\"", + Utils::String::format( + _("IT SEEMS AS IF THIS IS A SHALLOW REPOSITORY WHICH MEANS THAT IT HAS " + "BEEN DOWNLOADED USING SOME OTHER TOOL THAN THIS THEME DOWNLOADER. A " + "FRESH DOWNLOAD IS REQUIRED AND THE OLD THEME DIRECTORY \"%s\" WILL BE " + "RENAMED TO \"%s_DISABLED\""), + std::string {theme.reponame + theme.manualExtension}.c_str(), + std::string {theme.reponame + theme.manualExtension}.c_str()), _("PROCEED"), [this, theme] { if (renameDirectory(mThemeDirectory + theme.reponame + @@ -855,9 +861,10 @@ void GuiThemeDownloader::populateGUI() else if (theme.hasLocalChanges) { mWindow->pushGui(new GuiMsgBox( getHelpStyle(), - "THEME REPOSITORY \"" + theme.reponame + - "\" CONTAINS LOCAL CHANGES. PROCEED TO OVERWRITE YOUR CHANGES " - "OR CANCEL TO SKIP ALL UPDATES FOR THIS THEME", + Utils::String::format( + _("THEME REPOSITORY \"%s\" CONTAINS LOCAL CHANGES. PROCEED TO OVERWRITE " + "YOUR CHANGES OR CANCEL TO SKIP ALL UPDATES FOR THIS THEME"), + std::string {theme.reponame}.c_str()), _("PROCEED"), [this, theme] { std::promise().swap(mPromise); diff --git a/es-core/src/InputManager.cpp b/es-core/src/InputManager.cpp index d0e9d078e..e528aa1d0 100644 --- a/es-core/src/InputManager.cpp +++ b/es-core/src/InputManager.cpp @@ -15,6 +15,7 @@ #include "Window.h" #include "resources/ResourceManager.h" #include "utils/FileSystemUtil.h" +#include "utils/LocalizationUtil.h" #include "utils/PlatformUtil.h" #include "utils/StringUtil.h" @@ -822,9 +823,10 @@ void InputManager::addControllerByDeviceIndex(Window* window, int deviceIndex) if (window != nullptr) { window->queueInfoPopup( - "ADDED INPUT DEVICE '" + - Utils::String::toUpper(std::string(SDL_GameControllerName(mControllers[joyID]))) + - "'", + Utils::String::format( + _("ADDED INPUT DEVICE '%s'"), + Utils::String::toUpper(std::string(SDL_GameControllerName(mControllers[joyID]))) + .c_str()), 4000); } @@ -870,9 +872,10 @@ void InputManager::removeControllerByJoystickID(Window* window, SDL_JoystickID j if (window != nullptr) { window->queueInfoPopup( - "REMOVED INPUT DEVICE '" + - Utils::String::toUpper(std::string(SDL_GameControllerName(mControllers[joyID]))) + - "'", + Utils::String::format( + _("REMOVED INPUT DEVICE '%s'"), + Utils::String::toUpper(std::string(SDL_GameControllerName(mControllers[joyID]))) + .c_str()), 4000); }