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:
parent
5b74739c51
commit
610f189839
@ -124,6 +124,17 @@ namespace hex::plugin::builtin {
|
|||||||
return false;
|
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) {
|
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);
|
static int fps = static_cast<int>(setting);
|
||||||
|
|
||||||
|
@ -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() {
|
void drawWikiExplainer() {
|
||||||
static hex::Net net;
|
static hex::Net net;
|
||||||
|
|
||||||
@ -677,8 +682,6 @@ namespace hex::plugin::builtin {
|
|||||||
return s;
|
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);
|
ImGui::Header("hex.builtin.tools.wiki_explain.control"_lang, true);
|
||||||
|
|
||||||
bool startSearch;
|
bool startSearch;
|
||||||
@ -691,7 +694,7 @@ namespace hex::plugin::builtin {
|
|||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
if (startSearch && !searchString.empty()) {
|
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);
|
ImGui::Header("hex.builtin.tools.wiki_explain.results"_lang);
|
||||||
@ -716,7 +719,7 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
if (!extendedSearch && resultExtract.ends_with(':')) {
|
if (!extendedSearch && resultExtract.ends_with(':')) {
|
||||||
extendedSearch = true;
|
extendedSearch = true;
|
||||||
searchProcess = net.getString(WikipediaApiUrl + "&titles="s + net.encode(searchString));
|
searchProcess = net.getString(getWikipediaApiUrl() + "&titles="s + net.encode(searchString));
|
||||||
resultTitle.clear();
|
resultTitle.clear();
|
||||||
resultExtract.clear();
|
resultExtract.clear();
|
||||||
} else {
|
} else {
|
||||||
|
@ -666,6 +666,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
|
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
|
||||||
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
|
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
|
||||||
{ "hex.builtin.setting.interface.language", "Sprache" },
|
{ "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", "FPS Limite" },
|
||||||
{ "hex.builtin.setting.interface.fps.unlocked", "Unbegrenzt" },
|
{ "hex.builtin.setting.interface.fps.unlocked", "Unbegrenzt" },
|
||||||
{ "hex.builtin.setting.interface.highlight_alpha", "Markierungssichtbarkeit" },
|
{ "hex.builtin.setting.interface.highlight_alpha", "Markierungssichtbarkeit" },
|
||||||
|
@ -670,6 +670,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
|
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
|
||||||
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
|
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
|
||||||
{ "hex.builtin.setting.interface.language", "Language" },
|
{ "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", "FPS Limit" },
|
||||||
{ "hex.builtin.setting.interface.fps.unlocked", "Unlocked" },
|
{ "hex.builtin.setting.interface.fps.unlocked", "Unlocked" },
|
||||||
{ "hex.builtin.setting.interface.highlight_alpha", "Highlighting opacity" },
|
{ "hex.builtin.setting.interface.highlight_alpha", "Highlighting opacity" },
|
||||||
|
@ -662,6 +662,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.builtin.setting.interface.color.light", "Chiaro" },
|
{ "hex.builtin.setting.interface.color.light", "Chiaro" },
|
||||||
{ "hex.builtin.setting.interface.color.classic", "Classico" },
|
{ "hex.builtin.setting.interface.color.classic", "Classico" },
|
||||||
{ "hex.builtin.setting.interface.language", "Lingua" },
|
{ "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", "Scale" },
|
||||||
{ "hex.builtin.setting.interface.scaling.native", "Nativo" },
|
{ "hex.builtin.setting.interface.scaling.native", "Nativo" },
|
||||||
{ "hex.builtin.setting.interface.scaling.x0_5", "x0.5" },
|
{ "hex.builtin.setting.interface.scaling.x0_5", "x0.5" },
|
||||||
|
@ -668,6 +668,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
|
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
|
||||||
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
|
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
|
||||||
{ "hex.builtin.setting.interface.language", "言語" },
|
{ "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", "FPS制限" },
|
||||||
{ "hex.builtin.setting.interface.fps.unlocked", "無制限" },
|
{ "hex.builtin.setting.interface.fps.unlocked", "無制限" },
|
||||||
{ "hex.builtin.setting.interface.highlight_alpha", "ハイライトの不透明度" },
|
{ "hex.builtin.setting.interface.highlight_alpha", "ハイライトの不透明度" },
|
||||||
|
@ -662,6 +662,7 @@ namespace hex::plugin::builtin {
|
|||||||
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
|
{ "hex.builtin.setting.interface.scaling.x1_5", "x1.5" },
|
||||||
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
|
{ "hex.builtin.setting.interface.scaling.x2_0", "x2.0" },
|
||||||
{ "hex.builtin.setting.interface.language", "语言" },
|
{ "hex.builtin.setting.interface.language", "语言" },
|
||||||
|
{ "hex.builtin.setting.interface.wiki_explain_language", "维基百科语种" },
|
||||||
{ "hex.builtin.setting.interface.fps", "FPS限制" },
|
{ "hex.builtin.setting.interface.fps", "FPS限制" },
|
||||||
{ "hex.builtin.setting.interface.fps.unlocked", "无限制" },
|
{ "hex.builtin.setting.interface.fps.unlocked", "无限制" },
|
||||||
{ "hex.builtin.setting.interface.highlight_alpha", "高亮不透明度" },
|
{ "hex.builtin.setting.interface.highlight_alpha", "高亮不透明度" },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user