Added localization support to parts of the application

This commit is contained in:
Leon Styhre 2024-07-17 14:14:59 +02:00
parent 085b3da8e0
commit 35f51e6904
9 changed files with 78 additions and 54 deletions

View file

@ -10,6 +10,7 @@
#include "Sound.h"
#include "components/VideoFFmpegComponent.h"
#include "utils/LocalizationUtil.h"
#include "views/ViewController.h"
#define KEY_REPEAT_START_DELAY 600
@ -79,7 +80,7 @@ bool MediaViewer::startMediaViewer(FileData* game)
mEntryCount = std::to_string(mImages.size() + (mVideo == nullptr ? 0 : 1));
mMediaType =
std::make_unique<TextComponent>((mHasVideo ? "VIDEO" : mImageFiles[0].second.mediaType),
std::make_unique<TextComponent>((mHasVideo ? _("VIDEO") : mImageFiles[0].second.mediaType),
Font::get(FONT_SIZE_MINI, FONT_PATH_REGULAR), 0xAAAAAAFF);
mMediaType->setOrigin(0.0f, 0.5f);
@ -246,11 +247,11 @@ void MediaViewer::render(const glm::mat4& /*parentTrans*/)
std::vector<HelpPrompt> MediaViewer::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("left/right", "browse"));
prompts.push_back(HelpPrompt("left/right", _("browse")));
if (mHasManual)
prompts.push_back(HelpPrompt("up", "pdf manual"));
prompts.push_back(HelpPrompt("lt", "first"));
prompts.push_back(HelpPrompt("rt", "last"));
prompts.push_back(HelpPrompt("up", _("pdf manual")));
prompts.push_back(HelpPrompt("lt", _("first")));
prompts.push_back(HelpPrompt("rt", _("last")));
return prompts;
}
@ -280,34 +281,34 @@ void MediaViewer::findMedia()
}
if (!mHasVideo && (mediaFile = mGame->getScreenshotPath()) != "") {
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo("SCREENSHOT", false)));
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo(_("SCREENSHOT"), false)));
mScreenshotIndex = 0;
}
if ((mediaFile = mGame->getCoverPath()) != "")
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo("BOX COVER", true)));
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo(_("BOX COVER"), true)));
if ((mediaFile = mGame->getBackCoverPath()) != "")
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo("BOX BACK COVER", true)));
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo(_("BOX BACK COVER"), true)));
if ((mediaFile = mGame->getTitleScreenPath()) != "") {
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo("TITLE SCREEN", false)));
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo(_("TITLE SCREEN"), false)));
mTitleScreenIndex = static_cast<int>(mImageFiles.size() - 1);
}
if (mHasVideo && (mediaFile = mGame->getScreenshotPath()) != "") {
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo("SCREENSHOT", false)));
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo(_("SCREENSHOT"), false)));
mScreenshotIndex = static_cast<int>(mImageFiles.size() - 1);
}
if ((mediaFile = mGame->getFanArtPath()) != "")
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo("FAN ART", true)));
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo(_("FAN ART"), true)));
if ((mediaFile = mGame->getMiximagePath()) != "")
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo("MIXIMAGE", true)));
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo(_("MIXIMAGE"), true)));
if ((mediaFile = mGame->getCustomImagePath()) != "")
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo("CUSTOM", true)));
mImageFiles.push_back(std::make_pair(mediaFile, ImageInfo(_("CUSTOM"), true)));
if (!mImageFiles.empty())
mHasImages = true;
@ -406,7 +407,7 @@ void MediaViewer::showPrevious()
}
else if (mCurrentImageIndex == 0 && mHasVideo) {
mDisplayingImage = false;
mMediaType->setText("VIDEO");
mMediaType->setText(_("VIDEO"));
playVideo();
return;
}
@ -425,7 +426,8 @@ void MediaViewer::showFirst()
return;
mCurrentImageIndex = 0;
mMediaType->setText((mHasVideo ? "VIDEO" : mImageFiles[mCurrentImageIndex].second.mediaType));
mMediaType->setText(
(mHasVideo ? _("VIDEO") : mImageFiles[mCurrentImageIndex].second.mediaType));
if (mHasVideo) {
mDisplayingImage = false;

View file

@ -46,7 +46,7 @@ void MiximageGenerator::startThread(std::promise<bool>* miximagePromise)
if ((mScreenshotPath = mGame->getScreenshotPath()) == "") {
LOG(LogDebug) << "MiximageGenerator::MiximageGenerator(): "
"No screenshot image found, aborting";
mResultMessage = _("No screenshot image found, couldn't generate miximage");
mResultMessage = _("No screenshot found, couldn't generate miximage");
mMiximagePromise->set_value(true);
return;
}
@ -137,7 +137,7 @@ bool MiximageGenerator::generateImage()
if (fileFormat == FIF_UNKNOWN) {
LOG(LogError) << "Screenshot image in unknown image format, aborting";
mMessage = "Screenshot image in unknown format, couldn't generate miximage";
mMessage = _("Screenshot in unknown format, couldn't generate miximage");
return true;
}
@ -152,13 +152,13 @@ bool MiximageGenerator::generateImage()
}
else {
LOG(LogError) << "Screenshot file format not supported";
mMessage = "Screenshot image in unsupported format, couldn't generate miximage";
mMessage = _("Screenshot in unsupported format, couldn't generate miximage");
return true;
}
if (!screenshotFile) {
LOG(LogError) << "Error loading screenshot image, corrupt file?";
mMessage = "Error loading screenshot image, couldn't generate miximage";
mMessage = _("Error loading screenshot, couldn't generate miximage");
return true;
}
@ -196,7 +196,7 @@ bool MiximageGenerator::generateImage()
#endif
if (!marqueeFile) {
LOG(LogError) << "Couldn't load marquee image, corrupt file?";
mMessage = "Error loading marquee image, corrupt file?";
mMessage = _("Error loading marquee image, corrupt file?");
mMarquee = false;
}
}
@ -235,7 +235,7 @@ bool MiximageGenerator::generateImage()
#endif
if (!boxFile) {
LOG(LogError) << "Couldn't load 3D box image, corrupt file?";
mMessage = "Error loading 3d box image, corrupt file?";
mMessage = _("Error loading 3d box image, corrupt file?");
mBox3D = false;
}
}
@ -273,7 +273,7 @@ bool MiximageGenerator::generateImage()
#endif
if (!boxFile) {
LOG(LogError) << "Couldn't load box cover image, corrupt file?";
mMessage = "Error loading box cover image, corrupt file?";
mMessage = _("Error loading box cover image, corrupt file?");
mCover = false;
}
}
@ -313,7 +313,7 @@ bool MiximageGenerator::generateImage()
#endif
if (!physicalMediaFile) {
LOG(LogError) << "Couldn't load physical media image, corrupt file?";
mMessage = "Error loading physical media image, corrupt file?";
mMessage = _("Error loading physical media image, corrupt file?");
mPhysicalMedia = false;
}
}

