mirror of
https://github.com/HamletDuFromage/aio-switch-updater.git
synced 2024-11-08 11:31:43 +00:00
114 lines
2.7 KiB
C++
114 lines
2.7 KiB
C++
#include <switch.h>
|
|
#include "json.hpp"
|
|
#include "lang.hpp"
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
namespace lang {
|
|
|
|
namespace {
|
|
|
|
static json lang_json = nullptr;
|
|
static Language current_language = Language::Default;
|
|
|
|
} // namespace
|
|
|
|
const json &get_json() {
|
|
return lang_json;
|
|
}
|
|
|
|
Language get_current_language() {
|
|
return current_language;
|
|
}
|
|
|
|
Result set_language(Language lang) {
|
|
const char *path;
|
|
current_language = lang;
|
|
switch (lang) {
|
|
case Language::Chinese:
|
|
path = "romfs:/lang/ch.json";
|
|
break;
|
|
//if you need add a new language
|
|
//use it !
|
|
case Language::French:
|
|
path = "romfs:/lang/fr.json";
|
|
break;
|
|
/*
|
|
case Language::Dutch:
|
|
path = "romfs:/lang/nl.json";
|
|
break;
|
|
case Language::Italian:
|
|
path = "romfs:/lang/it.json";
|
|
break;
|
|
case Language::German:
|
|
path = "romfs:/lang/de.json";
|
|
break;
|
|
case Language::Spanish:
|
|
path = "romfs:/lang/es.json";
|
|
break;*/
|
|
case Language::English:
|
|
case Language::Default:
|
|
default:
|
|
path = "romfs:/lang/en.json";
|
|
break;
|
|
}
|
|
|
|
std::fstream langFile;
|
|
if(std::filesystem::exists(path)){
|
|
langFile.open(path, std::fstream::in);
|
|
langFile >> lang_json;
|
|
langFile.close();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
Result initialize_to_system_language() {
|
|
if (auto rc = setInitialize(); R_FAILED(rc)) {
|
|
setExit();
|
|
return rc;
|
|
}
|
|
|
|
u64 l;
|
|
if (auto rc = setGetSystemLanguage(&l); R_FAILED(rc)) {
|
|
setExit();
|
|
return rc;
|
|
}
|
|
|
|
SetLanguage sl;
|
|
if (auto rc = setMakeLanguage(l, &sl); R_FAILED(rc)) {
|
|
setExit();
|
|
return rc;
|
|
}
|
|
|
|
switch (sl) {
|
|
case SetLanguage_ENGB:
|
|
case SetLanguage_ENUS:
|
|
return set_language(Language::English);
|
|
case SetLanguage_ZHCN:
|
|
case SetLanguage_ZHHANS:
|
|
return set_language(Language::Chinese);
|
|
//if you need add a new language
|
|
//use it !
|
|
case SetLanguage_FR:
|
|
return set_language(Language::French);
|
|
/*
|
|
case SetLanguage_NL:
|
|
return set_language(Language::Dutch);
|
|
case SetLanguage_IT:
|
|
return set_language(Language::Italian);
|
|
case SetLanguage_DE:
|
|
return set_language(Language::German);
|
|
case SetLanguage_ES:
|
|
return set_language(Language::Spanish);*/
|
|
default:
|
|
return set_language(Language::Default);
|
|
}
|
|
}
|
|
|
|
std::string get_string(std::string key, const json &json) {
|
|
return json.value(key, key);
|
|
}
|
|
|
|
} // namespace lang
|