feat(i18n): add ui localization (#2279)

Co-authored-by: TheElixZammuto <6505622+TheElixZammuto@users.noreply.github.com>
This commit is contained in:
ReenigneArcher
2024-03-22 19:54:12 -04:00
committed by GitHub
parent 8316f44e10
commit 87774333f3
29 changed files with 4446 additions and 719 deletions

View File

@@ -441,6 +441,7 @@ namespace config {
};
sunshine_t sunshine {
"en", // locale
2, // min_log_level
0, // flags
{}, // User file
@@ -1101,6 +1102,19 @@ namespace config {
config::sunshine.flags[config::flag::UPNP].flip();
}
string_restricted_f(vars, "locale", config::sunshine.locale, {
"de"sv, // German
"en"sv, // English
"en-GB"sv, // English (UK)
"en-US"sv, // English (US)
"es"sv, // Spanish
"fr"sv, // French
"it"sv, // Italian
"ru"sv, // Russian
"sv"sv, // Swedish
"zh"sv, // Chinese
});
std::string log_level_string;
string_f(vars, "min_log_level", log_level_string);

View File

@@ -160,6 +160,7 @@ namespace config {
bool elevated;
};
struct sunshine_t {
std::string locale;
int min_log_level;
std::bitset<flag::FLAG_SIZE> flags;
std::string credentials_file;

View File

@@ -550,6 +550,24 @@ namespace confighttp {
}
}
void
getLocale(resp_https_t response, req_https_t request) {
// we need to return the locale whether authenticated or not
print_req(request);
pt::ptree outputTree;
auto g = util::fail_guard([&]() {
std::ostringstream data;
pt::write_json(data, outputTree);
response->write(data.str());
});
outputTree.put("status", "true");
outputTree.put("locale", config::sunshine.locale);
}
void
saveConfig(resp_https_t response, req_https_t request) {
if (!authenticate(response, request)) return;
@@ -743,6 +761,7 @@ namespace confighttp {
server.resource["^/api/apps$"]["POST"] = saveApp;
server.resource["^/api/config$"]["GET"] = getConfig;
server.resource["^/api/config$"]["POST"] = saveConfig;
server.resource["^/api/configLocale$"]["GET"] = getLocale;
server.resource["^/api/restart$"]["POST"] = restart;
server.resource["^/api/password$"]["POST"] = savePassword;
server.resource["^/api/apps/([0-9]+)$"]["DELETE"] = deleteApp;