diff --git a/.travis.yml b/.travis.yml index e981e6c..4333a2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ branches: - /.*travis/ os: - linux -email: - on_success: change - on_failure: change +notifications: + email: + on_success: change + on_failure: change diff --git a/Settings.h b/Settings.h index 013cd70..3468989 100644 --- a/Settings.h +++ b/Settings.h @@ -30,6 +30,7 @@ namespace settings_names { //! Translation const QString translationGroup = "Translation"; const QString doTranslation = "doTranslation"; + const QString ignoreSslErrors = "ignoreSslErrors"; const QString sourceLanguage = "source_language"; const QString translationLanguage = "translation_language"; const QString translationTimeout = "translation_timeout"; @@ -67,6 +68,7 @@ namespace settings_values { //! Translation const bool doTranslation = true; + const bool ignoreSslErrors = false; const QString sourceLanguage = "auto"; const QString translationLanguage = "ru"; const int translationTimeout = 15; // secs diff --git a/SettingsEditor.cpp b/SettingsEditor.cpp index 72b75c7..fe6cb11 100644 --- a/SettingsEditor.cpp +++ b/SettingsEditor.cpp @@ -128,6 +128,7 @@ void SettingsEditor::saveSettings () const { settings.beginGroup (translationGroup); settings.setValue (doTranslation, ui->doTranslationCheck->isChecked ()); + settings.setValue (ignoreSslErrors, ui->ignoreSslCheck->isChecked ()); settings.setValue (translationDebugMode, ui->translatorDebugCheck->isChecked ()); QString trLanguage = dictionary_.translateUiToCode (ui->translateLangCombo->currentText ()); settings.setValue (translationLanguage, trLanguage); @@ -216,6 +217,7 @@ void SettingsEditor::loadSettings () { settings.beginGroup (settings_names::translationGroup); ui->doTranslationCheck->setChecked (GET (doTranslation).toBool ()); + ui->ignoreSslCheck->setChecked (GET (ignoreSslErrors).toBool ()); ui->translatorDebugCheck->setChecked (GET (translationDebugMode).toBool ()); QString trLanguage = dictionary_.translateCodeToUi (GET (translationLanguage).toString ()); ui->translateLangCombo->setCurrentText (trLanguage); diff --git a/SettingsEditor.ui b/SettingsEditor.ui index d7a1fab..064b900 100644 --- a/SettingsEditor.ui +++ b/SettingsEditor.ui @@ -378,7 +378,7 @@ - + <html><head/><body><p>Отображает окно переводчика. Следует использовать только для разработки переводчиков.</p></body></html> @@ -388,6 +388,13 @@ + + + + Игнорировать ошибки SSL + + + @@ -398,6 +405,13 @@ + + + + сек. + + + @@ -411,6 +425,9 @@ + + + @@ -421,16 +438,6 @@ - - - - - - - сек. - - - diff --git a/WebTranslator.cpp b/WebTranslator.cpp index 1a9b166..6293816 100644 --- a/WebTranslator.cpp +++ b/WebTranslator.cpp @@ -14,7 +14,8 @@ WebTranslator::WebTranslator () : QObject (), proxy_ (new WebTranslatorProxy (this)), view_ (new QWebView), - translatorHelper_ (new TranslatorHelper), isReady_ (true) { + translatorHelper_ (new TranslatorHelper), isReady_ (true), + ignoreSslErrors_ (settings_values::ignoreSslErrors){ view_->settings ()->setAttribute (QWebSettings::AutoLoadImages, false); view_->settings ()->setAttribute (QWebSettings::DeveloperExtrasEnabled, true); @@ -25,6 +26,9 @@ WebTranslator::WebTranslator () this, SLOT (addProxyToView ())); connect (view_->page ()->networkAccessManager (), SIGNAL (finished (QNetworkReply *)), this, SLOT (replyFinished (QNetworkReply *))); + connect (view_->page ()->networkAccessManager (), + SIGNAL (sslErrors (QNetworkReply *, QList)), + this, SLOT (handleSslErrors (QNetworkReply *, QList))); translationTimeout_.setSingleShot (true); connect (&translationTimeout_, SIGNAL (timeout ()), SLOT (abortTranslation ())); @@ -76,6 +80,12 @@ void WebTranslator::proxyTranslated (const QString &text) { finishTranslation (false); } +void WebTranslator::handleSslErrors (QNetworkReply *reply, const QList &) { + if (ignoreSslErrors_) { + reply->ignoreSslErrors (); + } +} + void WebTranslator::abortTranslation () { if (!tryNextTranslator ()) { emit error (tr ("Перевод отменен по таймауту.")); @@ -134,6 +144,8 @@ void WebTranslator::applySettings () { } bool debugMode = GET (translationDebugMode).toBool (); setDebugMode (debugMode); + + ignoreSslErrors_ = GET(ignoreSslErrors).toBool (); #undef GET } diff --git a/WebTranslator.h b/WebTranslator.h index 8cb60ba..bcc31a3 100644 --- a/WebTranslator.h +++ b/WebTranslator.h @@ -9,6 +9,7 @@ class QWebView; class QNetworkReply; +class QSslError; class WebTranslatorProxy; class TranslatorHelper; @@ -35,6 +36,7 @@ class WebTranslator : public QObject { void addProxyToView (); void abortTranslation (); void proxyTranslated (const QString &text); + void handleSslErrors (QNetworkReply *reply, const QList &errors); private: void translateQueued (); @@ -47,6 +49,7 @@ class WebTranslator : public QObject { TranslatorHelper *translatorHelper_; QVector queue_; bool isReady_; + bool ignoreSslErrors_; QTimer translationTimeout_; }; diff --git a/scripts/make_app.sh b/scripts/make_app.sh index 90388bb..afaede9 100755 --- a/scripts/make_app.sh +++ b/scripts/make_app.sh @@ -6,7 +6,7 @@ cleanupDirInNeeded $APP_DIR cd $APP_DIR echo "Building app" -lrelease $QT_CHOOSER $SRC_DIR/ScreenTranslator.pro +$QT_LRELEASE $QT_CHOOSER $SRC_DIR/ScreenTranslator.pro $QMAKE $QT_CHOOSER "CONFIG-=debug_and_release" "CONFIG+=release" $SRC_DIR make $JOBS diff --git a/scripts/options.sh b/scripts/options.sh index f824fe7..2bb1144 100755 --- a/scripts/options.sh +++ b/scripts/options.sh @@ -7,6 +7,7 @@ CLEAN=false JOBS="" QT_CHOOSER="-qt=qt5" QMAKE=qmake +QT_LRELEASE=lrelease QT_LIB_DIR=/usr/lib/x86_64-linux-gnu STRIP=strip @@ -17,6 +18,7 @@ for arg in ${@}; do "clean" ) CLEAN=true;; "-j"* ) JOBS=$arg;; *"qmake" ) QMAKE=$arg + QT_LRELEASE=`readlink -e $(dirname $arg)/lrelease` QT_LIB_DIR=`readlink -e $(dirname $arg)/../lib` QT_CHOOSER="" ;; diff --git a/translations/translation_en.ts b/translations/translation_en.ts index f8bc7fb..cfbd843 100644 --- a/translations/translation_en.ts +++ b/translations/translation_en.ts @@ -34,7 +34,7 @@ - + Результат Result @@ -56,7 +56,7 @@ - + О программе About @@ -73,12 +73,12 @@ %1 - + Не найден подходящий язык распознавания. Failed to find selected recognition language. - + Программа для распознавания текста на экране. Создана с использованием Qt, tesseract-ocr, Google Translate. Автор: Gres (translator@gres.biz) @@ -86,7 +86,7 @@ Screen text recognition and translation program. \n Uses Qt, tesseract-ocr, Google Translate. \n Author: Gres (translator@gres.biz) \n Version: %1 from %2 %3 - + Подсказки. @@ -113,17 +113,17 @@ Key modifiers what capturing : - + Последний результат был скопирован в буфер обмена. Last result has been copied to clipboard. - + Правка Correction - + Исправьте распознанный текст Correct recognized text @@ -736,27 +736,27 @@ Key modifiers what capturing : Result - + Распознать другой язык Recognize another language - + Перевести на другой язык Translate to another language - + Скопировать в буфер Copy to clipboard - + Скопировать рисунок в буфер Copy image to clibpoard - + Исправить распознанный текст Correct recognized text @@ -846,7 +846,7 @@ Key modifiers what capturing : - + Путь к tessdata Tessdata path @@ -1001,36 +1001,41 @@ Key modifiers what capturing : + Игнорировать ошибки SSL + Ignore SSL errors + + + <html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html> <html><head/><body><p>Max time of translation process.</p></body></html> - + Максимальное время перевода: Max translation time: - + <html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html> <html><head/><body><p>Translated text language.</p></body></html> - + Язык результата: Translation language: - + Переводчики: Translators: - + сек. secs. - + <html><head/><body><p>Отображены в порядке убывания приоритета.</p></body></html> <html><head/><body><p>Sorted by priority descending.</p></body></html> @@ -1446,17 +1451,17 @@ Change dirs permissions and try again or perform manual update. WebTranslator - + Перевод отменен по таймауту. Translation timed out. - + Ошибка загрузки страницы (%1) для перевода. Page (%1) load failed. - + Нет сценариев для перевода. Измените настройки. Not found any translators. Change settings. diff --git a/translations/translation_ru.ts b/translations/translation_ru.ts index 690dc61..05cbd2c 100644 --- a/translations/translation_ru.ts +++ b/translations/translation_ru.ts @@ -34,7 +34,7 @@ - + Результат Результат @@ -56,7 +56,7 @@ - + О программе О программе @@ -73,12 +73,12 @@ %1 - + Не найден подходящий язык распознавания. Не найден подходящий язык распознавания. - + Программа для распознавания текста на экране. Создана с использованием Qt, tesseract-ocr, Google Translate. Автор: Gres (translator@gres.biz) @@ -89,7 +89,7 @@ Версия: %1 от %2 %3 - + Подсказки. @@ -116,17 +116,17 @@ - + Последний результат был скопирован в буфер обмена. Последний результат был скопирован в буфер обмена. - + Правка Правка - + Исправьте распознанный текст Исправьте распознанный текст @@ -741,27 +741,27 @@ Результат - + Распознать другой язык Распознать другой язык - + Перевести на другой язык Перевести на другой язык - + Скопировать в буфер Скопировать в буфер - + Скопировать рисунок в буфер Скопировать рисунок в буфер - + Исправить распознанный текст Исправить распознанный текст @@ -851,7 +851,7 @@ - + Путь к tessdata Путь к tessdata @@ -1006,36 +1006,41 @@ + Игнорировать ошибки SSL + Игнорировать ошибки SSL + + + <html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html> <html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html> - + Максимальное время перевода: Максимальное время перевода: - + <html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html> <html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html> - + Язык результата: Язык результата: - + Переводчики: Переводчики: - + сек. сек. - + <html><head/><body><p>Отображены в порядке убывания приоритета.</p></body></html> <html><head/><body><p>Отображены в порядке убывания приоритета.</p></body></html> @@ -1455,17 +1460,17 @@ WebTranslator - + Перевод отменен по таймауту. Перевод отменен по таймауту. - + Ошибка загрузки страницы (%1) для перевода. Ошибка загрузки страницы (%1) для перевода. - + Нет сценариев для перевода. Измените настройки. Нет сценариев для перевода. Измените настройки. diff --git a/translators/bing.js b/translators/bing.js index 2fa19c1..23998b2 100644 --- a/translators/bing.js +++ b/translators/bing.js @@ -6,15 +6,16 @@ function checkFinished () { if (!isPageLoaded || !isTranslationFinished || isScheduled) return; isScheduled = true; setTimeout(function () { - var spans = [].slice.call (document.querySelectorAll ('#OutputText span')); + var spans = [].slice.call (document.querySelectorAll ('#destText span')); var text = spans.reduce (function (res, i) { return res + i.innerText; }, ''); st_wtp.translated (text); + isTranslationFinished = isScheduled = false; }, 2000); // wait for gui fill } function onResourceLoad (url) { - if (url.indexOf ('/api.microsofttranslator.com/') > -1) { + if (url.indexOf ('/translator/api/Dictionary/Lookup?') > -1) { isTranslationFinished = true; checkFinished (); } @@ -27,7 +28,7 @@ function onPageLoad () { window.onload = onPageLoad(); function translate (){ - var url = 'https://bing.com/translator/?text=' + st_wtp.sourceText + '#auto/' + - st_wtp.resultLanguage; + var url = 'https://bing.com/translator/?from=auto&to=' + st_wtp.resultLanguage + + '&text=' + st_wtp.sourceText; window.location = encodeURI (url); } diff --git a/translators/yandex.js b/translators/yandex.js index 7686593..5c8a084 100644 --- a/translators/yandex.js +++ b/translators/yandex.js @@ -6,14 +6,19 @@ function checkFinished () { if (!isPageLoaded || !isTranslationFinished || isScheduled) return; isScheduled = true; setTimeout(function () { - var spans = [].slice.call (document.querySelectorAll ('#translation > span')); + var spans = [].slice.call (document.querySelectorAll ('span.translation-chunk')); var text = spans.reduce (function (res, i) { - return res + i.innerText; + return res + i.innerText + ' '; }, ''); st_wtp.translated (text); + isTranslationFinished = isScheduled = false; }, 2000); // wait for gui fill } function onResourceLoad (url) { + if (url.indexOf ('/tr.json/translate?') > -1) { + isTranslationFinished = true; + checkFinished (); + } } st_wtp.resourceLoaded.connect (onResourceLoad); function onPageLoad () { @@ -23,9 +28,8 @@ function onPageLoad () { window.onload = onPageLoad(); function translate (){ - var url = 'https://translate.yandex.ru/?text=' + st_wtp.sourceText + '&lang=auto-' + - st_wtp.resultLanguage; + var url = 'https://translate.yandex.ru/&lang=' + st_wtp.sourceLanguage + '-' + + st_wtp.resultLanguage + '?text=' + st_wtp.sourceText ; url = url.replace(new RegExp(' ','g') , '%20') - console.log(encodeURI(url)); window.location = (url); } diff --git a/version.json b/version.json index cccede6..d6f4158 100644 --- a/version.json +++ b/version.json @@ -14,7 +14,7 @@ "path_linux": "ScreenTranslator" }, "Bing translator": { - "version": 1, + "version": 2, "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/bing.js", "path": "translators/bing.js" }, @@ -24,7 +24,7 @@ "path": "translators/google.js" }, "Yandex translator": { - "version": 1, + "version": 2, "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/yandex.js", "path": "translators/yandex.js" }