From bdcd28cf5c1e57ccfcf592c66e8ace40f1c59e88 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Thu, 27 Apr 2023 17:31:44 -0500 Subject: [PATCH] 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. --- src/Mod/Part/Gui/DlgExtrusion.cpp | 12 +++++++----- src/Mod/Part/Gui/DlgPrimitives.cpp | 6 +++--- src/Mod/Part/Gui/DlgRevolution.cpp | 6 +++--- src/Mod/Part/Gui/TaskAttacher.cpp | 6 +++--- src/Mod/Part/Gui/TaskLoft.cpp | 2 +- src/Mod/Part/Gui/TaskOffset.cpp | 2 +- src/Mod/Part/Gui/TaskSweep.cpp | 2 +- src/Mod/Part/Gui/TaskThickness.cpp | 3 ++- 8 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/Mod/Part/Gui/DlgExtrusion.cpp b/src/Mod/Part/Gui/DlgExtrusion.cpp index 64e9d31d74..4ca834fc5a 100644 --- a/src/Mod/Part/Gui/DlgExtrusion.cpp +++ b/src/Mod/Part/Gui/DlgExtrusion.cpp @@ -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(...) { diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index b6a1df1d42..c6c9c24291 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -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())); } } diff --git a/src/Mod/Part/Gui/DlgRevolution.cpp b/src/Mod/Part/Gui/DlgRevolution.cpp index 359f5c5ab8..d2b684b609 100644 --- a/src/Mod/Part/Gui/DlgRevolution.cpp +++ b/src/Mod/Part/Gui/DlgRevolution.cpp @@ -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(), diff --git a/src/Mod/Part/Gui/TaskAttacher.cpp b/src/Mod/Part/Gui/TaskAttacher.cpp index 2400ee7346..27f74c185a 100644 --- a/src/Mod/Part/Gui/TaskAttacher.cpp +++ b/src/Mod/Part/Gui/TaskAttacher.cpp @@ -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; } diff --git a/src/Mod/Part/Gui/TaskLoft.cpp b/src/Mod/Part/Gui/TaskLoft.cpp index 136bd2a5b4..afa53efc2f 100644 --- a/src/Mod/Part/Gui/TaskLoft.cpp +++ b/src/Mod/Part/Gui/TaskLoft.cpp @@ -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; } diff --git a/src/Mod/Part/Gui/TaskOffset.cpp b/src/Mod/Part/Gui/TaskOffset.cpp index 6e9c0c339e..f38ac8fe0c 100644 --- a/src/Mod/Part/Gui/TaskOffset.cpp +++ b/src/Mod/Part/Gui/TaskOffset.cpp @@ -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; } diff --git a/src/Mod/Part/Gui/TaskSweep.cpp b/src/Mod/Part/Gui/TaskSweep.cpp index fb886e7071..59366dfbce 100644 --- a/src/Mod/Part/Gui/TaskSweep.cpp +++ b/src/Mod/Part/Gui/TaskSweep.cpp @@ -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; } diff --git a/src/Mod/Part/Gui/TaskThickness.cpp b/src/Mod/Part/Gui/TaskThickness.cpp index 097647f91b..32d27f2512 100644 --- a/src/Mod/Part/Gui/TaskThickness.cpp +++ b/src/Mod/Part/Gui/TaskThickness.cpp @@ -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; }