add:添加已翻译过内容直接取值功能。
This commit is contained in:
parent
ffc92d6a1f
commit
a793406ab7
22
.vscode/settings.json
vendored
22
.vscode/settings.json
vendored
@ -107,6 +107,26 @@
|
|||||||
"span": "cpp",
|
"span": "cpp",
|
||||||
"valarray": "cpp",
|
"valarray": "cpp",
|
||||||
"variant": "cpp",
|
"variant": "cpp",
|
||||||
"xstring": "cpp"
|
"xstring": "cpp",
|
||||||
|
"chrono": "cpp",
|
||||||
|
"filesystem": "cpp",
|
||||||
|
"ios": "cpp",
|
||||||
|
"locale": "cpp",
|
||||||
|
"xfacet": "cpp",
|
||||||
|
"xhash": "cpp",
|
||||||
|
"xiosbase": "cpp",
|
||||||
|
"xlocale": "cpp",
|
||||||
|
"xlocbuf": "cpp",
|
||||||
|
"xlocinfo": "cpp",
|
||||||
|
"xlocmes": "cpp",
|
||||||
|
"xlocmon": "cpp",
|
||||||
|
"xlocnum": "cpp",
|
||||||
|
"xloctime": "cpp",
|
||||||
|
"xmemory": "cpp",
|
||||||
|
"xmemory0": "cpp",
|
||||||
|
"xstddef": "cpp",
|
||||||
|
"xtr1common": "cpp",
|
||||||
|
"xtree": "cpp",
|
||||||
|
"xutility": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <SimpleIni.h>
|
#include <SimpleIni.h>
|
||||||
|
#include <cctype>
|
||||||
|
|
||||||
CHttpsHandle::CHttpsHandle()
|
CHttpsHandle::CHttpsHandle()
|
||||||
{
|
{
|
||||||
|
17
main.cpp
17
main.cpp
@ -3,8 +3,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <xlnt/xlnt.hpp>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <xlnt/xlnt.hpp>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
// #include <filesystem>
|
// #include <filesystem>
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
@ -59,6 +60,7 @@ int main(int argc, char* argv[])
|
|||||||
auto trans_tool = std::make_shared<CTransTool>();
|
auto trans_tool = std::make_shared<CTransTool>();
|
||||||
trans_tool->set_id(base_info.appID, base_info.secretID);
|
trans_tool->set_id(base_info.appID, base_info.secretID);
|
||||||
|
|
||||||
|
std::unordered_map<std::string, std::string> word_map;
|
||||||
auto trans = [&](const std::string& words, std::string& out) -> bool {
|
auto trans = [&](const std::string& words, std::string& out) -> bool {
|
||||||
std::string request_url = base_info.baseUrl + trans_tool->combine(words, "auto", "en");
|
std::string request_url = base_info.baseUrl + trans_tool->combine(words, "auto", "en");
|
||||||
std::string response = https->sendGetRequest(request_url);
|
std::string response = https->sendGetRequest(request_url);
|
||||||
@ -81,13 +83,22 @@ int main(int argc, char* argv[])
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::string ret;
|
std::string ret;
|
||||||
std::cout << "翻译:" << line << std::endl;
|
|
||||||
|
if (word_map.count(line)) {
|
||||||
|
ret = word_map[line];
|
||||||
|
vec.emplace_back(TResult{line, ret});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!trans(line, ret)) {
|
if (!trans(line, ret)) {
|
||||||
vec.emplace_back(TResult{line, "Failed"});
|
vec.emplace_back(TResult{line, "Failed"});
|
||||||
|
word_map[line] = "Failed";
|
||||||
} else {
|
} else {
|
||||||
vec.emplace_back(TResult{line, ret});
|
vec.emplace_back(TResult{line, ret});
|
||||||
|
word_map[line] = ret;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::cout << "翻译:" << line << ", 结果:" << ret << std::endl;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user