translatewrapper: regex lineedit doesn't translate sentence on a full match
This commit is contained in:
parent
f732f488e6
commit
24a199a8c4
@ -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;
|
bool translateSelectedOnly = false, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 1000;
|
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 1000;
|
||||||
|
std::wstring dontTranslateIfMatch = L"";
|
||||||
|
|
||||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, TranslationParam tlp)
|
std::pair<bool, std::wstring> Translate(const std::wstring& text, TranslationParam tlp)
|
||||||
{
|
{
|
||||||
|
@ -99,6 +99,7 @@ extern const std::unordered_map<std::wstring, std::wstring> codes
|
|||||||
|
|
||||||
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = true, useCache = true, useFilter = true;
|
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = true, useCache = true, useFilter = true;
|
||||||
int tokenCount = 10, rateLimitTimespan = 60000, maxSentenceSize = 1000;
|
int tokenCount = 10, rateLimitTimespan = 60000, maxSentenceSize = 1000;
|
||||||
|
std::wstring dontTranslateIfMatch = L"";
|
||||||
|
|
||||||
enum KeyType { CAT, REST };
|
enum KeyType { CAT, REST };
|
||||||
int keyType = 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;
|
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 2500;
|
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 2500;
|
||||||
|
std::wstring dontTranslateIfMatch = L"";
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
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;
|
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 2500;
|
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 2500;
|
||||||
|
std::wstring dontTranslateIfMatch = L"";
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||||
{
|
{
|
||||||
|
@ -114,6 +114,7 @@ extern const std::unordered_map<std::wstring, std::wstring> codes
|
|||||||
|
|
||||||
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
bool translateSelectedOnly = true, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 2500;
|
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 2500;
|
||||||
|
std::wstring dontTranslateIfMatch = L"";
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
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;
|
bool translateSelectedOnly = false, useRateLimiter = true, rateLimitSelected = false, useCache = true, useFilter = true;
|
||||||
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 1000;
|
int tokenCount = 30, rateLimitTimespan = 60000, maxSentenceSize = 1000;
|
||||||
|
std::wstring dontTranslateIfMatch = L"";
|
||||||
|
|
||||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, TranslationParam tlp)
|
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* MAX_TRANSLATIONS_IN_TIMESPAN;
|
||||||
extern const char* TIMESPAN;
|
extern const char* TIMESPAN;
|
||||||
extern const char* MAX_SENTENCE_SIZE;
|
extern const char* MAX_SENTENCE_SIZE;
|
||||||
|
extern const char* DONT_TRANSLATE_IF_MATCH;
|
||||||
extern const char* API_KEY;
|
extern const char* API_KEY;
|
||||||
extern const wchar_t* TOO_MANY_TRANS_REQUESTS;
|
extern const wchar_t* TOO_MANY_TRANS_REQUESTS;
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ extern const char* GET_API_KEY_FROM;
|
|||||||
extern const QStringList languagesTo, languagesFrom;
|
extern const QStringList languagesTo, languagesFrom;
|
||||||
extern bool translateSelectedOnly, useRateLimiter, rateLimitSelected, useCache, useFilter;
|
extern bool translateSelectedOnly, useRateLimiter, rateLimitSelected, useCache, useFilter;
|
||||||
extern int tokenCount, rateLimitTimespan, maxSentenceSize;
|
extern int tokenCount, rateLimitTimespan, maxSentenceSize;
|
||||||
|
extern std::wstring dontTranslateIfMatch;
|
||||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, TranslationParam tlp);
|
std::pair<bool, std::wstring> Translate(const std::wstring& text, TranslationParam tlp);
|
||||||
|
|
||||||
QFormLayout* display;
|
QFormLayout* display;
|
||||||
@ -119,6 +121,14 @@ public:
|
|||||||
display->addRow(label, spinBox);
|
display->addRow(label, spinBox);
|
||||||
connect(spinBox, qOverload<int>(&QSpinBox::valueChanged), [label, &value](int newValue) { settings.setValue(label, value = newValue); });
|
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)
|
if (GET_API_KEY_FROM)
|
||||||
{
|
{
|
||||||
auto keyEdit = new QLineEdit(settings.value(API_KEY).toString(), this);
|
auto keyEdit = new QLineEdit(settings.value(API_KEY).toString(), this);
|
||||||
@ -189,6 +199,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());
|
sentence.erase(std::remove_if(sentence.begin(), sentence.end(), [](wchar_t ch) { return ch < ' ' && ch != '\n'; }), sentence.end());
|
||||||
}
|
}
|
||||||
if (sentence.empty()) return true;
|
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 (useCache)
|
if (useCache)
|
||||||
{
|
{
|
||||||
auto translationCache = ::translationCache.Acquire();
|
auto translationCache = ::translationCache.Acquire();
|
||||||
|
2
text.cpp
2
text.cpp
@ -157,6 +157,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
|
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)";
|
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* 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* TOPMOST = u8"Always on top";
|
||||||
const char* DICTIONARY = u8"Dictionary";
|
const char* DICTIONARY = u8"Dictionary";
|
||||||
const char* DICTIONARY_INSTRUCTIONS = u8R"(This file is used only for the "Dictionary" feature of the Extra Window extension.
|
const char* DICTIONARY_INSTRUCTIONS = u8R"(This file is used only for the "Dictionary" feature of the Extra Window extension.
|
||||||
@ -875,6 +876,7 @@ esempio: Textractor -p4466 -p"My Game.exe" sta tentando di inniettare i processi
|
|||||||
EXTRA_WINDOW_INFO = u8R"(Tasto destro per cambiare le impostazioni
|
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)";
|
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";
|
MAX_SENTENCE_SIZE = u8"Dimensione massima sentenza";
|
||||||
|
DONT_TRANSLATE_IF_MATCH = u8"Non traduce se corrisponde completamente";
|
||||||
TOPMOST = u8"Sempre in primo piano";
|
TOPMOST = u8"Sempre in primo piano";
|
||||||
DICTIONARY = u8"Dizionario";
|
DICTIONARY = u8"Dizionario";
|
||||||
DICTIONARY_INSTRUCTIONS = u8R"(Questo file è utilizzato solo per la funzione "Dizionario" dell'estenzione Extra Window.
|
DICTIONARY_INSTRUCTIONS = u8R"(Questo file è utilizzato solo per la funzione "Dizionario" dell'estenzione Extra Window.
|
||||||
|
Loading…
Reference in New Issue
Block a user