mirror of
https://github.com/Syping/dtranslatebot.git
synced 2026-04-01 13:20:40 +02:00
bump version to 0.3.2 and minor changes
This commit is contained in:
parent
58028b6e82
commit
ec1294a960
7 changed files with 25 additions and 29 deletions
|
|
@ -22,7 +22,6 @@
|
|||
#include "deepl.h"
|
||||
using namespace bot::translator;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace std::string_literals;
|
||||
|
||||
deepl::deepl(const std::string &hostname, const std::string apiKey) :
|
||||
m_hostname(hostname), m_apiKey(apiKey)
|
||||
|
|
@ -44,7 +43,7 @@ const std::vector<language> deepl::get_languages()
|
|||
|
||||
try {
|
||||
http_request request;
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, 443, "/v2/languages?type=target"s, true), { {"Authorization"s, "DeepL-Auth-Key "s + m_apiKey} });
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, 443, "/v2/languages?type=target", true), { {"Authorization", "DeepL-Auth-Key " + m_apiKey} });
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_array()) {
|
||||
|
|
@ -84,20 +83,20 @@ const std::vector<language> deepl::get_languages()
|
|||
const std::string deepl::translate(const std::string &text, const std::string &source, const std::string &target)
|
||||
{
|
||||
const dpp::http_headers http_headers = {
|
||||
{"Authorization"s, "DeepL-Auth-Key " + m_apiKey},
|
||||
{"Content-Type"s, "application/json"s}
|
||||
{"Authorization", "DeepL-Auth-Key " + m_apiKey},
|
||||
{"Content-Type", "application/json"}
|
||||
};
|
||||
|
||||
dpp::json json_body = {
|
||||
{"text"s, { text } },
|
||||
{"target_lang"s, target}
|
||||
{"text", { text } },
|
||||
{"target_lang", target}
|
||||
};
|
||||
if (!source.empty())
|
||||
json_body["source_lang"] = source;
|
||||
|
||||
try {
|
||||
http_request request;
|
||||
http_response response = request.post(http_request::legacy_url(m_hostname, 443, "/v2/translate", true), json_body.dump(), "application/json", { {"Authorization"s, "DeepL-Auth-Key " + m_apiKey} });
|
||||
http_response response = request.post(http_request::legacy_url(m_hostname, 443, "/v2/translate", true), json_body.dump(), "application/json", { {"Authorization", "DeepL-Auth-Key " + m_apiKey} });
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_object()) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#include "libretranslate.h"
|
||||
using namespace bot::translator;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace std::string_literals;
|
||||
|
||||
libretranslate::libretranslate(const std::string &hostname, uint16_t port, const std::string &url, bool tls, const std::string apiKey) :
|
||||
m_hostname(hostname), m_port(port), m_url(url), m_tls(tls), m_apiKey(apiKey)
|
||||
|
|
@ -44,7 +43,7 @@ const std::vector<language> libretranslate::get_languages()
|
|||
|
||||
try {
|
||||
http_request request;
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "languages"s, m_tls));
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "languages", m_tls));
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_array()) {
|
||||
|
|
@ -79,14 +78,14 @@ const std::vector<language> libretranslate::get_languages()
|
|||
const std::string libretranslate::translate(const std::string &text, const std::string &source, const std::string &target)
|
||||
{
|
||||
const dpp::http_headers http_headers = {
|
||||
{"Content-Type"s, "application/json"s}
|
||||
{"Content-Type", "application/json"}
|
||||
};
|
||||
|
||||
dpp::json json_body = {
|
||||
{"q"s, text},
|
||||
{"source"s, source.empty() ? "auto"s : source},
|
||||
{"target"s, target},
|
||||
{"format"s, "text"s}
|
||||
{"q", text},
|
||||
{"source", source.empty() ? "auto" : source},
|
||||
{"target", target},
|
||||
{"format", "text"}
|
||||
};
|
||||
|
||||
if (!m_apiKey.empty())
|
||||
|
|
@ -94,7 +93,7 @@ const std::string libretranslate::translate(const std::string &text, const std::
|
|||
|
||||
try {
|
||||
http_request request;
|
||||
http_response response = request.post(http_request::legacy_url(m_hostname, m_port, m_url + "translate"s, m_tls), json_body.dump(), "application/json");
|
||||
http_response response = request.post(http_request::legacy_url(m_hostname, m_port, m_url + "translate", m_tls), json_body.dump(), "application/json");
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_object()) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#include "lingvatranslate.h"
|
||||
using namespace bot::translator;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace std::string_literals;
|
||||
|
||||
lingvatranslate::lingvatranslate(const std::string &hostname, uint16_t port, const std::string &url, bool tls) :
|
||||
m_hostname(hostname), m_port(port), m_url(url), m_tls(tls)
|
||||
|
|
@ -45,7 +44,7 @@ const std::vector<language> lingvatranslate::get_languages()
|
|||
|
||||
try {
|
||||
http_request request;
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/v1/languages/target"s, m_tls));
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/v1/languages/target", m_tls));
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_object()) {
|
||||
|
|
@ -84,7 +83,7 @@ const std::string lingvatranslate::translate(const std::string &text, const std:
|
|||
{
|
||||
try {
|
||||
http_request request;
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/v1/"s + (source.empty() ? "auto"s : source) + "/"s + target + "/"s + dpp::utility::url_encode(text), m_tls));
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/v1/" + (source.empty() ? "auto" : source) + "/" + target + "/" + dpp::utility::url_encode(text), m_tls));
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_object()) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#include "mozhi.h"
|
||||
using namespace bot::translator;
|
||||
using namespace std::chrono_literals;
|
||||
using namespace std::string_literals;
|
||||
|
||||
mozhi::mozhi(const std::string &hostname, uint16_t port, const std::string &url, bool tls, const std::string &engine) :
|
||||
m_hostname(hostname), m_port(port), m_url(url), m_tls(tls), m_engine(engine)
|
||||
|
|
@ -45,10 +44,10 @@ const std::vector<language> mozhi::get_languages()
|
|||
|
||||
try {
|
||||
const std::string parameters = dpp::utility::make_url_parameters({
|
||||
{"engine"s, m_engine}
|
||||
{"engine", m_engine}
|
||||
});
|
||||
http_request request;
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/target_languages"s, m_tls));
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/target_languages", m_tls));
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_array()) {
|
||||
|
|
@ -84,13 +83,13 @@ const std::string mozhi::translate(const std::string &text, const std::string &s
|
|||
{
|
||||
try {
|
||||
const std::string parameters = dpp::utility::make_url_parameters({
|
||||
{"engine"s, m_engine},
|
||||
{"from"s, source.empty() ? "auto"s : source},
|
||||
{"to"s, target},
|
||||
{"text"s, text}
|
||||
{"engine", m_engine},
|
||||
{"from", source.empty() ? "auto" : source},
|
||||
{"to", target},
|
||||
{"text", text}
|
||||
});
|
||||
http_request request;
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/translate"s + parameters, m_tls));
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, m_port, m_url + "api/translate" + parameters, m_tls));
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_object()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue