From 47a8363f322709ca297025e09068f93932269163 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 17 Jul 2024 19:51:18 +0200 Subject: [PATCH] Added localization support to parts of the application --- es-app/src/CollectionSystemsManager.cpp | 23 ++++++++++----- es-app/src/guis/GuiMetaDataEd.cpp | 39 ++++++++++++++++++++----- es-app/src/guis/GuiScraperSearch.cpp | 25 +++++++++++++--- es-app/src/views/GamelistBase.cpp | 30 ++++++++++--------- es-app/src/views/GamelistView.cpp | 2 ++ 5 files changed, 86 insertions(+), 33 deletions(-) diff --git a/es-app/src/CollectionSystemsManager.cpp b/es-app/src/CollectionSystemsManager.cpp index 688f52e07..c9d64a6a2 100644 --- a/es-app/src/CollectionSystemsManager.cpp +++ b/es-app/src/CollectionSystemsManager.cpp @@ -397,10 +397,12 @@ void CollectionSystemsManager::updateCollectionSystem(FileData* file, Collection parentRootFolder->getSortTypeString()), favoritesSorting); mWindow->queueInfoPopup( - "DISABLED '" + + Utils::String::format( + _("DISABLED '%s' IN '%s'"), Utils::String::toUpper( - Utils::String::removeParenthesis(file->getName())) + - "' IN '" + Utils::String::toUpper(sysData.system->getName()) + "'", + Utils::String::removeParenthesis(file->getName())) + .c_str(), + Utils::String::toUpper(sysData.system->getName()).c_str()), 4000); } else { @@ -786,14 +788,19 @@ const bool CollectionSystemsManager::toggleGameInCollection(FileData* file) ViewController::getInstance()->reloadGamelistView( mAutoCollectionSystemsData["favorites"].system); } + std::string sysTemp {sysName}; + if (sysTemp == "Favorites") + sysTemp = _("Favorites"); if (adding) { - mWindow->queueInfoPopup("ADDED '" + Utils::String::toUpper(name) + "' TO '" + - Utils::String::toUpper(sysName) + "'", + mWindow->queueInfoPopup(Utils::String::format(_("ADDED '%s' TO '%s'"), + Utils::String::toUpper(name).c_str(), + Utils::String::toUpper(sysTemp).c_str()), 4000); } else { - mWindow->queueInfoPopup("REMOVED '" + Utils::String::toUpper(name) + "' FROM '" + - Utils::String::toUpper(sysName) + "'", + mWindow->queueInfoPopup(Utils::String::format(_("REMOVED '%s' FROM '%s'"), + Utils::String::toUpper(name).c_str(), + Utils::String::toUpper(sysTemp).c_str()), 4000); } return true; @@ -825,7 +832,7 @@ FileData* CollectionSystemsManager::updateCollectionFolderMetadata(SystemData* s FileData* rootFolder {sys->getRootFolder()}; FileFilterIndex* idx {rootFolder->getSystem()->getIndex()}; - std::string desc {"This collection is empty"}; + std::string desc {_("This collection is empty")}; std::vector gamesList; std::vector gamesListRandom; diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 04e4f0d49..cd38ae4a9 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -593,7 +593,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, else if (newVal == "" && (currentKey == "developer" || currentKey == "publisher" || currentKey == "genre" || currentKey == "players")) { - ed->setValue("unknown"); + ed->setValue(_("unknown")); if (originalValue == "unknown") ed->setColor(mMenuColorPrimary); else @@ -601,10 +601,17 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, } else { ed->setValue(newVal); - if (newVal == originalValue) + if ((currentKey == "developer" || currentKey == "publisher" || + currentKey == "genre" || currentKey == "players") && + newVal == _("unknown") && newVal == _(originalValue.c_str())) { ed->setColor(mMenuColorPrimary); - else - ed->setColor(mMenuColorBlue); + } + else { + if (newVal == originalValue) + ed->setColor(mMenuColorPrimary); + else + ed->setColor(mMenuColorBlue); + } } }; @@ -645,7 +652,12 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, ed->setValue(ViewController::EXCLAMATION_CHAR + " " + mMetaData->get(it->key)); } else { - ed->setValue(mMetaData->get(it->key)); + if ((currentKey == "developer" || currentKey == "publisher" || currentKey == "genre" || + currentKey == "players") && + mMetaData->get(it->key) == "unknown") + ed->setValue(_(mMetaData->get(it->key).c_str())); + else + ed->setValue(mMetaData->get(it->key)); } mEditors.push_back(ed); @@ -784,7 +796,7 @@ void GuiMetaDataEd::save() bool setGameAsCounted {false}; int offset {0}; - for (unsigned int i = 0; i < mEditors.size(); ++i) { + for (unsigned int i {0}; i < mEditors.size(); ++i) { // The offset is needed to make the editor and metadata fields match up if we're // skipping the custom collections sortname field (which we do if not editing the // game from within a custom collection gamelist). @@ -803,7 +815,7 @@ void GuiMetaDataEd::save() continue; if (key == "controller" && mEditors.at(i)->getValue() != "") { - std::string shortName = BadgeComponent::getShortName(mEditors.at(i)->getValue()); + std::string shortName {BadgeComponent::getShortName(mEditors.at(i)->getValue())}; if (shortName != "unknown") mMetaData->set(key, shortName); continue; @@ -819,7 +831,13 @@ void GuiMetaDataEd::save() setGameAsCounted = true; } - mMetaData->set(key, mEditors.at(i)->getValue()); + if ((key == "developer" || key == "publisher" || key == "genre" || key == "players") && + mEditors.at(i)->getValue() == _("unknown")) { + mMetaData->set(key, "unknown"); + } + else { + mMetaData->set(key, mEditors.at(i)->getValue()); + } } // If hidden games are not shown and the hide flag was set for the entry, then write the @@ -980,6 +998,11 @@ void GuiMetaDataEd::close() std::string mMetaDataValue {mMetaData->get(key)}; std::string mEditorsValue {mEditors.at(i)->getValue()}; + if ((key == "developer" || key == "publisher" || key == "genre" || key == "players") && + mEditorsValue == _("unknown")) { + mEditorsValue = "unknown"; + } + if (key == "controller" && mEditors.at(i)->getValue() != "") { std::string shortName = BadgeComponent::getShortName(mEditors.at(i)->getValue()); if (shortName == "unknown" || mMetaDataValue == shortName) diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 03929ed8e..a62f08695 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -648,10 +648,27 @@ void GuiScraperSearch::updateInfoPane() mMD_Rating->setOpacity(1.0f); } mMD_ReleaseDate->setValue(Utils::String::toUpper(res.mdl.get("releasedate"))); - mMD_Developer->setText(Utils::String::toUpper(res.mdl.get("developer"))); - mMD_Publisher->setText(Utils::String::toUpper(res.mdl.get("publisher"))); - mMD_Genre->setText(Utils::String::toUpper(res.mdl.get("genre"))); - mMD_Players->setText(Utils::String::toUpper(res.mdl.get("players"))); + + if (res.mdl.get("developer") == "unknown") + mMD_Developer->setText(Utils::String::toUpper(_(res.mdl.get("developer").c_str()))); + else + mMD_Developer->setText(Utils::String::toUpper(res.mdl.get("developer"))); + + if (res.mdl.get("publisher") == "unknown") + mMD_Publisher->setText(Utils::String::toUpper(_(res.mdl.get("publisher").c_str()))); + else + mMD_Publisher->setText(Utils::String::toUpper(res.mdl.get("publisher"))); + + if (res.mdl.get("genre") == "unknown") + mMD_Genre->setText(Utils::String::toUpper(_(res.mdl.get("genre").c_str()))); + else + mMD_Genre->setText(Utils::String::toUpper(res.mdl.get("genre"))); + + if (res.mdl.get("players") == "unknown") + mMD_Players->setText(Utils::String::toUpper(_(res.mdl.get("players").c_str()))); + else + mMD_Players->setText(Utils::String::toUpper(res.mdl.get("players"))); + mGrid.onSizeChanged(); } else { diff --git a/es-app/src/views/GamelistBase.cpp b/es-app/src/views/GamelistBase.cpp index 8367497a9..f29b2c505 100644 --- a/es-app/src/views/GamelistBase.cpp +++ b/es-app/src/views/GamelistBase.cpp @@ -17,6 +17,7 @@ #include "FileFilterIndex.h" #include "UIModeController.h" #include "guis/GuiGamelistOptions.h" +#include "utils/LocalizationUtil.h" #include "views/ViewController.h" GamelistBase::GamelistBase(FileData* root) @@ -270,13 +271,14 @@ bool GamelistBase::input(InputConfig* config, Input input) mRoot->getSystem()->isGameSystem() && getCursor()->getType() != PLACEHOLDER && getCursor()->getParent()->getPath() == "collections") { NavigationSounds::getInstance().playThemeNavigationSound(FAVORITESOUND); - mWindow->queueInfoPopup("CAN'T ADD CUSTOM COLLECTIONS TO CUSTOM COLLECTIONS", 4000); + mWindow->queueInfoPopup(_("CAN'T ADD CUSTOM COLLECTIONS TO CUSTOM COLLECTIONS"), + 4000); } // Notify the user if attempting to add a placeholder to a custom collection. if (CollectionSystemsManager::getInstance()->isEditing() && mRoot->getSystem()->isGameSystem() && getCursor()->getType() == PLACEHOLDER) { NavigationSounds::getInstance().playThemeNavigationSound(FAVORITESOUND); - mWindow->queueInfoPopup("CAN'T ADD PLACEHOLDERS TO CUSTOM COLLECTIONS", 4000); + mWindow->queueInfoPopup(_("CAN'T ADD PLACEHOLDERS TO CUSTOM COLLECTIONS"), 4000); } else if (mRoot->getSystem()->isGameSystem() && getCursor()->getType() != PLACEHOLDER && getCursor()->getParent()->getPath() != "collections") { @@ -385,26 +387,28 @@ bool GamelistBase::input(InputConfig* config, Input input) // CollectionSystemsManager. if (entryToUpdate->getType() == FOLDER) { if (isEditing) { - mWindow->queueInfoPopup("CAN'T ADD FOLDERS TO CUSTOM COLLECTIONS", 4000); + mWindow->queueInfoPopup(_("CAN'T ADD FOLDERS TO CUSTOM COLLECTIONS"), 4000); } else { MetaDataList* md {&entryToUpdate->getSourceFileData()->metadata}; if (md->get("favorite") == "false") { md->set("favorite", "true"); mWindow->queueInfoPopup( - "MARKED FOLDER '" + - Utils::String::toUpper(Utils::String::removeParenthesis( - entryToUpdate->getName())) + - "' AS FAVORITE", + Utils::String::format( + _("MARKED FOLDER '%s' AS FAVORITE"), + Utils::String::toUpper( + Utils::String::removeParenthesis(entryToUpdate->getName())) + .c_str()), 4000); } else { md->set("favorite", "false"); mWindow->queueInfoPopup( - "REMOVED FAVORITE MARKING FOR FOLDER '" + - Utils::String::toUpper(Utils::String::removeParenthesis( - entryToUpdate->getName())) + - "'", + Utils::String::format( + _("REMOVED FAVORITE MARKING FOR FOLDER '%s'"), + Utils::String::toUpper( + Utils::String::removeParenthesis(entryToUpdate->getName())) + .c_str()), 4000); } } @@ -430,8 +434,8 @@ bool GamelistBase::input(InputConfig* config, Input input) return true; } else if (isEditing && entryToUpdate->metadata.get("nogamecount") == "true") { - mWindow->queueInfoPopup("CAN'T ADD ENTRIES THAT ARE NOT COUNTED " - "AS GAMES TO CUSTOM COLLECTIONS", + mWindow->queueInfoPopup(_("CAN'T ADD ENTRIES THAT ARE NOT COUNTED " + "AS GAMES TO CUSTOM COLLECTIONS"), 4000); } else if (CollectionSystemsManager::getInstance()->toggleGameInCollection( diff --git a/es-app/src/views/GamelistView.cpp b/es-app/src/views/GamelistView.cpp index 726507f3a..31b204b95 100644 --- a/es-app/src/views/GamelistView.cpp +++ b/es-app/src/views/GamelistView.cpp @@ -543,6 +543,8 @@ std::vector GamelistView::getHelpPrompts() (Settings::getInstance()->getBool("FavoritesAddButton") || CollectionSystemsManager::getInstance()->isEditing())) { std::string prompt {CollectionSystemsManager::getInstance()->getEditingCollection()}; + if (prompt == "Favorites") + prompt = _("Favorites"); if (prompt.length() > 24) prompt = prompt.substr(0, 22) + "..."; prompts.push_back(HelpPrompt("y", prompt));