1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-08 19:41:49 +00:00
AIO-switch-updater/source/lang.cpp

115 lines
2.7 KiB
C++
Raw Normal View History

#include <switch.h>
2020-10-05 16:14:10 +01:00
#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 !
2020-10-05 16:14:10 +01:00
case Language::French:
path = "romfs:/lang/fr.json";
break;
2020-10-05 16:14:10 +01:00
/*
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;
}
2020-10-05 16:14:10 +01:00
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 !
2020-10-05 16:14:10 +01:00
case SetLanguage_FR:
return set_language(Language::French);
2020-10-05 16:14:10 +01:00
/*
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