Merge remote-tracking branch 'Blu3train/translatewrapper_regex_lineedit_dont_call_translator'
This commit is contained in:
commit
4d1dfdac85
@ -194,6 +194,7 @@ extern const std::unordered_map<std::wstring, std::wstring> codes
|
||||
|
||||
bool translateSelectedOnly = false, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 1000;
|
||||
std::wstring dontTranslateIfMatch = L"";
|
||||
|
||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, TranslationParam tlp)
|
||||
{
|
||||
|
@ -105,6 +105,7 @@ extern const std::unordered_map<std::wstring, std::wstring> codes
|
||||
|
||||
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = true, useCache = true, useFilter = true;
|
||||
int tokenCount = 10, rateLimitTimespan = 60000, maxSentenceSize = 1000;
|
||||
std::wstring dontTranslateIfMatch = L"";
|
||||
|
||||
enum KeyType { CAT, REST };
|
||||
int keyType = REST;
|
||||
|
@ -99,6 +99,7 @@ extern const std::unordered_map<std::wstring, std::wstring> codes
|
||||
|
||||
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 2500;
|
||||
std::wstring dontTranslateIfMatch = L"";
|
||||
|
||||
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
|
@ -48,6 +48,7 @@ extern const std::unordered_map<std::wstring, std::wstring> codes
|
||||
|
||||
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 2500;
|
||||
std::wstring dontTranslateIfMatch = L"";
|
||||
|
||||
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
|
@ -115,6 +115,7 @@ extern const std::unordered_map<std::wstring, std::wstring> codes
|
||||
|
||||
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 2500;
|
||||
std::wstring dontTranslateIfMatch = L"";
|
||||
|
||||
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
|
@ -234,6 +234,7 @@ extern const std::unordered_map<std::wstring, std::wstring> codes
|
||||
|
||||
bool translateSelectedOnly = false, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 1000;
|
||||
std::wstring dontTranslateIfMatch = L"";
|
||||
|
||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, TranslationParam tlp)
|
||||
{
|
||||
|
@ -17,6 +17,7 @@ extern const char* FILTER_GARBAGE;
|
||||
extern const char* MAX_TRANSLATIONS_IN_TIMESPAN;
|
||||
extern const char* TIMESPAN;
|
||||
extern const char* MAX_SENTENCE_SIZE;
|
||||
extern const char* DONT_TRANSLATE_IF_MATCH;
|
||||
extern const char* API_KEY;
|
||||
extern const wchar_t* SENTENCE_TOO_LARGE_TO_TRANS;
|
||||
extern const wchar_t* TRANSLATION_ERROR;
|
||||
@ -27,6 +28,7 @@ extern const char* GET_API_KEY_FROM;
|
||||
extern const QStringList languagesTo, languagesFrom;
|
||||
extern bool translateSelectedOnly, useRateLimiter, rateLimitSelected, useCache, useFilter;
|
||||
extern int tokenCount, rateLimitTimespan, maxSentenceSize;
|
||||
extern std::wstring dontTranslateIfMatch;
|
||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, TranslationParam tlp);
|
||||
|
||||
QFormLayout* display;
|
||||
@ -118,6 +120,14 @@ public:
|
||||
display->addRow(label, spinBox);
|
||||
connect(spinBox, qOverload<int>(&QSpinBox::valueChanged), [label, &value](int newValue) { settings.setValue(label, value = newValue); });
|
||||
}
|
||||
|
||||
auto matchEdit = new QLineEdit(settings.value(DONT_TRANSLATE_IF_MATCH).toString(), this);
|
||||
dontTranslateIfMatch = S(matchEdit->text());
|
||||
QObject::connect(matchEdit, &QLineEdit::textChanged, [](QString match) { settings.setValue(DONT_TRANSLATE_IF_MATCH, S(dontTranslateIfMatch = S(match))); });
|
||||
auto matchLabel = new QLabel(QString("%1 (<a href=\"https://regexr.com/\">regex</a>)").arg(DONT_TRANSLATE_IF_MATCH), this);
|
||||
matchLabel->setOpenExternalLinks(true);
|
||||
display->addRow(matchLabel, matchEdit);
|
||||
|
||||
if (GET_API_KEY_FROM)
|
||||
{
|
||||
auto keyEdit = new QLineEdit(settings.value(API_KEY).toString(), this);
|
||||
@ -182,6 +192,16 @@ bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||
sentence.erase(std::remove_if(sentence.begin(), sentence.end(), [](wchar_t ch) { return ch < ' ' && ch != '\n'; }), sentence.end());
|
||||
}
|
||||
if (sentence.empty()) return true;
|
||||
|
||||
try
|
||||
{
|
||||
if (!dontTranslateIfMatch.empty() && std::regex_match(sentence, std::wregex(dontTranslateIfMatch)))
|
||||
{
|
||||
sentence += L"\x200b \n" + sentence;
|
||||
return true;
|
||||
}
|
||||
} catch (...) {}
|
||||
|
||||
if (sentence.size() > maxSentenceSize) translation = SENTENCE_TOO_LARGE_TO_TRANS;
|
||||
if (useCache)
|
||||
{
|
||||
|
2
text.cpp
2
text.cpp
@ -160,6 +160,7 @@ const wchar_t* ERROR_START_CHROME = L"failed to start Chrome or to connect to it
|
||||
const char* EXTRA_WINDOW_INFO = u8R"(Right click to change settings
|
||||
Click and drag on window edges to move, or the bottom right corner to resize)";
|
||||
const char* MAX_SENTENCE_SIZE = u8"Max sentence size";
|
||||
const char* DONT_TRANSLATE_IF_MATCH = u8"Don't translate if match full";
|
||||
const char* TOPMOST = u8"Always on top";
|
||||
const char* DICTIONARY = u8"Dictionary";
|
||||
const char* DICTIONARY_INSTRUCTIONS = u8R"(This file is used only for the "Dictionary" feature of the Extra Window extension.
|
||||
@ -917,6 +918,7 @@ esempio: Textractor -p4466 -p"My Game.exe" sta tentando di inniettare i processi
|
||||
EXTRA_WINDOW_INFO = u8R"(Tasto destro per cambiare le impostazioni
|
||||
Clicca e trascina i bordi della finestra per muoverla, oppure nell'angolo in basso a destra per ridimensionare)";
|
||||
MAX_SENTENCE_SIZE = u8"Dimensione massima sentenza";
|
||||
DONT_TRANSLATE_IF_MATCH = u8"Non traduce se corrisponde completamente";
|
||||
TOPMOST = u8"Sempre in primo piano";
|
||||
DICTIONARY = u8"Dizionario";
|
||||
DICTIONARY_INSTRUCTIONS = u8R"(Questo file è utilizzato solo per la funzione "Dizionario" dell'estenzione Extra Window.
|
||||
|
Loading…
Reference in New Issue
Block a user