Change messages text

This commit is contained in:
Gres 2020-04-11 13:57:37 +03:00
parent 7c87371fe5
commit 7227fc9844
6 changed files with 58 additions and 47 deletions

View File

@ -38,6 +38,11 @@ Manager::Manager()
{ {
SOFT_ASSERT(settings_, return ); SOFT_ASSERT(settings_, return );
// updater components
(void)QT_TRANSLATE_NOOP("QObject", "app");
(void)QT_TRANSLATE_NOOP("QObject", "recognizers");
(void)QT_TRANSLATE_NOOP("QObject", "translators");
tray_ = std::make_unique<TrayIcon>(*this, *settings_); tray_ = std::make_unique<TrayIcon>(*this, *settings_);
capturer_ = std::make_unique<Capturer>(*this, *settings_, *models_); capturer_ = std::make_unique<Capturer>(*this, *settings_, *models_);
recognizer_ = std::make_unique<Recognizer>(*this, *settings_); recognizer_ = std::make_unique<Recognizer>(*this, *settings_);
@ -173,8 +178,7 @@ void Manager::setupTrace(bool isOn)
if (!debug::setTraceFileName(traceFile)) { if (!debug::setTraceFileName(traceFile)) {
QMessageBox::warning( QMessageBox::warning(
nullptr, {}, nullptr, {}, QObject::tr("Failed to set log file: %1").arg(traceFile));
QObject::tr("Failed to setup log to file: %1").arg(traceFile));
return; return;
} }

View File

@ -1,4 +1,5 @@
#include "recognizer.h" #include "recognizer.h"
#include "debug.h"
#include "manager.h" #include "manager.h"
#include "recognizerworker.h" #include "recognizerworker.h"
#include "settings.h" #include "settings.h"
@ -40,10 +41,7 @@ Recognizer::~Recognizer()
void Recognizer::updateSettings() void Recognizer::updateSettings()
{ {
if (settings_.tessdataPath.isEmpty()) { SOFT_ASSERT(!settings_.tessdataPath.isEmpty(), return );
manager_.fatalError(tr("Tessdata path is empty"));
return;
}
emit reset(settings_.tessdataPath); emit reset(settings_.tessdataPath);
} }

View File

@ -142,7 +142,7 @@ void Tesseract::init(const LanguageId &language, const QString &tessdataPath)
if (result == 0) if (result == 0)
return; return;
error_ = QObject::tr("troubles with tessdata"); error_ = QObject::tr("init failed");
engine_.reset(); engine_.reset();
} }
@ -193,7 +193,7 @@ QString Tesseract::recognize(const QPixmap &source)
delete[] outText; delete[] outText;
if (result.isEmpty()) if (result.isEmpty())
error_ = QObject::tr("Failed to recognize text"); error_ = QObject::tr("Failed to recognize text or no text selected");
return result; return result;
} }

View File

