mirror of
https://github.com/PretendoNetwork/Inkay.git
synced 2026-08-17 18:22:15 +02:00
feat: added language changing
This commit is contained in:
parent
979d9de91a
commit
907de64376
6 changed files with 107 additions and 27 deletions
|
|
@ -4,40 +4,40 @@
|
|||
|
||||
#include "lang.h"
|
||||
|
||||
config_strings get_config_strings(nn::swkbd::LanguageType language) {
|
||||
config_strings get_config_strings(inkay_language language) {
|
||||
switch (language) {
|
||||
case nn::swkbd::LanguageType::English:
|
||||
case inkay_language::English:
|
||||
default: return {
|
||||
#include "en_US.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::Spanish: return {
|
||||
case inkay_language::Spanish: return {
|
||||
#include "es_ES.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::French: return {
|
||||
case inkay_language::French: return {
|
||||
#include "fr_FR.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::Italian: return {
|
||||
case inkay_language::Italian: return {
|
||||
#include "it_IT.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::German: return {
|
||||
case inkay_language::German: return {
|
||||
#include "de_DE.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::SimplifiedChinese: return {
|
||||
case inkay_language::SimplifiedChinese: return {
|
||||
#include "zh_CN.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::TraditionalChinese: return {
|
||||
case inkay_language::TraditionalChinese: return {
|
||||
#include "zh_Hant.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::Portuguese: return {
|
||||
case inkay_language::Portuguese: return {
|
||||
#include "pt_BR.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::Japanese: return {
|
||||
case inkay_language::Japanese: return {
|
||||
#include "ja_JP.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::Dutch: return {
|
||||
case inkay_language::Dutch: return {
|
||||
#include "nl_NL.lang"
|
||||
};
|
||||
case nn::swkbd::LanguageType::Russian: return {
|
||||
case inkay_language::Russian: return {
|
||||
#include "ru_RU.lang"
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
#include <nn/swkbd.h>
|
||||
|
||||
enum inkay_language {
|
||||
Japanese = 0,
|
||||
English,
|
||||
French,
|
||||
German,
|
||||
Italian,
|
||||
Spanish,
|
||||
SimplifiedChinese,
|
||||
Korean,
|
||||
Dutch,
|
||||
Portuguese,
|
||||
Russian,
|
||||
TraditionalChinese,
|
||||
Invalid,
|
||||
// custom ones
|
||||
System,
|
||||
EnUwU,
|
||||
};
|
||||
|
||||
struct config_strings {
|
||||
const char *plugin_name;
|
||||
|
|
@ -19,4 +37,4 @@ struct config_strings {
|
|||
std::string_view module_init_not_found;
|
||||
};
|
||||
|
||||
config_strings get_config_strings(nn::swkbd::LanguageType language);
|
||||
config_strings get_config_strings(inkay_language language);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
14
src/main.cpp
14
src/main.cpp
|
|
@ -93,18 +93,18 @@ static bool is555(MCPSystemVersion version) {
|
|||
return (version.major == 5) && (version.minor == 5) && (version.patch >= 5);
|
||||
}
|
||||
|
||||
static const char *get_nintendo_network_message() {
|
||||
static const char *get_nintendo_network_message(inkay_language language) {
|
||||
// TL note: "Nintendo Network" is a proper noun - "Network" is part of the name
|
||||
// TL note: "Using" instead of "Connected" is deliberate - we don't know if a successful connection exists, we are
|
||||
// only specifying what we'll *attempt* to connect to
|
||||
return get_config_strings(get_system_language()).using_nintendo_network.data();
|
||||
return get_config_strings(language).using_nintendo_network.data();
|
||||
}
|
||||
|
||||
static const char *get_pretendo_message() {
|
||||
static const char *get_pretendo_message(inkay_language language) {
|
||||
// TL note: "Pretendo Network" is also a proper noun - though "Pretendo" alone can refer to us as a project
|
||||
// TL note: "Using" instead of "Connected" is deliberate - we don't know if a successful connection exists, we are
|
||||
// only specifying what we'll *attempt* to connect to
|
||||
return get_config_strings(get_system_language()).using_pretendo_network.data();
|
||||
return get_config_strings(language).using_pretendo_network.data();
|
||||
}
|
||||
|
||||
static void Inkay_SetPluginRunning() {
|
||||
|
|
@ -122,7 +122,7 @@ static InkayStatus Inkay_GetStatus() {
|
|||
}
|
||||
}
|
||||
|
||||
static void Inkay_Initialize(bool apply_patches) {
|
||||
static void Inkay_Initialize(bool apply_patches, inkay_language language) {
|
||||
if (Config::initialized)
|
||||
return;
|
||||
|
||||
|
|
@ -150,12 +150,12 @@ static void Inkay_Initialize(bool apply_patches) {
|
|||
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Pretendo URL and NoSSL patches applied successfully.");
|
||||
|
||||
ShowNotification(get_pretendo_message());
|
||||
ShowNotification(get_pretendo_message(language));
|
||||
Config::initialized = true;
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Pretendo URL and NoSSL patches skipped.");
|
||||
|
||||
ShowNotification(get_nintendo_network_message());
|
||||
ShowNotification(get_nintendo_network_message(language));
|
||||
Config::initialized = true;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue