1
0
mirror of synced 2024-11-25 08:10:24 +01:00

feat(wiki): Support custom language for Wikipedia (#505)

* sys: support typeless settings

* feat(wiki): support custom language for Wikipedia

* update
This commit is contained in:
xtexChooser 2022-05-23 05:26:46 +08:00 committed by GitHub
parent 5b74739c51
commit 610f189839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 4 deletions

View File

@ -124,6 +124,17 @@ namespace hex::plugin::builtin {
return false;
});
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.wiki_explain_language", "en", [](auto name, nlohmann::json &setting) {
static auto lang = std::string(setting);
if (ImGui::InputText(name.data(), lang, ImGuiInputTextFlags_CharsNoBlank)) {
setting = std::string(lang.c_str()); // remove following zero bytes
return true;
}
return false;
});
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.fps", 60, [](auto name, nlohmann::json &setting) {
static int fps = static_cast<int>(setting);

View File

@ -662,6 +662,11 @@ namespace hex::plugin::builtin {
}
}
std::string getWikipediaApiUrl() {
auto setting = ContentRegistry::Settings::getSetting("hex.builtin.setting.interface", "hex.builtin.setting.interface.wiki_explain_language");
return "https://" + std::string(setting) + ".wikipedia.org/w/api.php?format=json&action=query&prop=extracts&explaintext&redirects=10&formatversion=2";
}
void drawWikiExplainer() {
static hex::Net net;
@ -677,8 +682,6 @@ namespace hex::plugin::builtin {
return s;
}();
constexpr static auto WikipediaApiUrl = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&explaintext&redirects=10&formatversion=2";
ImGui::Header("hex.builtin.tools.wiki_explain.control"_lang, true);
bool startSearch;
@ -691,7 +694,7 @@ namespace hex::plugin::builtin {
ImGui::EndDisabled();
if (startSearch && !searchString.empty()) {
searchProcess = net.getString(WikipediaApiUrl + "&exintro"s + "&titles="s + net.encode(searchString));
searchProcess = net.getString(getWikipediaApiUrl() + "&exintro"s + "&titles="s + net.encode(searchString));
}
ImGui::Header("hex.builtin.tools.wiki_explain.results"_lang);
@ -716,7 +719,7 @@ namespace hex::plugin::builtin {
if (!extendedSearch && resultExtract.ends_with(':')) {
extendedSearch = true;
searchProcess = net.getString(WikipediaApiUrl + "&titles="s + net.encode(searchString));
searchProcess = net.getString(getWikipediaApiUrl() + "&titles="s + net.encode(searchString));
resultTitle.clear();
resultExtract.clear();
} else {

View File

@ -666,6 +666,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
{ "hex.builtin.setting.interface.language", "Sprache" },
//{ "hex.builtin.setting.interface.wiki_explain_language", "Wikipedia Language" },
{ "hex.builtin.setting.interface.fps", "FPS Limite" },
{ "hex.builtin.setting.interface.fps.unlocked", "Unbegrenzt" },
{ "hex.builtin.setting.interface.highlight_alpha", "Markierungssichtbarkeit" },

View File

@ -670,6 +670,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
{ "hex.builtin.setting.interface.language", "Language" },
{ "hex.builtin.setting.interface.wiki_explain_language", "Wikipedia Language" },
{ "hex.builtin.setting.interface.fps", "FPS Limit" },
{ "hex.builtin.setting.interface.fps.unlocked", "Unlocked" },
{ "hex.builtin.setting.interface.highlight_alpha", "Highlighting opacity" },

View File

@ -662,6 +662,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.interface.color.light", "Chiaro" },
{ "hex.builtin.setting.interface.color.classic", "Classico" },
{ "hex.builtin.setting.interface.language", "Lingua" },
//{ "hex.builtin.setting.interface.wiki_explain_language", "Wikipedia Language" },
{ "hex.builtin.setting.interface.scaling", "Scale" },
{ "hex.builtin.setting.interface.scaling.native", "Nativo" },
{ "hex.builtin.setting.interface.scaling.x0_5", "x0.5" },

View File

@ -668,6 +668,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
{ "hex.builtin.setting.interface.language", "言語" },
//{ "hex.builtin.setting.interface.wiki_explain_language", "Wikipedia Language" },
{ "hex.builtin.setting.interface.fps", "FPS制限" },
{ "hex.builtin.setting.interface.fps.unlocked", "無制限" },
{ "hex.builtin.setting.interface.highlight_alpha", "ハイライトの不透明度" },

View File

@ -662,6 +662,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
{ "hex.builtin.setting.interface.language", "语言" },
{ "hex.builtin.setting.interface.wiki_explain_language", "维基百科语种" },
{ "hex.builtin.setting.interface.fps", "FPS限制" },
{ "hex.builtin.setting.interface.fps.unlocked", "无限制" },
{ "hex.builtin.setting.interface.highlight_alpha", "高亮不透明度" },