mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 08:54:12 +08:00
dont need that param anymore
This commit is contained in:
parent
e20a12862c
commit
a129394fb5
@ -83,7 +83,7 @@ QStringList languages
|
|||||||
bool translateSelectedOnly = false, rateLimitAll = true, rateLimitSelected = false, useCache = true;
|
bool translateSelectedOnly = false, rateLimitAll = true, rateLimitSelected = false, useCache = true;
|
||||||
int tokenCount = 30, tokenRestoreDelay = 60000, maxSentenceSize = 500;
|
int tokenCount = 30, tokenRestoreDelay = 60000, maxSentenceSize = 500;
|
||||||
|
|
||||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, SentenceInfo)
|
std::pair<bool, std::wstring> Translate(const std::wstring& text)
|
||||||
{
|
{
|
||||||
if (!apiKey->empty())
|
if (!apiKey->empty())
|
||||||
if (HttpRequest httpRequest{
|
if (HttpRequest httpRequest{
|
||||||
|
@ -25,13 +25,13 @@ QStringList languages
|
|||||||
"Spanish: ES",
|
"Spanish: ES",
|
||||||
};
|
};
|
||||||
|
|
||||||
bool translateSelectedOnly = true, rateLimitAll = true, rateLimitSelected = true, useCache = false;
|
bool translateSelectedOnly = true, rateLimitAll = true, rateLimitSelected = true, useCache = true;
|
||||||
int tokenCount = 10, tokenRestoreDelay = 60000, maxSentenceSize = 500;
|
int tokenCount = 10, tokenRestoreDelay = 60000, maxSentenceSize = 500;
|
||||||
|
|
||||||
const wchar_t* accept[] = { L"*/*", nullptr };
|
const wchar_t* accept[] = { L"*/*", nullptr };
|
||||||
Synchronized<std::wstring> LMTBID;
|
Synchronized<std::wstring> LMTBID;
|
||||||
|
|
||||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, SentenceInfo sentenceInfo)
|
std::pair<bool, std::wstring> Translate(const std::wstring& text)
|
||||||
{
|
{
|
||||||
if (!apiKey->empty())
|
if (!apiKey->empty())
|
||||||
if (HttpRequest httpRequest{
|
if (HttpRequest httpRequest{
|
||||||
|
@ -156,7 +156,7 @@ bool IsHash(const std::wstring& result)
|
|||||||
return result.size() == 32 && std::all_of(result.begin(), result.end(), [](char ch) { return (ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'z'); });
|
return result.size() == 32 && std::all_of(result.begin(), result.end(), [](char ch) { return (ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'z'); });
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, SentenceInfo)
|
std::pair<bool, std::wstring> Translate(const std::wstring& text)
|
||||||
{
|
{
|
||||||
if (!apiKey->empty())
|
if (!apiKey->empty())
|
||||||
if (HttpRequest httpRequest{
|
if (HttpRequest httpRequest{
|
||||||
|
@ -23,7 +23,7 @@ extern const char* GET_API_KEY_FROM;
|
|||||||
extern QStringList languages;
|
extern QStringList languages;
|
||||||
extern bool translateSelectedOnly, rateLimitAll, rateLimitSelected, useCache;
|
extern bool translateSelectedOnly, rateLimitAll, rateLimitSelected, useCache;
|
||||||
extern int tokenCount, tokenRestoreDelay, maxSentenceSize;
|
extern int tokenCount, tokenRestoreDelay, maxSentenceSize;
|
||||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, SentenceInfo sentenceInfo);
|
std::pair<bool, std::wstring> Translate(const std::wstring& text);
|
||||||
|
|
||||||
const char* LANGUAGE = u8"Language";
|
const char* LANGUAGE = u8"Language";
|
||||||
const std::string TRANSLATION_CACHE_FILE = FormatString("%s Cache.txt", TRANSLATION_PROVIDER);
|
const std::string TRANSLATION_CACHE_FILE = FormatString("%s Cache.txt", TRANSLATION_PROVIDER);
|
||||||
@ -154,7 +154,7 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
|||||||
if (auto it = translationCache->find(sentence); it != translationCache->end()) translation = it->second + L"\x200b"; // dumb hack to not try to translate if stored empty translation
|
if (auto it = translationCache->find(sentence); it != translationCache->end()) translation = it->second + L"\x200b"; // dumb hack to not try to translate if stored empty translation
|
||||||
}
|
}
|
||||||
if (translation.empty() && (!translateSelectedOnly || sentenceInfo["current select"]))
|
if (translation.empty() && (!translateSelectedOnly || sentenceInfo["current select"]))
|
||||||
if (rateLimiter.Request() || !rateLimitAll || (!rateLimitSelected && sentenceInfo["current select"])) std::tie(cache, translation) = Translate(sentence, sentenceInfo);
|
if (rateLimiter.Request() || !rateLimitAll || (!rateLimitSelected && sentenceInfo["current select"])) std::tie(cache, translation) = Translate(sentence);
|
||||||
else translation = TOO_MANY_TRANS_REQUESTS;
|
else translation = TOO_MANY_TRANS_REQUESTS;
|
||||||
if (cache) translationCache->try_emplace(sentence, translation);
|
if (cache) translationCache->try_emplace(sentence, translation);
|
||||||
if (cache && translationCache->size() > savedSize + 50) SaveCache();
|
if (cache && translationCache->size() > savedSize + 50) SaveCache();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user