From c7340d02bbb49d251afc4b2dd7695725f44b6a66 Mon Sep 17 00:00:00 2001 From: LinuxCat <46047705+L-i-n-u-x-C-a-t@users.noreply.github.com> Date: Tue, 21 Jul 2020 05:19:24 +0200 Subject: [PATCH] Set system language to the app on first launch (#42) * add language on first launch * add language on first launch Editing the hpp aswell --- include/utils/config.hpp | 3 ++- source/utils/config.cpp | 52 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/include/utils/config.hpp b/include/utils/config.hpp index 823485d..aec97d9 100644 --- a/include/utils/config.hpp +++ b/include/utils/config.hpp @@ -38,6 +38,7 @@ public: void save(); void initialize(); void addMissingThings(); + void sysLang(); // Bar Color. u32 barColor() { return this->v_barColor; } @@ -157,4 +158,4 @@ private: std::string v_3dsx_install_path, v_nds_install_path, v_archive_path; }; -#endif \ No newline at end of file +#endif diff --git a/source/utils/config.cpp b/source/utils/config.cpp index d62effd..cc5b56e 100644 --- a/source/utils/config.cpp +++ b/source/utils/config.cpp @@ -40,6 +40,52 @@ void Config::addMissingThings() { } } +//Detects system language and is used later to set app language to system language +void Config::sysLang() { + u8 language = 0; + + CFGU_GetSystemLanguage(&language); + switch(language) { + case 0: + this->language("jp"); + break; + case 1: + this->language("en"); + break; + case 2: + this->language("fr"); + break; + case 3: + this->language("de"); + break; + case 4: + this->language("it"); + break; + case 5: + this->language("es"); + break; + case 6: + this->language("en"); //Simplified chinese, not translated + break; + case 7: + this->language("en"); //Korean, not translated + break; + case 8: + this->language("nl"); + break; + case 9: + this->language("pt"); + break; + case 10: + this->language("ru"); + break; + case 11: + this->language("en"); //traditional chinese, not translated + break; + } +} + + // In case it doesn't exist. void Config::initialize() { // Create through fopen "Write". @@ -70,7 +116,7 @@ void Config::initialize() { this->setInt("KEY_DELAY", 5); this->setBool("SCREEN_FADE", false); this->setBool("PROGRESS_DISPLAY", true); - this->setString("LANGUAGE", "en"); + this->sysLang(); this->setBool("FIRST_STARTUP", true); this->setBool("USE_SCRIPT_COLORS", true); this->setBool("SHOW_SPEED", false); @@ -250,7 +296,7 @@ Config::Config() { } if (!this->json.contains("LANGUAGE") || this->json.at("LANGUAGE").is_number()) { - this->language("en"); + this->sysLang(); this->initialChanges = true; } else { this->language(this->getString("LANGUAGE")); @@ -378,4 +424,4 @@ std::string Config::getString(const std::string &key) { } void Config::setString(const std::string &key, const std::string &v) { this->json[key] = v; -} \ No newline at end of file +}