feat: added language changing

This commit is contained in:
ADev531 2025-07-21 20:59:55 +09:00
commit 907de64376
6 changed files with 107 additions and 27 deletions

View file

@ -25,6 +25,7 @@
#include <wups.h>
#include <wups/storage.h>
#include <wups/config_api.h>
#include <wups/config/WUPSConfigItemMultipleValues.h>
#include <wups/config/WUPSConfigItemBoolean.h>
#include <wups/config/WUPSConfigItemStub.h>
@ -42,6 +43,8 @@ bool Config::connect_to_network = true;
bool Config::need_relaunch = false;
bool Config::unregister_task_item_pressed = false;
bool Config::is_wiiu_menu = false;
uint32_t Config::language = 13;
inkay_language Config::current_language = English;
static WUPSConfigAPICallbackStatus report_error(WUPSConfigAPIStatus err) {
DEBUG_FUNCTION_LINE_VERBOSE("WUPS config error: %s", WUPSConfigAPI_GetStatusStr(err));
@ -64,6 +67,21 @@ static void connect_to_network_changed(ConfigItemBoolean* item, bool new_value)
if (res != WUPS_STORAGE_ERROR_SUCCESS) return report_storage_error(res);
}
static void language_changed(ConfigItemMultipleValues* item, uint32_t new_value) {
DEBUG_FUNCTION_LINE_VERBOSE("language changed to: %d", new_value);
if (new_value != Config::language) {
if (new_value == inkay_language::System)
Config::current_language = (inkay_language)get_system_language();
else
Config::current_language = (inkay_language)new_value;
}
Config::language = new_value;
WUPSStorageError res;
res = WUPSStorageAPI::Store<int>("language", Config::language);
if (res != WUPS_STORAGE_ERROR_SUCCESS) return report_storage_error(res);
}
static void unregister_task_item_on_input_cb(void *context, WUPSConfigSimplePadData input) {
if (!Config::unregister_task_item_pressed && Config::is_wiiu_menu && ((input.buttons_d & WUPS_CONFIG_BUTTON_A) == WUPS_CONFIG_BUTTON_A)) {
@ -124,7 +142,7 @@ static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHa
Config::is_wiiu_menu = (current_title_id == wiiu_menu_tid);
// get translation strings
strings = get_config_strings(get_system_language());
strings = get_config_strings(Config::current_language);
// create root config category
WUPSConfigCategory root = WUPSConfigCategory(rootHandle);
@ -181,6 +199,29 @@ static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHa
err = WUPSConfigAPI_Category_AddItem(other_cat->getHandle(), unregisterTasksItem);
if (err != WUPSCONFIG_API_RESULT_SUCCESS) return report_error(err);
constexpr WUPSConfigItemMultipleValues::ValuePair languages[] = {
{0, "Japanese"},
{1, "English"},
{2, "French"},
{3, "German"},
{4, "Spanish"},
{5, "Italian"},
{6, "Simplified Chinese"},
{7, "Korean"},
{8, "Dutch"},
{9, "Portuguese"},
{10, "Russian"},
{11, "Traditional Chinese"},
{13, "System"},
{14, "English (UwU)"},
};
auto language_item = WUPSConfigItemMultipleValues::CreateFromValue("language", "Language", 13, Config::language, languages, &language_changed, err);
if (!language_item) return report_error(err);
res = other_cat->add(std::move(*language_item), err);
if (!res) report_error(err);
res = root.add(std::move(*other_cat), err);
if (!res) return report_error(err);
@ -228,6 +269,22 @@ void Config::Init() {
}
else if (res != WUPS_STORAGE_ERROR_SUCCESS) return report_storage_error(res);
res = WUPSStorageAPI::Get<uint32_t>("language", Config::language);
if (res == WUPS_STORAGE_ERROR_NOT_FOUND) {
DEBUG_FUNCTION_LINE("Language value not found, attempting to create");
// Add the value to the storage.
res = WUPSStorageAPI::Store<uint32_t>("language", Config::language);
if (res != WUPS_STORAGE_ERROR_SUCCESS) return report_storage_error(res);
}
else if (res != WUPS_STORAGE_ERROR_SUCCESS) return report_storage_error(res);
// Set the language that's currently used
if (Config::language == inkay_language::System)
Config::current_language = (inkay_language)get_system_language();
else
Config::current_language = (inkay_language)Config::language;
// Save storage
res = WUPSStorageAPI::SaveStorage();
if (res != WUPS_STORAGE_ERROR_SUCCESS) return report_storage_error(res);

View file

@ -5,12 +5,16 @@
#ifndef INKAY_CONFIG_H
#define INKAY_CONFIG_H
#include <stdint.h>
#include "lang.h"
class Config {
public:
static void Init();
// wups config items
static bool connect_to_network;
static uint32_t language;
// private stuff
static bool need_relaunch;
@ -18,6 +22,7 @@ public:
// private stuff
static bool is_wiiu_menu;
static inkay_language current_language;
static bool unregister_task_item_pressed;
};

View file

@ -18,22 +18,22 @@
#include "Notification.h"
#include "utils/logger.h"
#include "sysconfig.h"
#include "config.h"
#include "lang.h"
#include <coreinit/dynload.h>
static OSDynLoad_Module module;
static void (*moduleInitialize)(bool) = nullptr;
static void (*moduleInitialize)(bool, inkay_language) = nullptr;
static InkayStatus (*moduleGetStatus)() = nullptr;
static void (*moduleSetPluginRunning)() = nullptr;
static const char *get_module_not_found_message() {
return get_config_strings(get_system_language()).module_not_found.data();
return get_config_strings(Config::current_language).module_not_found.data();
}
static const char *get_module_init_not_found_message() {
return get_config_strings(get_system_language()).module_init_not_found.data();
return get_config_strings(Config::current_language).module_init_not_found.data();
}
void Inkay_Initialize(bool apply_patches) {
@ -54,7 +54,7 @@ void Inkay_Initialize(bool apply_patches) {
return;
}
moduleInitialize(apply_patches);
moduleInitialize(apply_patches, Config::current_language);
}
void Inkay_Finalize() {