@ -87,30 +87,33 @@ QString sizeString(qint64 bytes, int precision)
if (bytes >= tb) { if (bytes >= tb) {
return QString::number(bytes / tb, 'f', precision) + ' ' + return QString::number(bytes / tb, 'f', precision) + ' ' +
QObject::tr("Tb"); QApplication::translate("Updates", "Tb");
} }
if (bytes >= gb) { if (bytes >= gb) {
return QString::number(bytes / gb, 'f', precision) + ' ' + return QString::number(bytes / gb, 'f', precision) + ' ' +
QObject::tr("Gb"); QApplication::translate("Updates", "Gb");
} }
if (bytes >= mb) { if (bytes >= mb) {
return QString::number(bytes / mb, 'f', precision) + ' ' + return QString::number(bytes / mb, 'f', precision) + ' ' +
QObject::tr("Mb"); QApplication::translate("Updates", "Mb");
} }
if (bytes >= kb) { if (bytes >= kb) {
return QString::number(bytes / kb, 'f', precision) + ' ' + return QString::number(bytes / kb, 'f', precision) + ' ' +
QObject::tr("Kb"); QApplication::translate("Updates", "Kb");
} }
return QString::number(bytes) + ' ' + QObject::tr("bytes"); return QString::number(bytes) + ' ' +
QApplication::translate("Updates", "bytes");
} }
QString toString(State state) QString toString(State state)
{ {
const QMap<State, QString> names{ const QMap<State, QString> names{
{State::NotAvailable, {}}, {State::NotAvailable, {}},
{State::NotInstalled, QObject::tr("Not installed")}, {State::NotInstalled,
{State::UpdateAvailable, QObject::tr("Update available")}, QApplication::translate("Updates", "Not installed")},
{State::Actual, QObject::tr("Up to date")}, {State::UpdateAvailable,
QApplication::translate("Updates", "Update available")},
{State::Actual, QApplication::translate("Updates", "Up to date")},
}; };
return names.value(state); return names.value(state);
} }
@ -119,8 +122,8 @@ QString toString(Action action)
{ {
const QMap<Action, QString> names{ const QMap<Action, QString> names{
{Action::NoAction, {}}, {Action::NoAction, {}},
{Action::Remove, QObject::tr("Remove")}, {Action::Remove, QApplication::translate("Updates", "Remove")},
{Action::Install, QObject::tr("Install/Update")}, {Action::Install, QApplication::translate("Updates", "Install/Update")},
}; };
return names.value(action); return names.value(action);
} }
@ -212,7 +215,7 @@ void Loader::handleUpdateReply(QNetworkReply *reply)
const auto replyData = reply->readAll(); const auto replyData = reply->readAll();
if (replyData.isEmpty()) { if (replyData.isEmpty()) {
addError(tr("Received empty updates info from %1").arg(url.toString())); addError(tr("Empty updates info from\n%1").arg(url.toString()));
startDownloadUpdates(url); startDownloadUpdates(url);
return; return;
} }
@ -221,8 +224,7 @@ void Loader::handleUpdateReply(QNetworkReply *reply)
url.toString().endsWith(".zip") ? unpack(replyData) : replyData; url.toString().endsWith(".zip") ? unpack(replyData) : replyData;
if (unpacked.isEmpty()) { if (unpacked.isEmpty()) {
addError( addError(tr("Empty updates info unpacked from\n%1").arg(url.toString()));
tr("Empty updates info after unpacking from %1").arg(url.toString()));
startDownloadUpdates(url); startDownloadUpdates(url);
return; return;
} }
@ -230,7 +232,7 @@ void Loader::handleUpdateReply(QNetworkReply *reply)
SOFT_ASSERT(model_, return ); SOFT_ASSERT(model_, return );
const auto parseError = model_->parse(unpacked); const auto parseError = model_->parse(unpacked);
if (!parseError.isEmpty()) { if (!parseError.isEmpty()) {
addError(tr("Failed to parse updates from %1 (%2)") addError(tr("Failed to parse updates from\n%1 (%2)")
.arg(url.toString(), parseError)); .arg(url.toString(), parseError));
startDownloadUpdates(url); startDownloadUpdates(url);
return; return;
@ -244,7 +246,7 @@ void Loader::handleUpdateReply(QNetworkReply *reply)
QString Loader::toError(QNetworkReply &reply) const QString Loader::toError(QNetworkReply &reply) const
{ {
return tr("Failed to download file %1. Error %2") return tr("Failed to download file\n%1. Error %2")
.arg(reply.url().toString(), reply.errorString()); .arg(reply.url().toString(), reply.errorString());
} }
@ -252,13 +254,13 @@ void Loader::applyUserActions()
{ {
SOFT_ASSERT(model_, return ); SOFT_ASSERT(model_, return );
if (!currentActions_.empty() || !downloads_.empty()) { if (!currentActions_.empty() || !downloads_.empty()) {
emit error(tr("Update already in process")); emit error(tr("Already updating"));
return; return;
} }
currentActions_ = model_->userActions(); currentActions_ = model_->userActions();
if (currentActions_.empty()) { if (currentActions_.empty()) {
emit error(tr("No actions to apply")); emit error(tr("No actions selected"));
return; return;
} }
@ -323,14 +325,14 @@ bool Loader::handleComponentReply(QNetworkReply *reply)
const auto &fileName = file->downloadPath; const auto &fileName = file->downloadPath;
auto dir = QFileInfo(fileName).absoluteDir(); auto dir = QFileInfo(fileName).absoluteDir();
if (!dir.exists() && !dir.mkpath(".")) { if (!dir.exists() && !dir.mkpath(".")) {
finishUpdate(tr("Failed to create temp path %1").arg(dir.absolutePath())); finishUpdate(tr("Failed to create temp path\n%1").arg(dir.absolutePath()));
return false; return false;
} }
const auto url = reply->url(); const auto url = reply->url();
const auto replyData = reply->readAll(); const auto replyData = reply->readAll();
if (replyData.isEmpty()) { if (replyData.isEmpty()) {
addError(tr("Empty data downloaded from %1").arg(url.toString())); addError(tr("Empty data downloaded from\n%1").arg(url.toString()));
if (!startDownload(*file)) if (!startDownload(*file))
finishUpdate(); finishUpdate();
@ -343,7 +345,7 @@ bool Loader::handleComponentReply(QNetworkReply *reply)
const auto unpacked = mustUnpack ? unpack(replyData) : replyData; const auto unpacked = mustUnpack ? unpack(replyData) : replyData;
if (unpacked.isEmpty()) { if (unpacked.isEmpty()) {
addError(tr("Empty data after unpacking from %1").arg(url.toString())); addError(tr("Empty data unpacked from\n%1").arg(url.toString()));
if (!startDownload(*file)) if (!startDownload(*file))
finishUpdate(); finishUpdate();
@ -353,7 +355,7 @@ bool Loader::handleComponentReply(QNetworkReply *reply)
QFile f(fileName); QFile f(fileName);
if (!f.open(QFile::WriteOnly)) { if (!f.open(QFile::WriteOnly)) {
const auto error = tr("Failed to save downloaded file %1 to %2. Error %3") const auto error = tr("Failed to save downloaded file\n%1\nto %2\nError %3")
.arg(url.toString(), f.fileName(), f.errorString()); .arg(url.toString(), f.fileName(), f.errorString());
finishUpdate(error); finishUpdate(error);
return false; return false;
@ -496,7 +498,7 @@ QString Model::parse(const QByteArray &data)
const auto json = doc.object(); const auto json = doc.object();
const auto version = json[versionKey].toInt(); const auto version = json[versionKey].toInt();
if (version != 1) { if (version != 1) {
return tr("Wrong updates version %1").arg(version); return tr("Wrong updates version: %1").arg(version);
} }
beginResetModel(); beginResetModel();
@ -507,9 +509,8 @@ QString Model::parse(const QByteArray &data)
endResetModel(); endResetModel();
if (!root_) { if (!root_)
return tr("No data parsed"); return tr("No data parsed");
}
return {}; return {};
} }
@ -1021,7 +1022,8 @@ void Installer::checkRemove(const File &file)
return; return;
if (installDir.exists() && !installDir.isWritable()) { if (installDir.exists() && !installDir.isWritable()) {
errors_.append(QObject::tr("Directory is not writable %1") errors_.append(
QApplication::translate("Updates", "Directory is not writable\n%1")
.arg(installDir.absolutePath())); .arg(installDir.absolutePath()));
} }
} }
@ -1030,13 +1032,15 @@ void Installer::checkInstall(const File &file)
{ {
if (!QFileInfo::exists(file.downloadPath)) { if (!QFileInfo::exists(file.downloadPath)) {
errors_.append( errors_.append(
QObject::tr("Downloaded file not exists %1").arg(file.downloadPath)); QApplication::translate("Updates", "Downloaded file not exists\n%1")
.arg(file.downloadPath));
// no return // no return
} }
QFileInfo installDir(QFileInfo(file.expandedPath).absolutePath()); QFileInfo installDir(QFileInfo(file.expandedPath).absolutePath());
if (installDir.exists() && !installDir.isWritable()) { if (installDir.exists() && !installDir.isWritable()) {
errors_.append(QObject::tr("Directory is not writable %1") errors_.append(
QApplication::translate("Updates", "Directory is not writable\n%1")
.arg(installDir.absolutePath())); .arg(installDir.absolutePath()));
} }
} }
@ -1048,7 +1052,8 @@ void Installer::remove(const File &file)
return; return;
if (!f.remove()) { if (!f.remove()) {
errors_.append(QObject::tr("Failed to remove file %1. Error %2") errors_.append(QApplication::translate(
"Updates", "Failed to remove file\n%1\nError %2")
.arg(f.fileName(), f.errorString())); .arg(f.fileName(), f.errorString()));
} }
} }
@ -1058,20 +1063,23 @@ void Installer::install(const File &file)
auto installDir = QFileInfo(file.expandedPath).absoluteDir(); auto installDir = QFileInfo(file.expandedPath).absoluteDir();
if (!installDir.exists() && !installDir.mkpath(".")) { if (!installDir.exists() && !installDir.mkpath(".")) {
errors_.append( errors_.append(
QObject::tr("Failed to create path %1").arg(installDir.absolutePath())); QApplication::translate("Updates", "Failed to create path\n%1")
.arg(installDir.absolutePath()));
return; return;
} }
QFile existing(file.expandedPath); QFile existing(file.expandedPath);
if (existing.exists() && !existing.remove()) { if (existing.exists() && !existing.remove()) {
errors_.append(QObject::tr("Failed to remove file %1. Error %2") errors_.append(QApplication::translate(
"Updates", "Failed to remove file\n%1\nError %2")
.arg(existing.fileName(), existing.errorString())); .arg(existing.fileName(), existing.errorString()));
return; return;
} }
QFile f(file.downloadPath); QFile f(file.downloadPath);
if (!f.rename(file.expandedPath)) { if (!f.rename(file.expandedPath)) {
errors_.append(QObject::tr("Failed to move file %1 to %2. Error %3") errors_.append(QApplication::translate(
"Updates", "Failed to move file\n%1\nto %2\nError %3")
.arg(f.fileName(), file.expandedPath, f.errorString())); .arg(f.fileName(), file.expandedPath, f.errorString()));
return; return;
} }
@ -1081,8 +1089,9 @@ void Installer::install(const File &file)
if (!f.open(QFile::WriteOnly | QFile::Append) || if (!f.open(QFile::WriteOnly | QFile::Append) ||
!f.setFileTime(file.versionDate, QFile::FileTime::FileModificationTime)) { !f.setFileTime(file.versionDate, QFile::FileTime::FileModificationTime)) {
errors_.append(QObject::tr("Failed to set modification time of " errors_.append(QApplication::translate("Updates",
"file %1 to %2. Error %3") "Failed to set modification time of "
"file\n%1\nto %2. Error %3")
.arg(f.fileName(), .arg(f.fileName(),
file.versionDate.toString(Qt::ISODate), file.versionDate.toString(Qt::ISODate),
f.errorString())); f.errorString()));

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Настройки</string> <string>Settings</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="0" colspan="4"> <item row="1" column="0" colspan="4">

View File

@ -134,7 +134,7 @@ void Translator::updateSettings()
loadScripts(settings_.translatorsDir, settings_.translators); loadScripts(settings_.translatorsDir, settings_.translators);
if (loaded.empty()) { if (loaded.empty()) {
manager_.fatalError( manager_.fatalError(
tr("No translators loaded from %1 (%2)") tr("No translators loaded from\n%1\n(%2)")
.arg(settings_.translatorsDir, settings_.translators.join(", "))); .arg(settings_.translatorsDir, settings_.translators.join(", ")));
return; return;
} }
@ -272,8 +272,8 @@ void Translator::processQueue()
continue; continue;
if (task->translators.isEmpty()) { if (task->translators.isEmpty()) {
task->error = tr("All translators failed (%1)") task->error =
.arg(task->translatorErrors.join(", ")); tr("All translators failed\n").arg(task->translatorErrors.join("\n"));
finishedTasks.push_back(task); finishedTasks.push_back(task);
continue; continue;
} }