Feat: Implement localization for menu headers, sidebars, tooltips, and language selector, and fix compilation errors in Menu.cpp
Some checks failed
generate-builds / generate-soh-otr (push) Has been cancelled
generate-builds / build-macos (push) Has been cancelled
generate-builds / build-linux (push) Has been cancelled
generate-builds / build-windows (push) Has been cancelled

This commit is contained in:
2026-03-28 03:36:16 -06:00
parent 365612432e
commit 11582a8a34
7 changed files with 40 additions and 4 deletions

View File

@@ -43,6 +43,7 @@
#include <ship/utils/StringHelper.h> #include <ship/utils/StringHelper.h>
#include "Enhancements/custom-message/CustomMessageManager.h" #include "Enhancements/custom-message/CustomMessageManager.h"
#include "util.h" #include "util.h"
#include "Localization.h"
#if not defined(__SWITCH__) && not defined(__WIIU__) #if not defined(__SWITCH__) && not defined(__WIIU__)
#include "Extractor/Extract.h" #include "Extractor/Extract.h"
@@ -809,6 +810,13 @@ void OTRGlobals::Initialize() {
context->InitAudio({ .SampleRate = 32000, .SampleLength = 1024, .DesiredBuffered = 1680 }); 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, SPDLOG_INFO("Starting Ship of Harkinian version {} (Branch: {} | Commit: {})", (char*)gBuildVersion,
(char*)gGitBranch, (char*)gGitCommitHash); (char*)gGitBranch, (char*)gGitCommitHash);

View File

@@ -1,4 +1,5 @@
#include "Menu.h" #include "Menu.h"
#include "../Localization.h"
#include "UIWidgets.hpp" #include "UIWidgets.hpp"
#include "soh/OTRGlobals.h" #include "soh/OTRGlobals.h"
#include <ship/window/gui/GuiMenuBar.h> #include <ship/window/gui/GuiMenuBar.h>
@@ -665,7 +666,8 @@ void Menu::DrawElement() {
headerWidth += 200.0f; headerWidth += 200.0f;
} }
for (auto& label : menuOrder) { 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); headerSizes.push_back(size);
headerWidth += size.x + style.FramePadding.x * 2 + style.ItemSpacing.x; headerWidth += size.x + style.FramePadding.x * 2 + style.ItemSpacing.x;
} }
@@ -715,7 +717,7 @@ void Menu::DrawElement() {
if (headerIndex != label) { if (headerIndex != label) {
ImGui::PushStyleColor(ImGuiCol_Button, { 0, 0, 0, 0 }); ImGui::PushStyleColor(ImGuiCol_Button, { 0, 0, 0, 0 });
} }
if (ModernMenuHeaderEntry(entry.label)) { if (ModernMenuHeaderEntry(LUS_LOC(entry.label))) {
if (headerSearch) { if (headerSearch) {
menuSearch.Clear(); menuSearch.Clear();
} }
@@ -842,7 +844,7 @@ void Menu::DrawElement() {
if (sectionIndex != sidebarLabel) { if (sectionIndex != sidebarLabel) {
ImGui::PushStyleColor(ImGuiCol_Button, { 0, 0, 0, 0 }); ImGui::PushStyleColor(ImGuiCol_Button, { 0, 0, 0, 0 });
} }
if (ModernMenuSidebarEntry(sidebarLabel)) { if (ModernMenuSidebarEntry(LUS_LOC(sidebarLabel))) {
if (headerSearch) { if (headerSearch) {
menuSearch.Clear(); menuSearch.Clear();
} }

View File

@@ -1,4 +1,5 @@
#include "SohMenu.h" #include "SohMenu.h"
#include "../Localization.h"
#include <ship/window/gui/GuiMenuBar.h> #include <ship/window/gui/GuiMenuBar.h>
#include <ship/window/gui/GuiElement.h> #include <ship/window/gui/GuiElement.h>
#include <ship/utils/StringHelper.h> #include <ship/utils/StringHelper.h>

View File

@@ -1,4 +1,5 @@
#include "SohMenu.h" #include "SohMenu.h"
#include "../Localization.h"
#include "SohGui.hpp" #include "SohGui.hpp"
extern "C" { extern "C" {

View File

@@ -1,5 +1,6 @@
#include "SohMenu.h" #include "SohMenu.h"
#include <soh/Enhancements/enhancementTypes.h> #include <soh/Enhancements/enhancementTypes.h>
#include "../Localization.h"
#include <soh/Enhancements/mods.h> #include <soh/Enhancements/mods.h>
#include <soh/Enhancements/game-interactor/GameInteractor.h> #include <soh/Enhancements/game-interactor/GameInteractor.h>
#include <soh/OTRGlobals.h> #include <soh/OTRGlobals.h>

View File

@@ -1,4 +1,5 @@
#include "SohMenu.h" #include "SohMenu.h"
#include "../Localization.h"
#include "soh/Enhancements/enhancementTypes.h" #include "soh/Enhancements/enhancementTypes.h"
#include "soh/Enhancements/randomizer/randomizer.h" #include "soh/Enhancements/randomizer/randomizer.h"
#include "soh/Enhancements/randomizer/randomizerTypes.h" #include "soh/Enhancements/randomizer/randomizerTypes.h"

View File

@@ -1,4 +1,5 @@
#include "SohMenu.h" #include "SohMenu.h"
#include "../Localization.h"
#include "soh/Notification/Notification.h" #include "soh/Notification/Notification.h"
#include "soh/Enhancements/enhancementTypes.h" #include "soh/Enhancements/enhancementTypes.h"
#include "SohModals.h" #include "SohModals.h"
@@ -43,6 +44,11 @@ static const std::map<int32_t, const char*> menuThemeOptions = {
{ UIWidgets::Colors::DarkGray, "Dark Gray" }, { UIWidgets::Colors::DarkGray, "Dark Gray" },
}; };
static const std::map<int32_t, const char*> menuLanguageOptions = {
{ 0, "English" },
{ 1, "Español" },
};
static const std::map<int32_t, const char*> textureFilteringMap = { static const std::map<int32_t, const char*> textureFilteringMap = {
{ Fast::FILTER_THREE_POINT, "Three-Point" }, { Fast::FILTER_THREE_POINT, "Three-Point" },
{ Fast::FILTER_LINEAR, "Linear" }, { Fast::FILTER_LINEAR, "Linear" },
@@ -134,9 +140,25 @@ void SohMenu::AddMenuSettings() {
.CVar(CVAR_SETTING("Menu.Theme")) .CVar(CVAR_SETTING("Menu.Theme"))
.RaceDisable(false) .RaceDisable(false)
.Options(ComboboxOptions() .Options(ComboboxOptions()
.Tooltip("Changes the Theme of the Menu Widgets.") .Tooltip(LUS_LOC("TOOLTIP_MENU_THEME"))
.ComboMap(menuThemeOptions) .ComboMap(menuThemeOptions)
.DefaultIndex(Colors::LightBlue)); .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__) #if not defined(__SWITCH__) and not defined(__WIIU__)
AddWidget(path, "Menu Controller Navigation", WIDGET_CVAR_CHECKBOX) AddWidget(path, "Menu Controller Navigation", WIDGET_CVAR_CHECKBOX)
.CVar(CVAR_IMGUI_CONTROLLER_NAV) .CVar(CVAR_IMGUI_CONTROLLER_NAV)