dont need that param anymore

This commit is contained in:
Akash Mozumdar 2020-04-25 20:39:12 -06:00
parent e20a12862c
commit a129394fb5
4 changed files with 6 additions and 6 deletions

View File

@ -83,7 +83,7 @@ QStringList languages
bool translateSelectedOnly = false, rateLimitAll = true, rateLimitSelected = false, useCache = true;
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 (HttpRequest httpRequest{

View File

@ -25,13 +25,13 @@ QStringList languages
"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;
const wchar_t* accept[] = { L"*/*", nullptr };
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 (HttpRequest httpRequest{

View File

@ -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'); });
}
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 (HttpRequest httpRequest{

View File

@ -23,7 +23,7 @@ extern const char* GET_API_KEY_FROM;
extern QStringList languages;
extern bool translateSelectedOnly, rateLimitAll, rateLimitSelected, useCache;
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 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 (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;
if (cache) translationCache->try_emplace(sentence, translation);
if (cache && translationCache->size() > savedSize + 50) SaveCache();