From 11582a8a348e19e1719b3930ba044cd3802e3b02 Mon Sep 17 00:00:00 2001 From: nickpons666 Date: Sat, 28 Mar 2026 03:36:16 -0600 Subject: [PATCH] Feat: Implement localization for menu headers, sidebars, tooltips, and language selector, and fix compilation errors in Menu.cpp --- soh/soh/OTRGlobals.cpp | 8 ++++++++ soh/soh/SohGui/Menu.cpp | 8 +++++--- soh/soh/SohGui/SohMenu.cpp | 1 + soh/soh/SohGui/SohMenuDevTools.cpp | 1 + soh/soh/SohGui/SohMenuEnhancements.cpp | 1 + soh/soh/SohGui/SohMenuRandomizer.cpp | 1 + soh/soh/SohGui/SohMenuSettings.cpp | 24 +++++++++++++++++++++++- 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 7cd67c266..2f40c4881 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -43,6 +43,7 @@ #include #include "Enhancements/custom-message/CustomMessageManager.h" #include "util.h" +#include "Localization.h" #if not defined(__SWITCH__) && not defined(__WIIU__) #include "Extractor/Extract.h" @@ -809,6 +810,13 @@ void OTRGlobals::Initialize() { context->InitAudio({ .SampleRate = 32000, .SampleLength = 1024, .DesiredBuffered = 1680 }); + int32_t lang = CVarGetInteger("gSettings.Menu.Language", 0); + if (lang == 1) { + LUS::Localization::GetInstance()->LoadLanguage("es_ES"); + } else { + LUS::Localization::GetInstance()->LoadLanguage("en_US"); + } + SPDLOG_INFO("Starting Ship of Harkinian version {} (Branch: {} | Commit: {})", (char*)gBuildVersion, (char*)gGitBranch, (char*)gGitCommitHash); diff --git a/soh/soh/SohGui/Menu.cpp b/soh/soh/SohGui/Menu.cpp index 0147d75ab..ea017fd3d 100644 --- a/soh/soh/SohGui/Menu.cpp +++ b/soh/soh/SohGui/Menu.cpp @@ -1,4 +1,5 @@ #include "Menu.h" +#include "../Localization.h" #include "UIWidgets.hpp" #include "soh/OTRGlobals.h" #include @@ -665,7 +666,8 @@ void Menu::DrawElement() { headerWidth += 200.0f; } for (auto& label : menuOrder) { - ImVec2 size = ImGui::CalcTextSize(label.c_str()); + auto& entry = menuEntries.at(label); + ImVec2 size = ImGui::CalcTextSize(entry.label.c_str()); headerSizes.push_back(size); headerWidth += size.x + style.FramePadding.x * 2 + style.ItemSpacing.x; } @@ -715,7 +717,7 @@ void Menu::DrawElement() { if (headerIndex != label) { ImGui::PushStyleColor(ImGuiCol_Button, { 0, 0, 0, 0 }); } - if (ModernMenuHeaderEntry(entry.label)) { + if (ModernMenuHeaderEntry(LUS_LOC(entry.label))) { if (headerSearch) { menuSearch.Clear(); } @@ -842,7 +844,7 @@ void Menu::DrawElement() { if (sectionIndex != sidebarLabel) { ImGui::PushStyleColor(ImGuiCol_Button, { 0, 0, 0, 0 }); } - if (ModernMenuSidebarEntry(sidebarLabel)) { + if (ModernMenuSidebarEntry(LUS_LOC(sidebarLabel))) { if (headerSearch) { menuSearch.Clear(); } diff --git a/soh/soh/SohGui/SohMenu.cpp b/soh/soh/SohGui/SohMenu.cpp index 0e8ea5cf8..35b46fcf6 100644 --- a/soh/soh/SohGui/SohMenu.cpp +++ b/soh/soh/SohGui/SohMenu.cpp @@ -1,4 +1,5 @@ #include "SohMenu.h" +#include "../Localization.h" #include #include #include diff --git a/soh/soh/SohGui/SohMenuDevTools.cpp b/soh/soh/SohGui/SohMenuDevTools.cpp index c5b88ce8f..e82802c80 100644 --- a/soh/soh/SohGui/SohMenuDevTools.cpp +++ b/soh/soh/SohGui/SohMenuDevTools.cpp @@ -1,4 +1,5 @@ #include "SohMenu.h" +#include "../Localization.h" #include "SohGui.hpp" extern "C" { diff --git a/soh/soh/SohGui/SohMenuEnhancements.cpp b/soh/soh/SohGui/SohMenuEnhancements.cpp index 8e9a9059b..270634877 100644 --- a/soh/soh/SohGui/SohMenuEnhancements.cpp +++ b/soh/soh/SohGui/SohMenuEnhancements.cpp @@ -1,5 +1,6 @@ #include "SohMenu.h" #include +#include "../Localization.h" #include #include #include diff --git a/soh/soh/SohGui/SohMenuRandomizer.cpp b/soh/soh/SohGui/SohMenuRandomizer.cpp index b5b9ece98..bd7baa96d 100644 --- a/soh/soh/SohGui/SohMenuRandomizer.cpp +++ b/soh/soh/SohGui/SohMenuRandomizer.cpp @@ -1,4 +1,5 @@ #include "SohMenu.h" +#include "../Localization.h" #include "soh/Enhancements/enhancementTypes.h" #include "soh/Enhancements/randomizer/randomizer.h" #include "soh/Enhancements/randomizer/randomizerTypes.h" diff --git a/soh/soh/SohGui/SohMenuSettings.cpp b/soh/soh/SohGui/SohMenuSettings.cpp index b806da560..b9f66121f 100644 --- a/soh/soh/SohGui/SohMenuSettings.cpp +++ b/soh/soh/SohGui/SohMenuSettings.cpp @@ -1,4 +1,5 @@ #include "SohMenu.h" +#include "../Localization.h" #include "soh/Notification/Notification.h" #include "soh/Enhancements/enhancementTypes.h" #include "SohModals.h" @@ -43,6 +44,11 @@ static const std::map menuThemeOptions = { { UIWidgets::Colors::DarkGray, "Dark Gray" }, }; +static const std::map menuLanguageOptions = { + { 0, "English" }, + { 1, "Español" }, +}; + static const std::map textureFilteringMap = { { Fast::FILTER_THREE_POINT, "Three-Point" }, { Fast::FILTER_LINEAR, "Linear" }, @@ -134,9 +140,25 @@ void SohMenu::AddMenuSettings() { .CVar(CVAR_SETTING("Menu.Theme")) .RaceDisable(false) .Options(ComboboxOptions() - .Tooltip("Changes the Theme of the Menu Widgets.") + .Tooltip(LUS_LOC("TOOLTIP_MENU_THEME")) .ComboMap(menuThemeOptions) .DefaultIndex(Colors::LightBlue)); + + AddWidget(path, "Menu Language", WIDGET_CVAR_COMBOBOX) + .CVar("gSettings.Menu.Language") + .RaceDisable(false) + .Callback([](WidgetInfo& info) { + int32_t lang = CVarGetInteger("gSettings.Menu.Language", 0); + if (lang == 1) { + LUS::Localization::GetInstance()->LoadLanguage("es_ES"); + } else { + LUS::Localization::GetInstance()->LoadLanguage("en_US"); + } + }) + .Options(ComboboxOptions() + .Tooltip(LUS_LOC("TOOLTIP_MENU_LANGUAGE")) + .ComboMap(menuLanguageOptions) + .DefaultIndex(0)); #if not defined(__SWITCH__) and not defined(__WIIU__) AddWidget(path, "Menu Controller Navigation", WIDGET_CVAR_CHECKBOX) .CVar(CVAR_IMGUI_CONTROLLER_NAV)