View file

@ -11,6 +11,7 @@
#include "Log.h"
#include "Sound.h"
#include "utils/FileSystemUtil.h"
#include "utils/LocalizationUtil.h"
#include "utils/StringUtil.h"
#include "views/ViewController.h"
@ -185,7 +186,8 @@ bool PDFViewer::startPDFViewer(FileData* game)
mEntryCount = std::to_string(mPages.size());
mEntryNumText = std::make_unique<TextComponent>(
"PAGE 1 OF " + mEntryCount, Font::get(FONT_SIZE_MINI, FONT_PATH_REGULAR), 0xAAAAAAFF);
Utils::String::format(_("PAGE %s OF %s"), "1", mEntryCount.c_str()),
Font::get(FONT_SIZE_MINI, FONT_PATH_REGULAR), 0xAAAAAAFF);
mEntryNumText->setOrigin(0.0f, 0.5f);
if (mHelpInfoPosition == HelpInfoPosition::TOP) {
@ -706,17 +708,17 @@ std::vector<HelpPrompt> PDFViewer::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
if (mZoom > 1.0f) {
prompts.push_back(HelpPrompt("up/down/left/right", "pan"));
prompts.push_back(HelpPrompt("ltrt", "reset"));
prompts.push_back(HelpPrompt("up/down/left/right", _("pan")));
prompts.push_back(HelpPrompt("ltrt", _("reset")));
}
else {
prompts.push_back(HelpPrompt("left/right", "browse"));
prompts.push_back(HelpPrompt("down", "game media"));
prompts.push_back(HelpPrompt("lt", "first"));
prompts.push_back(HelpPrompt("rt", "last"));
prompts.push_back(HelpPrompt("left/right", _("browse")));
prompts.push_back(HelpPrompt("down", _("game media")));
prompts.push_back(HelpPrompt("lt", _("first")));
prompts.push_back(HelpPrompt("rt", _("last")));
}
prompts.push_back(HelpPrompt("lr", "zoom"));
prompts.push_back(HelpPrompt("lr", _("zoom")));
return prompts;
}
@ -728,7 +730,8 @@ void PDFViewer::showNextPage()
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
++mCurrentPage;
mEntryNumText->setText("PAGE " + std::to_string(mCurrentPage) + " OF " + mEntryCount);
mEntryNumText->setText(Utils::String::format(
_("PAGE %s OF %s"), std::to_string(mCurrentPage).c_str(), mEntryCount.c_str()));
convertPage(mCurrentPage);
}
@ -739,7 +742,8 @@ void PDFViewer::showPreviousPage()
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
--mCurrentPage;
mEntryNumText->setText("PAGE " + std::to_string(mCurrentPage) + " OF " + mEntryCount);
mEntryNumText->setText(Utils::String::format(
_("PAGE %s OF %s"), std::to_string(mCurrentPage).c_str(), mEntryCount.c_str()));
convertPage(mCurrentPage);
}
@ -828,7 +832,8 @@ void PDFViewer::navigateLeftTrigger()
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
mCurrentPage = 1;
mEntryNumText->setText("PAGE " + std::to_string(mCurrentPage) + " OF " + mEntryCount);
mEntryNumText->setText(Utils::String::format(
_("PAGE %s OF %s"), std::to_string(mCurrentPage).c_str(), mEntryCount.c_str()));
convertPage(mCurrentPage);
}
@ -849,6 +854,7 @@ void PDFViewer::navigateRightTrigger()
NavigationSounds::getInstance().playThemeNavigationSound(SCROLLSOUND);
mCurrentPage = mPageCount;
mEntryNumText->setText("PAGE " + std::to_string(mCurrentPage) + " OF " + mEntryCount);
mEntryNumText->setText(Utils::String::format(
_("PAGE %s OF %s"), std::to_string(mCurrentPage).c_str(), mEntryCount.c_str()));
convertPage(mCurrentPage);
}

