Part: Attempt to translate exceptions in dialogs

Relies on the exception text having been added to the translation database in a previous call to QT_TRANSLATE_NOOP, and put in the 'Exception' context.
This commit is contained in:
Chris Hennes
2023-04-27 17:31:44 -05:00
parent 1b2857c306
commit bdcd28cf5c
8 changed files with 21 additions and 18 deletions

View File

@@ -495,8 +495,10 @@ void DlgExtrusion::apply()
throw;
}
catch (Base::Exception &err){
QMessageBox::critical(this, windowTitle(),
tr("Creating Extrusion failed.\n%1").arg(QString::fromUtf8(err.what())));
QMessageBox::critical(this,
windowTitle(),
tr("Creating Extrusion failed.\n%1")
.arg(QCoreApplication::translate("Exception", err.what())));
return;
}
catch(...) {
@@ -643,11 +645,11 @@ bool DlgExtrusion::validate()
Base::Vector3d dir, base;
hasValidAxisLink = Part::Extrusion::fetchAxisLink(lnk, base, dir);
} catch(Base::Exception &err) {
errmsg = QString::fromUtf8(err.what());
errmsg = QCoreApplication::translate("Exception", err.what());
} catch(Standard_Failure &err) {
errmsg = QString::fromLocal8Bit(err.GetMessageString());
} catch(...) {
errmsg = QString::fromUtf8("Unknown error");
errmsg = tr("Unknown error");
}
if (this->getDirMode() == Part::Extrusion::dmEdge && !hasValidAxisLink){
if (errmsg.length() > 0)
@@ -669,7 +671,7 @@ bool DlgExtrusion::validate()
lnk.setValue(&this->getShapeToExtrude()); //simplified - check only for the first shape.
Part::Extrusion::calculateShapeNormal(lnk);
} catch(Base::Exception &err) {
errmsg = QString::fromUtf8(err.what());
errmsg = QCoreApplication::translate("Exception", err.what());
} catch(Standard_Failure &err) {
errmsg = QString::fromLocal8Bit(err.GetMessageString());
} catch(...) {

View File

@@ -125,7 +125,7 @@ void Picker::createPrimitive(QWidget* widget, const QString& descr, Gui::Documen
Gui::Command::runCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
}
catch (const Base::Exception& e) {
QMessageBox::warning(widget, descr, QString::fromLatin1(e.what()));
QMessageBox::warning(widget, descr, QCoreApplication::translate("Exception", e.what()));
}
}
@@ -1935,11 +1935,11 @@ void DlgPrimitives::createPrimitive(const QString& placement)
}
catch (const std::exception& e) {
QMessageBox::warning(this, tr("Create %1")
.arg(ui->PrimitiveTypeCB->currentText()), QString::fromLatin1(e.what()));
.arg(ui->PrimitiveTypeCB->currentText()), QCoreApplication::translate("Exception", e.what()));
}
catch (const Base::PyException& e) {
QMessageBox::warning(this, tr("Create %1")
.arg(ui->PrimitiveTypeCB->currentText()), QString::fromLatin1(e.what()));
.arg(ui->PrimitiveTypeCB->currentText()), QCoreApplication::translate("Exception", e.what()));
}
}

View File

@@ -277,7 +277,7 @@ bool DlgRevolution::validate()
axisLinkHasAngle = angle_edge != 1e100;
} catch(Base::Exception &err) {
QMessageBox::critical(this, windowTitle(),
tr("Revolution axis link is invalid.\n\n%1").arg(QString::fromUtf8(err.what())));
tr("Revolution axis link is invalid.\n\n%1").arg(QCoreApplication::translate("Exception", err.what())));
ui->txtAxisLink->setFocus();
return false;
} catch(Standard_Failure &err) {
@@ -287,7 +287,7 @@ bool DlgRevolution::validate()
return false;
} catch(...) {
QMessageBox::critical(this, windowTitle(),
tr("Revolution axis link is invalid.\n\n%1").arg(QString::fromUtf8("Unknown error")));
tr("Revolution axis link is invalid.\n\n%1").arg(tr("Unknown error")));
ui->txtAxisLink->setFocus();
return false;
}
@@ -440,7 +440,7 @@ void DlgRevolution::accept()
activeDoc->recompute();
} catch (Base::Exception &err) {
QMessageBox::critical(this, windowTitle(),
tr("Creating Revolve failed.\n\n%1").arg(QString::fromUtf8(err.what())));
tr("Creating Revolve failed.\n\n%1").arg(QCoreApplication::translate("Exception", err.what())));
return;
} catch (...){
QMessageBox::critical(this, windowTitle(),

View File

@@ -313,7 +313,7 @@ bool TaskAttacher::updatePreview()
try{
attached = pcAttach->positionBySupport();
} catch (Base::Exception &err){
errMessage = QString::fromLatin1(err.what());
errMessage = QCoreApplication::translate("Exception", err.what());
} catch (Standard_Failure &err){
errMessage = tr("OCC error: %1").arg(QString::fromLatin1(err.GetMessageString()));
} catch (...) {
@@ -414,7 +414,7 @@ void TaskAttacher::onSelectionChanged(const Gui::SelectionChanges& msg)
}
catch(Base::Exception& e) {
//error = true;
ui->message->setText(QString::fromLatin1(e.what()));
ui->message->setText(QCoreApplication::translate("Exception", e.what()));
ui->message->setStyleSheet(QString::fromLatin1("QLabel{color: red;}"));
}
@@ -1115,7 +1115,7 @@ bool TaskDlgAttacher::accept()
document->commitCommand();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Datum dialog: Input error"), QString::fromLatin1(e.what()));
QMessageBox::warning(parameter, tr("Datum dialog: Input error"), QCoreApplication::translate("Exception", e.what()));
return false;
}

View File

@@ -212,7 +212,7 @@ bool LoftWidget::accept()
doc->commitCommand();
}
catch (const Base::Exception& e) {
QMessageBox::warning(this, tr("Input error"), QString::fromLatin1(e.what()));
QMessageBox::warning(this, tr("Input error"), QCoreApplication::translate("Exception", e.what()));
return false;
}

View File

@@ -207,7 +207,7 @@ bool OffsetWidget::accept()
Gui::Command::commitCommand();
}
catch (const Base::Exception& e) {
QMessageBox::warning(this, tr("Input error"), QString::fromLatin1(e.what()));
QMessageBox::warning(this, tr("Input error"), QCoreApplication::translate("Exception", e.what()));
return false;
}

View File

@@ -378,7 +378,7 @@ bool SweepWidget::accept()
doc->commitCommand();
}
catch (const Base::Exception& e) {
QMessageBox::warning(this, tr("Input error"), QString::fromLatin1(e.what()));
QMessageBox::warning(this, tr("Input error"), QCoreApplication::translate("Exception", e.what()));
return false;
}

View File

@@ -255,7 +255,8 @@ bool ThicknessWidget::accept()
Gui::Command::commitCommand();
}
catch (const Base::Exception& e) {
QMessageBox::warning(this, tr("Input error"), QString::fromLatin1(e.what()));
QMessageBox::warning(
this, tr("Input error"), QCoreApplication::translate("Exception", e.what()));
return false;
}