From d637b13441dd30c71e07506499139c8ae809b729 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 16 Jun 2024 01:32:45 +0000 Subject: [PATCH] add translation support & replace sha w/ commit msg --- CMakeLists.txt | 2 +- readme.md | 1 - resources/i18n/en-US/app.json | 64 +++++++++++++++++ resources/xml/activity/main.xml | 72 +------------------ resources/xml/views/download_view.xml | 2 +- resources/xml/views/empty_message.xml | 4 +- resources/xml/views/icon_part_select.xml | 4 +- resources/xml/views/icon_part_select_grid.xml | 2 +- resources/xml/views/main_view.xml | 23 +++--- resources/xml/views/settings.xml | 26 ++----- source/util/download.cpp | 4 +- source/util/extract.cpp | 4 +- source/view/download_view.cpp | 12 ++-- source/view/main_view.cpp | 12 ++-- source/view/settings_view.cpp | 30 ++++---- 15 files changed, 122 insertions(+), 140 deletions(-) create mode 100644 resources/i18n/en-US/app.json diff --git a/CMakeLists.txt b/CMakeLists.txt index bfceb07..bde43ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ include(${BOREALIS_LIBRARY}/cmake/toolchain.cmake) # project info project(nso-icon-tool) set(VERSION_MAJOR "0") -set(VERSION_MINOR "1") +set(VERSION_MINOR "2") set(VERSION_ALTER "0") set(VERSION_BUILD "0") set(PROJECT_AUTHOR "dslatt") diff --git a/readme.md b/readme.md index fb14267..1e64602 100644 --- a/readme.md +++ b/readme.md @@ -111,7 +111,6 @@ If you want to help me open an issue when you encounter a bug and a pull request ## TODO -- Add translation support. - Bugfixes. I'm sure there's some. - Add some notification that an icon cache update is available on startup. Consider adding more details/clarity to the update process as well. diff --git a/resources/i18n/en-US/app.json b/resources/i18n/en-US/app.json new file mode 100644 index 0000000..4dba6ce --- /dev/null +++ b/resources/i18n/en-US/app.json @@ -0,0 +1,64 @@ +{ + "title": "nso-icon-tool", + "main": { + "change_user": "Change User", + "config": "Config", + "settings": "Settings", + "icon_components": "Icon Components", + "custom": "Custom", + "custom_image": "Custom Image", + "frame": "Select Frame", + "character": "Select Character", + "background": "Select Background", + "new_icon": "New Icon", + "apply": "Apply to User", + "select_game": "Select a Game", + "available_images": "Available Images" + }, + "settings": { + "title": "Settings", + "icon_cache": { + "label": "Icon Cache Update", + "yes": "Icon Cache Found", + "no": "No Icon Cache Found", + "last_checked": "Last Checked: {}", + "current_version": "Current Version: {} ({})", + "check_updates": "Check for Updates", + "update_available": "Update Available: {} ({})", + "download_update": "Download/Apply Update", + "never": "Never", + "none": "None" + }, + "toggles": { + "label": "Settings", + "debug": "Debug Layer", + "overwrite": "Overwrite Existing Files During Update" + }, + "version": { + "label": "Version", + "version": "Version: {}", + "author": "Author: {}", + "commit": "Commit: {} ", + "commit_clean": "clean", + "commit_dirty": "dirty", + "commit_date": "Commit Date: {}" + }, + "thanks_label": "Thanks", + "thanks": "▼ Thanks to nadrino for cpp-generic-toolbox library\n▼ Thanks to Natinusala, xfangfang and XITRIX for borealis library\n▼ Thanks to HamletDuFromage (AIO-Switch-Updater) and PoloNX (SimpleModDownloader)\n▼ Special thanks to henry-debruin for creating nso-icons." + }, + "download": { + "title": "Downloading and Extracting Icons...", + "downloading": "Downloading:", + "waiting": "Waiting:", + "downloaded": "Downloaded:", + "extracting": "Extracting:", + "extracted": "Extracted:", + "back": "Back" + }, + "errors": { + "insufficient_storage": "Insufficient Storage on SD Card", + "nothing": "Nothing Here!", + "nothing_icon_cache": "Nothing here! Check settings to download Icon Cache.", + "nothing_images": "Nothing here! Did you place images into \"{}\"?" + } +} \ No newline at end of file diff --git a/resources/xml/activity/main.xml b/resources/xml/activity/main.xml index fea06f3..7efb597 100644 --- a/resources/xml/activity/main.xml +++ b/resources/xml/activity/main.xml @@ -3,78 +3,8 @@ footerHidden="false"> - - - - \ No newline at end of file diff --git a/resources/xml/views/download_view.xml b/resources/xml/views/download_view.xml index 66fa4eb..f0f976c 100644 --- a/resources/xml/views/download_view.xml +++ b/resources/xml/views/download_view.xml @@ -1,7 +1,7 @@ diff --git a/resources/xml/views/empty_message.xml b/resources/xml/views/empty_message.xml index ddfede9..236a336 100644 --- a/resources/xml/views/empty_message.xml +++ b/resources/xml/views/empty_message.xml @@ -1,7 +1,7 @@ diff --git a/resources/xml/views/icon_part_select.xml b/resources/xml/views/icon_part_select.xml index 0b10570..16c2895 100644 --- a/resources/xml/views/icon_part_select.xml +++ b/resources/xml/views/icon_part_select.xml @@ -1,7 +1,7 @@ @@ -33,7 +33,7 @@ diff --git a/resources/xml/views/icon_part_select_grid.xml b/resources/xml/views/icon_part_select_grid.xml index be0aafc..900ff76 100644 --- a/resources/xml/views/icon_part_select_grid.xml +++ b/resources/xml/views/icon_part_select_grid.xml @@ -31,7 +31,7 @@ diff --git a/resources/xml/views/main_view.xml b/resources/xml/views/main_view.xml index 90dd7c2..0d6b0ce 100644 --- a/resources/xml/views/main_view.xml +++ b/resources/xml/views/main_view.xml @@ -20,7 +20,6 @@ @@ -38,15 +37,15 @@ + title="@i18n/app/main/config" /> @@ -62,27 +61,27 @@ + title="@i18n/app/main/icon_components" /> + title="@i18n/app/main/custom" /> @@ -97,7 +96,7 @@ @@ -115,7 +114,7 @@ width="75%" height="auto" style="primary" - text="Apply to User" + text="@i18n/app/main/apply" marginTop="20px" /> diff --git a/resources/xml/views/settings.xml b/resources/xml/views/settings.xml index f4b6f9d..e32e0f6 100644 --- a/resources/xml/views/settings.xml +++ b/resources/xml/views/settings.xml @@ -1,6 +1,6 @@ @@ -111,24 +107,14 @@ - - diff --git a/source/util/download.cpp b/source/util/download.cpp index d215e16..c9c0548 100644 --- a/source/util/download.cpp +++ b/source/util/download.cpp @@ -16,6 +16,8 @@ #include #include +using namespace brls::literals; // for _i18n + constexpr const char API_AGENT[] = "nso-icons"; constexpr int _1MiB = 0x100000; @@ -217,7 +219,7 @@ namespace download fclose(chunk.out); if (!can_download) { - brls::Application::crash("menus/errors/insufficient_storage"); + brls::Application::crash("app/errors/insufficient_storage"_i18n); std::this_thread::sleep_for(std::chrono::microseconds(2000000)); brls::Application::quit(); res = {}; diff --git a/source/util/extract.cpp b/source/util/extract.cpp index 9308d81..8f1cd79 100644 --- a/source/util/extract.cpp +++ b/source/util/extract.cpp @@ -13,6 +13,8 @@ #include "util/progress_event.hpp" +using namespace brls::literals; // for _i18n + constexpr size_t WRITE_BUFFER_SIZE = 0x10000; namespace extract @@ -53,7 +55,7 @@ namespace extract brls::Logger::info("Uncompressed size of archive {}: {}. Available: {}", archivePath, uncompressedSize, freeStorage); if (uncompressedSize * 1.1 > freeStorage) { - brls::Application::crash("menus/errors/insufficient_storage"); + brls::Application::crash("app/errors/insufficient_storage"_i18n); std::this_thread::sleep_for(std::chrono::microseconds(2000000)); brls::Application::quit(); } diff --git a/source/view/download_view.cpp b/source/view/download_view.cpp index c9048cb..a9f7d82 100644 --- a/source/view/download_view.cpp +++ b/source/view/download_view.cpp @@ -67,8 +67,8 @@ void DownloadView::updateProgress() brls::sync([ASYNC_TOKEN]() { ASYNC_RELEASE - download_status->setText("Downloading:"); - extract_status->setText("Waiting:"); }); + download_status->setText("app/download/downloading"_i18n); + extract_status->setText("app/download/waiting"_i18n); }); while (ProgressEvent::instance().getTotal() == 0) { @@ -94,8 +94,8 @@ void DownloadView::updateProgress() brls::sync([ASYNC_TOKEN]() { ASYNC_RELEASE - download_status->setText("Downloaded:"); - extract_status->setText("Extracting:"); }); + download_status->setText("app/download/downloaded"_i18n); + extract_status->setText("app/download/extracting"_i18n); }); while (ProgressEvent::instance().getMax() == 0) { if (extractFinished) @@ -122,7 +122,7 @@ void DownloadView::updateProgress() this->status_spinner->setVisibility(brls::Visibility::INVISIBLE); this->status_current->setText(""); this->status_percent->setText(""); - extract_status->setText("Extracted:"); }); + extract_status->setText("app/download/extracted"_i18n); }); } } // CLEANUP @@ -136,7 +136,7 @@ void DownloadView::updateProgress() { ASYNC_RELEASE auto button = new brls::Button(); - button->setText("Back"); + button->setText("app/download/back"_i18n); button->setFocusable(true); button->registerClickAction(brls::ActionListener([this](brls::View* view) { this->dismiss(); diff --git a/source/view/main_view.cpp b/source/view/main_view.cpp index 35326ba..6cb797d 100644 --- a/source/view/main_view.cpp +++ b/source/view/main_view.cpp @@ -12,6 +12,8 @@ #include "GenericToolbox.Switch.h" #include "extern/json.hpp" +using namespace brls::literals; + std::vector getCategories(std::string subcategory) { std::vector res; @@ -96,7 +98,7 @@ MainView::MainView() image->setImageFromMemRGBA(imageState.working.img, imageState.working.x, imageState.working.y); }, [](std::string path, ImageState& state){ state.updateFrame(path); - }) : new EmptyMessage("Nothing here! Check settings to download Icon Cache."); + }) : new EmptyMessage("app/errors/nothing_icon_cache"_i18n); this->present(select); return true; }); @@ -113,7 +115,7 @@ MainView::MainView() image->setImageFromMemRGBA(imageState.working.img, imageState.working.x, imageState.working.y); }, [](std::string path, ImageState& state){ state.updateCharacter(path); - }) : new EmptyMessage("Nothing here! Check settings to download Icon Cache."); + }) : new EmptyMessage("app/errors/nothing_icon_cache"_i18n); this->present(select); return true; }); @@ -130,7 +132,7 @@ MainView::MainView() image->setImageFromMemRGBA(imageState.working.img, imageState.working.x, imageState.working.y); }, [](std::string path, ImageState& state){ state.updateBackground(path); - }) : new EmptyMessage("Nothing here! Check settings to download Icon Cache."); + }) : new EmptyMessage("app/errors/nothing_icon_cache"_i18n); this->present(select); return true; }); @@ -151,13 +153,13 @@ MainView::MainView() for (auto file : files) { brls::Logger::debug("{}", file); } - auto select = files.size() ? (brls::View*)new grid::IconPartSelectGrid(files, "Available Images", tempState, [this](std::string path) { + auto select = files.size() ? (brls::View*)new grid::IconPartSelectGrid(files, "app/main/available_images"_i18n, tempState, [this](std::string path) { brls::Logger::info("Recieved {} from selection.", path); imageState.updateWorking(path); image->setImageFromMemRGBA(imageState.working.img, imageState.working.x, imageState.working.y); }, [](std::string path, ImageState &state){ state.updateWorking(path); - }) : new EmptyMessage(fmt::format("Nothing here! Did you place images into \"{}\"?", paths::BasePath)); + }) : new EmptyMessage(fmt::format("app/errors/nothing_images"_i18n, paths::BasePath)); this->present(select); return true; }); diff --git a/source/view/settings_view.cpp b/source/view/settings_view.cpp index eadedf8..6415e19 100644 --- a/source/view/settings_view.cpp +++ b/source/view/settings_view.cpp @@ -36,24 +36,24 @@ using namespace brls::literals; // for _i18n void SettingsView::updateUI() { - appVersion->setText(fmt::format("Version: {}", version::AppVersion)); - appAuthor->setText(fmt::format("Author: {}", version::AppAuthor)); - gitSha->setText(fmt::format("Commit: {} ({})", version::GitHeadSHA1, version::GitDirty ? "dirty" : "clean")); - gitDate->setText(fmt::format("Commit Date: {}", version::GitCommitDate)); + appVersion->setText(fmt::format("app/settings/version/version"_i18n, version::AppVersion)); + appAuthor->setText(fmt::format("app/settings/version/author"_i18n, version::AppAuthor)); + gitSha->setText(fmt::format("app/settings/version/commit"_i18n, version::GitHeadSHA1, version::GitDirty ? "app/settings/version/commit_dirty"_i18n : "app/settings/version/commit_clean"_i18n)); + gitDate->setText(fmt::format("app/settings/version/commit_date"_i18n, version::GitCommitDate)); - cacheText->setText(GenericToolbox::doesPathIsFolder(paths::IconCachePath) ? "Icon Cache Found" : "No Icon Cache Found"); - checkText->setText(fmt::format("Last Checked: {}", cacheData.count("checkTime") ? cacheData["checkTime"] : "Never")); + cacheText->setText(GenericToolbox::isDir(paths::IconCachePath) ? "app/settings/icon_cache/yes"_i18n : "app/settings/icon_cache/no"_i18n); + checkText->setText(fmt::format("app/settings/icon_cache/last_checked"_i18n, cacheData.count("checkTime") ? cacheData["checkTime"] : "app/settings/icon_cache/never"_i18n)); if (updateState == UpdateState::CHECK) { - updateText->setText(fmt::format("Current Version: {} (sha {})", - cacheData.count("updateDate") ? cacheData["updateDate"] : "None", - cacheData.count("updateSha") ? cacheData["updateSha"] : "None")); - updateButton->setText("Check for Updates"); + updateText->setText(fmt::format("app/settings/icon_cache/current_version"_i18n, + cacheData.count("updateDate") ? cacheData["updateDate"] : "app/settings/icon_cache/none"_i18n, + cacheData.count("updateMessage") ? cacheData["updateMessage"] : "app/settings/icon_cache/none"_i18n)); + updateButton->setText("app/settings/icon_cache/check_updates"_i18n); } else if (updateState == UpdateState::UPDATE) { - updateText->setText(fmt::format("Update Available: {} (sha {})", data["updateDate"], data["updateSha"])); - updateButton->setText("Download/Apply Update"); + updateText->setText(fmt::format("app/settings/icon_cache/update_available"_i18n, data["updateDate"], data["updateMessage"])); + updateButton->setText("app/settings/icon_cache/download_update"_i18n); } } @@ -64,14 +64,14 @@ SettingsView::SettingsView(SettingsData &settings) : settings(settings) checkSpinner->setVisibility(brls::Visibility::INVISIBLE); - debug->init("Debug Layer", brls::Application::isDebuggingViewEnabled(), [](bool value) + debug->init("app/settings/toggles/debug"_i18n, brls::Application::isDebuggingViewEnabled(), [](bool value) { brls::Application::enableDebuggingView(value); brls::sync([value](){ brls::Logger::info("{} the debug layer", value ? "Open" : "Close"); }); }); - extract_overwrite->init("Overwrite Existing Files During Update", settings.overwriteDuringExtract, [&settings](bool value) + extract_overwrite->init("app/settings/toggles/overwrite"_i18n, settings.overwriteDuringExtract, [&settings](bool value) { settings.overwriteDuringExtract = value; brls::sync([value]() { @@ -110,8 +110,6 @@ SettingsView::SettingsView(SettingsData &settings) : settings(settings) if (!cacheData.count("updateSha") || (!GenericToolbox::isDir(paths::IconCachePath) || GenericToolbox::isDirEmpty(paths::IconCachePath)) || data["updateSha"] != cacheData["updateSha"]) { brls::Logger::info("Update available: sha {}, date {}", data["updateSha"], data["updateDate"]); - updateText->setText("Update Available"); - updateButton->setText("Download/Apply Update"); updateState = UpdateState::UPDATE; }