View file

@ -12,6 +12,7 @@
#include "SystemData.h"
#include "components/ComponentGrid.h"
#include "components/TextComponent.h"
#include "utils/LocalizationUtil.h"
#include "utils/StringUtil.h"
GuiLaunchScreen::GuiLaunchScreen()
@ -54,7 +55,7 @@ void GuiLaunchScreen::displayLaunchScreen(FileData* game)
// Title.
mTitle = std::make_shared<TextComponent>(
"LAUNCHING GAME",
_("LAUNCHING GAME"),
Font::get(titleFontSize *
std::min(Renderer::getScreenHeight(), Renderer::getScreenWidth())),
mMenuColorTertiary, ALIGN_CENTER);

View file

@ -952,7 +952,7 @@ void GuiScraperSearch::updateThumbnail()
}
else {
mResultThumbnail->setImage("");
onSearchError("Error downloading thumbnail:\n " + it->second->getErrorMsg(), true,
onSearchError(_("Error downloading thumbnail:") + " \n" + it->second->getErrorMsg(), true,
(mSearchHandle != nullptr ? mSearchHandle->getFatalError() : false),
it->second->status());
}

View file

@ -16,6 +16,7 @@
#include "ScreenScraper.h"
#include "Settings.h"
#include "SystemData.h"
#include "utils/LocalizationUtil.h"
#include "utils/StringUtil.h"
#if defined(_WIN64)
@ -178,7 +179,7 @@ void ScraperHttpRequest::update()
// Everything else is some sort of error.
LOG(LogError) << "ScraperHttpRequest network error (status: " << status << ") - "
<< mReq->getErrorMsg();
setError("Network error: " + mReq->getErrorMsg(), true);
setError(_("Network error:") + " " + mReq->getErrorMsg(), true);
}
// Download and write the media files to disk.
@ -325,8 +326,8 @@ MDResolveHandle::MDResolveHandle(const ScraperSearchResult& result,
// If the media directory does not exist, something is wrong, possibly permission
// problems or the MediaDirectory setting points to a file instead of a directory.
if (!Utils::FileSystem::isDirectory(Utils::FileSystem::getParent(filePath))) {
setError("Media directory does not exist and can't be created. "
"Permission problems?",
setError(_("Media directory does not exist and can't be created.") + " \n" +
_("Permission problems?"),
false);
LOG(LogError) << "Couldn't create media directory: \""
<< Utils::FileSystem::getParent(filePath) << "\"";
@ -340,7 +341,9 @@ MDResolveHandle::MDResolveHandle(const ScraperSearchResult& result,
std::ofstream stream(filePath, std::ios_base::out | std::ios_base::binary);
#endif
if (!stream || stream.bad()) {
setError("Failed to open path for writing media file\nPermission error?", false);
setError(_("Failed to open path for writing media file.") + " \n" +
_("Permission problems?"),
false);
return;
}
@ -348,14 +351,17 @@ MDResolveHandle::MDResolveHandle(const ScraperSearchResult& result,
stream.write(content.data(), content.length());
stream.close();
if (stream.bad()) {
setError("Failed to save media file\nDisk full?", false);
setError(_("Couldn't save media file, permission problems or is the disk full?"),
false);
return;
}
// Resize it.
if (it->resizeFile) {
if (!resizeImage(filePath, it->subDirectory)) {
setError("Error saving resized image\nOut of memory? Disk full?", false);
setError(
_("Couldn't save resized image, permission problems or is the disk full?"),
false);
return;
}
}
@ -429,7 +435,7 @@ void MediaDownloadHandle::update()
if (mReq->status() != HttpReq::REQ_SUCCESS) {
std::stringstream ss;
ss << "Network error: " << mReq->getErrorMsg();
ss << _("Network error:") << " " << mReq->getErrorMsg();
setError(ss.str(), true);
return;
}
@ -524,7 +530,8 @@ void MediaDownloadHandle::update()
// If the media directory does not exist, something is wrong, possibly permission
// problems or the MediaDirectory setting points to a file instead of a directory.
if (!Utils::FileSystem::isDirectory(Utils::FileSystem::getParent(mSavePath))) {
setError("Media directory does not exist and can't be created. Permission problems?",
setError(_("Media directory does not exist and can't be created.") + " \n" +
_("Permission problems?"),
false);
LOG(LogError) << "Couldn't create media directory: \""
<< Utils::FileSystem::getParent(mSavePath) << "\"";
@ -538,7 +545,9 @@ void MediaDownloadHandle::update()
std::ofstream stream(mSavePath, std::ios_base::out | std::ios_base::binary);
#endif
if (!stream || stream.bad()) {
setError("Failed to open path for writing media file\nPermission error?", false);
setError(_("Failed to open path for writing media file.") + " \n" +
_("Permission problems?"),
false);
return;
}
@ -546,7 +555,7 @@ void MediaDownloadHandle::update()
stream.write(content.data(), content.length());
stream.close();
if (stream.bad()) {
setError("Failed to save media file\nDisk full?", false);
setError(_("Couldn't save media file, permission problems or is the disk full?"), false);
return;
}
@ -570,7 +579,8 @@ void MediaDownloadHandle::update()
// Resize it.
if (mResizeFile) {
if (!resizeImage(mSavePath, mMediaType)) {
setError("Error saving resized image\nOut of memory? Disk full?", false);
setError(_("Couldn't save resized image, permission problems or is the disk full?"),
false);
return;
}
}

View file

@ -14,6 +14,7 @@
#include "PlatformId.h"
#include "Settings.h"
#include "SystemData.h"
#include "utils/LocalizationUtil.h"
#include "utils/StringUtil.h"
#include "utils/TimeUtil.h"
@ -291,7 +292,7 @@ void ScreenScraperRequest::process(const std::unique_ptr<HttpReq>& req,
std::string content {req->getContent()};
if (content.length() > maxErrorLength)
content = content.substr(0, maxErrorLength) + "...";
setError("ScreenScraper error: \n" + content, true);
setError(_("ScreenScraper error:") + " \n" + content, true);
return;
}
@ -357,7 +358,7 @@ void ScreenScraperRequest::processGame(const pugi::xml_document& xmldoc,
<< Settings::getInstance()->getString("ScraperUsernameScreenScraper")
<< "\", wrong username or password?";
setError("ScreenScraper: Wrong username or password", false, true);
setError(_("ScreenScraper: Wrong username or password"), false, true);
return;
}
}

View file

@ -14,6 +14,8 @@
#include "Settings.h"
#include "resources/ResourceManager.h"
#include "utils/FileSystemUtil.h"
#include "utils/LocalizationUtil.h"
#include "utils/StringUtil.h"
#include <algorithm>
#include <assert.h>
@ -398,7 +400,7 @@ void HttpReq::pollCurl()
if (responseCode == 430 &&
Settings::getInstance()->getString("Scraper") == "screenscraper") {
req->mContent << "You have exceeded your daily scrape quota";
req->mContent << _("You have exceeded your daily scrape quota");
req->mStatus = REQ_SUCCESS;
}
else if (responseCode == 404 && req->mScraperRequest &&
@ -407,8 +409,9 @@ void HttpReq::pollCurl()
}
else {
req->mStatus = REQ_BAD_STATUS_CODE;
req->onError("Server returned HTTP error code " +
std::to_string(responseCode));
req->onError(
Utils::String::format(_("Server returned HTTP error code %s"),
std::to_string(responseCode).c_str()));
}
}
else {

View file

@ -13,6 +13,7 @@
#include "GuiComponent.h"
#include "components/ComponentGrid.h"
#include "components/NinePatchComponent.h"
#include "utils/LocalizationUtil.h"
class ButtonComponent;
class TextComponent;
@ -22,7 +23,7 @@ class GuiMsgBox : public GuiComponent
public:
GuiMsgBox(const HelpStyle& helpstyle,
const std::string& text,
const std::string& name1 = "OK",
const std::string& name1 = _("OK"),
const std::function<void()>& func1 = nullptr,
const std::string& name2 = "",
const std::function<void()>& func2 = nullptr,