diff --git a/src/Base/Exception.cpp b/src/Base/Exception.cpp index b8c535cd4d..d8cb803401 100644 --- a/src/Base/Exception.cpp +++ b/src/Base/Exception.cpp @@ -38,24 +38,24 @@ TYPESYSTEM_SOURCE(Base::Exception,Base::BaseClass); Exception::Exception(void) - : _line(0) + : _line(0), _isTranslatable(false) { _sErrMsg = "FreeCAD Exception"; } Exception::Exception(const Exception &inst) : _sErrMsg(inst._sErrMsg), _file(inst._file), - _line(inst._line), _function(inst._function) + _line(inst._line), _function(inst._function), _isTranslatable(inst._isTranslatable) { } Exception::Exception(const char * sMessage) - : _sErrMsg(sMessage), _line(0) +: _sErrMsg(sMessage), _line(0), _isTranslatable(false) { } Exception::Exception(const std::string& sMessage) - : _sErrMsg(sMessage), _line(0) +: _sErrMsg(sMessage), _line(0), _isTranslatable(false) { } @@ -116,6 +116,7 @@ PyObject * Exception::getPyObject(void) #endif edict.setItem("sfunction", Py::String(this->getFunction())); edict.setItem("swhat", Py::String(this->what())); + edict.setItem("btranslatable", Py::Boolean(this->getTranslatable())); return Py::new_reference_to(edict); } @@ -138,6 +139,8 @@ void Exception::setPyObject( PyObject * pydict) #else _line = static_cast(Py::Int(edict.getItem("iline"))); #endif + if (edict.hasKey("btranslatable")) + _isTranslatable = static_cast(Py::Boolean(edict.getItem("btranslatable"))); } } diff --git a/src/Base/Exception.h b/src/Base/Exception.h index a59cee25b9..ef2c1e5d1d 100644 --- a/src/Base/Exception.h +++ b/src/Base/Exception.h @@ -34,25 +34,53 @@ #include "FileInfo.h" #include "BaseClass.h" +/* ENABLE TRANSLATION AWARENESS */ +#ifndef QT_TRANSLATE_NOOP +#define QT_TRANSLATE_NOOP(scope, x) x +#endif + /* MACROS FOR THROWING EXCEPTIONS */ +/// the macros do NOT mark any message for translation +/// If you want to mark text for translation, use the QT_TRANSLATE_NOOP macro +/// with the context "Exceptions" and the right throwing macro from below (the one ending in T) +/// example: +/// THROWMT(Base::ValueError,QT_TRANSLATE_NOOP("Exceptions","The multiplicity cannot be increased beyond the degree of the b-spline.")); +/// +/// N.B.: The QT_TRANSLATE_NOOP macro won't translate your string. It will just allow lupdate to identify that string for translation so that +/// if you ask for a translation (and the translator have provided one) at that time it gets translated (e.g. in the UI before showing the message +/// of the exception). + #ifdef _MSC_VER # define THROW(exception) {exception myexcp; myexcp.setDebugInformation(__FILE__,__LINE__,__FUNCSIG__); throw myexcp;} # define THROWM(exception, message) {exception myexcp(message); myexcp.setDebugInformation(__FILE__,__LINE__,__FUNCSIG__); throw myexcp;} # define THROWMF_FILEEXCEPTION(message,filenameorfileinfo) {FileException myexcp(message, filenameorfileinfo); myexcp.setDebugInformation(__FILE__,__LINE__,__FUNCSIG__); throw myexcp;} +# define THROWT(exception) {exception myexcp; myexcp.setDebugInformation(__FILE__,__LINE__,__FUNCSIG__); myexcp.setTranslatable(true); throw myexcp;} +# define THROWMT(exception, message) {exception myexcp(message); myexcp.setDebugInformation(__FILE__,__LINE__,__FUNCSIG__); myexcp.setTranslatable(true); throw myexcp;} +# define THROWMFT_FILEEXCEPTION(message,filenameorfileinfo) {FileException myexcp(message, filenameorfileinfo); myexcp.setDebugInformation(__FILE__,__LINE__,__FUNCSIG__); myexcp.setTranslatable(true); throw myexcp;} + #elif defined(__GNUC__) # define THROW(exception) {exception myexcp; myexcp.setDebugInformation(__FILE__,__LINE__,__PRETTY_FUNCTION__); throw myexcp;} # define THROWM(exception, message) {exception myexcp(message); myexcp.setDebugInformation(__FILE__,__LINE__,__PRETTY_FUNCTION__); throw myexcp;} # define THROWMF_FILEEXCEPTION(message,filenameorfileinfo) {FileException myexcp(message, filenameorfileinfo); myexcp.setDebugInformation(__FILE__,__LINE__,__PRETTY_FUNCTION__); throw myexcp;} +# define THROWT(exception) {exception myexcp; myexcp.setDebugInformation(__FILE__,__LINE__,__PRETTY_FUNCTION__); myexcp.setTranslatable(true); throw myexcp;} +# define THROWMT(exception, message) {exception myexcp(message); myexcp.setDebugInformation(__FILE__,__LINE__,__PRETTY_FUNCTION__); myexcp.setTranslatable(true); throw myexcp;} +# define THROWMFT_FILEEXCEPTION(message,filenameorfileinfo) {FileException myexcp(message, filenameorfileinfo); myexcp.setDebugInformation(__FILE__,__LINE__,__PRETTY_FUNCTION__); myexcp.setTranslatable(true); throw myexcp;} + #else # define THROW(exception) {exception myexcp; myexcp.setDebugInformation(__FILE__,__LINE__,__func__); throw myexcp;} # define THROWM(exception, message) {exception myexcp(message); myexcp.setDebugInformation(__FILE__,__LINE__,__func__); throw myexcp;} -# define THROWMF_FILEEXCEPTION(message,filenameorfileinfo) {FileException myexcp(message, filenameorfileinfo); myexcp.setDebugInformation(__FILE__,__LINE__,__func__); throw myexcp;} +# define THROWMF_FILEEXCEPTION(message,filenameorfileinfo) {FileException myexcp(message, filenameorfileinfo); myexcp.setDebugInformation(__FILE__,__LINE__,__func__); throw myexcp;} + +# define THROWT(exception) {exception myexcp; myexcp.setDebugInformation(__FILE__,__LINE__,__func__); myexcp.setTranslatable(true); throw myexcp;} +# define THROWMT(exception, message) {exception myexcp(message); myexcp.setDebugInformation(__FILE__,__LINE__,__func__); myexcp.setTranslatable(true); throw myexcp;} +# define THROWMFT_FILEEXCEPTION(message,filenameorfileinfo) {FileException myexcp(message, filenameorfileinfo); myexcp.setDebugInformation(__FILE__,__LINE__,__func__); myexcp.setTranslatable(true); throw myexcp;} + #endif @@ -80,10 +108,13 @@ public: inline std::string getFile() const; inline int getLine() const; inline std::string getFunction() const; + inline bool getTranslatable() const; /// setter methods for including debug information /// intended to use via macro for autofilling of debugging information inline void setDebugInformation(const std::string & file, const int line, const std::string & function); + + inline void setTranslatable(const bool translatable); /// returns a Python dictionary containing the exception data virtual PyObject * getPyObject(void); /// returns sets the exception data from a Python dictionary @@ -106,6 +137,7 @@ protected: std::string _file; int _line; std::string _function; + bool _isTranslatable; }; @@ -620,6 +652,11 @@ inline std::string Exception::getFunction() const return _function; } +inline bool Exception::getTranslatable() const +{ + return _isTranslatable; +} + inline void Exception::setDebugInformation(const std::string & file, const int line, const std::string & function) { _file = file; @@ -627,6 +664,11 @@ inline void Exception::setDebugInformation(const std::string & file, const int l _function = function; } +inline void Exception::setTranslatable(const bool translatable) +{ + _isTranslatable = translatable; +} + #if defined(__GNUC__) && defined (FC_OS_LINUX) class SignalException { diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index a7ed5a943e..118bee966e 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -57,6 +57,7 @@ # include # include # include +//# include #endif #include @@ -4167,7 +4168,7 @@ bool SketchObject::modifyBSplineKnotMultiplicity(int GeoId, int knotIndex, int m int curmult = bsp->getMultiplicity(knotIndex); if ( (curmult + multiplicityincr) > degree ) // zero is removing the knot, degree is just positional continuity - THROWM(Base::ValueError,"The multiplicity cannot be increased beyond the degree of the b-spline."); + THROWM(Base::ValueError,QT_TRANSLATE_NOOP("Exceptions","The multiplicity cannot be increased beyond the degree of the b-spline.")); if ( (curmult + multiplicityincr) < 0) // zero is removing the knot, degree is just positional continuity THROWM(Base::ValueError,"The multiplicity cannot be decreased beyond zero.");