mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 08:54:12 +08:00
cache filename extension translators: added target language name
This commit is contained in:
parent
d64a2c05b4
commit
db31e19997
@ -25,11 +25,12 @@ extern const wchar_t* TOO_MANY_TRANS_REQUESTS;
|
||||
extern const char* TRANSLATION_PROVIDER;
|
||||
extern const char* GET_API_KEY_FROM;
|
||||
extern const QStringList languagesTo, languagesFrom;
|
||||
extern const std::unordered_map<std::wstring, std::wstring> codes;
|
||||
extern bool translateSelectedOnly, rateLimitAll, rateLimitSelected, useCache, useFilter;
|
||||
extern int tokenCount, rateLimitTimespan, maxSentenceSize;
|
||||
std::pair<bool, std::wstring> Translate(const std::wstring& text, TranslationParam tlp);
|
||||
|
||||
const std::string TRANSLATION_CACHE_FILE = FormatString("%s Translation Cache.txt", TRANSLATION_PROVIDER);
|
||||
std::string TRANSLATION_CACHE_FILE = FormatString("%s Translation Cache.txt", TRANSLATION_PROVIDER);
|
||||
|
||||
QFormLayout* display;
|
||||
Settings settings;
|
||||
@ -47,6 +48,19 @@ namespace
|
||||
std::ofstream(TRANSLATION_CACHE_FILE, std::ios::binary | std::ios::trunc).write((const char*)allTranslations.c_str(), allTranslations.size() * sizeof(wchar_t));
|
||||
savedSize = translationCache->size();
|
||||
}
|
||||
void LoadCache()
|
||||
{
|
||||
translationCache->clear();
|
||||
std::ifstream stream(TRANSLATION_CACHE_FILE, std::ios::binary);
|
||||
BlockMarkupIterator savedTranslations(stream, Array<std::wstring_view>{ L"|SENTENCE|", L"|TRANSLATION|" });
|
||||
auto translationCache = ::translationCache.Acquire();
|
||||
while (auto read = savedTranslations.Next())
|
||||
{
|
||||
auto& [sentence, translation] = read.value();
|
||||
translationCache->try_emplace(std::move(sentence), std::move(translation));
|
||||
}
|
||||
savedSize = translationCache->size();
|
||||
}
|
||||
}
|
||||
|
||||
class Window : public QDialog, Localizer
|
||||
@ -117,16 +131,6 @@ public:
|
||||
|
||||
setWindowTitle(TRANSLATION_PROVIDER);
|
||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||
|
||||
std::ifstream stream(TRANSLATION_CACHE_FILE, std::ios::binary);
|
||||
BlockMarkupIterator savedTranslations(stream, Array<std::wstring_view>{ L"|SENTENCE|", L"|TRANSLATION|" });
|
||||
auto translationCache = ::translationCache.Acquire();
|
||||
while (auto read = savedTranslations.Next())
|
||||
{
|
||||
auto& [sentence, translation] = read.value();
|
||||
translationCache->try_emplace(std::move(sentence), std::move(translation));
|
||||
}
|
||||
savedSize = translationCache->size();
|
||||
}
|
||||
|
||||
~Window()
|
||||
@ -138,6 +142,9 @@ private:
|
||||
void SaveTranslateTo(QString language)
|
||||
{
|
||||
settings.setValue(TRANSLATE_TO, S(tlp->translateTo = S(language)));
|
||||
if (translationCache->size() > savedSize) SaveCache();
|
||||
TRANSLATION_CACHE_FILE = FormatString("%s Translation Cache (%ls).txt", TRANSLATION_PROVIDER, codes.at(S(language)));
|
||||
LoadCache();
|
||||
}
|
||||
void SaveTranslateFrom(QString language)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user