From: vsv Date: Fri, 3 Jun 2016 16:30:32 +0000 (+0300) Subject: Send information message for translation X-Git-Tag: V_2.4.0~139^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=765ac761dcec18f400b635f184df8bea6f201462;p=modules%2Fshaper.git Send information message for translation --- diff --git a/src/Config/Config_DataModelReader.cpp b/src/Config/Config_DataModelReader.cpp index b02ae823c..22c6608f7 100644 --- a/src/Config/Config_DataModelReader.cpp +++ b/src/Config/Config_DataModelReader.cpp @@ -12,6 +12,7 @@ #include "Config_Common.h" #include +#include Config_DataModelReader::Config_DataModelReader() @@ -29,7 +30,7 @@ void Config_DataModelReader::processNode(xmlNodePtr theNode) std::string aName = getProperty(theNode, FOLDER_NAME); std::string aGroupType = getProperty(theNode, GROUP_TYPE); if (aName.empty() || aGroupType.empty()) - Events_Error::send("Reading dataModel.xml: wrong folder definition"); + Events_InfoMessage("Config_DataModelReader", "Reading dataModel.xml: wrong folder definition.").send(); std::string aIcon = getProperty(theNode, NODE_ICON); std::string aEmpty = getProperty(theNode, SHOW_EMPTY); diff --git a/src/Config/Config_Translator.cpp b/src/Config/Config_Translator.cpp index 38bbf8bdd..bf105efe4 100644 --- a/src/Config/Config_Translator.cpp +++ b/src/Config/Config_Translator.cpp @@ -73,33 +73,52 @@ bool Config_Translator::load(const std::string& theFileName) return true; } -std::string Config_Translator::translate(const Events_InfoMessage& theInfo) +std::string Config_Translator::translate(std::shared_ptr theInfo) { - std::string aContext = theInfo.context(); - std::string aMessage = theInfo.message(); - std::list aParameters = theInfo.parameters(); - if (myTranslator.count(aContext) > 0) { - if (myTranslator[aContext].count(aMessage) > 0) { - std::string aTranslation = myTranslator[aContext][aMessage]; - if (aParameters.size() > 0) { - std::list::const_iterator aIt; - int i; - char aBuf[20]; - std::string aParam; - for (i=1, aIt = aParameters.cbegin(); aIt != aParameters.cend(); aIt++, i++) { - aParam = (*aIt); - sprintf(aBuf, "%d ", i); - std::string aCode = std::string("%") + std::string(aBuf); - size_t aPos = aTranslation.find(aCode); - if (aPos != std::string::npos) { - std::string aFirst = aTranslation.substr(0, aPos); - std::string aLast = aTranslation.substr(aPos + aCode.length(), std::string::npos); - aTranslation = aFirst + aParam + aLast; - } - } + std::string aContext = theInfo->context(); + std::string aMessage = theInfo->message(); + std::list aParameters = theInfo->parameters(); + return translate(aContext, aMessage, aParameters); +} + + +std::string insertParameters(const std::string& theString, const std::list& theParams) +{ + std::string aResult = theString; + std::list::const_iterator aIt; + int i; + char aBuf[20]; + std::string aParam; + for (i=1, aIt = theParams.cbegin(); aIt != theParams.cend(); aIt++, i++) { + aParam = (*aIt); + sprintf_s(aBuf, "%d", i); + std::string aCode = std::string("%") + std::string(aBuf); + size_t aPos = aResult.find(aCode); + if (aPos != std::string::npos) { + std::string aFirst = aResult.substr(0, aPos); + std::string aLast = aResult.substr(aPos + aCode.length(), std::string::npos); + aResult = aFirst + aParam + aLast; + } + } + return aResult; +} + +std::string Config_Translator::translate(const std::string& theContext, + const std::string& theMessage, + const std::list& theParams) +{ + if (myTranslator.count(theContext) > 0) { + if (myTranslator[theContext].count(theMessage) > 0) { + std::string aTranslation = myTranslator[theContext][theMessage]; + if (theParams.size() > 0) { + aTranslation = insertParameters(aTranslation, theParams); } return aTranslation; } } - return ""; + std::string aMsg = theMessage; + if (theParams.size() > 0) { + aMsg = insertParameters(aMsg, theParams); + } + return aMsg; } diff --git a/src/Config/Config_Translator.h b/src/Config/Config_Translator.h index 43350f8f3..4365ec752 100644 --- a/src/Config/Config_Translator.h +++ b/src/Config/Config_Translator.h @@ -13,6 +13,12 @@ #include #include +/** + * \class Config_Translator + * \ingroup Config + * \brief Class for messages translation on different languages. It can load TS + * files wich contain translation string and provides translations of messages from source code + */ class Config_Translator { public: @@ -34,7 +40,19 @@ public: * from the info data without translation * \param theInfo an info message */ - static CONFIG_EXPORT std::string translate(const Events_InfoMessage& theInfo); + static CONFIG_EXPORT std::string translate(std::shared_ptr theInfo); + + /** + * Returns translation from the given data. + * If transdlation is not exists then it returns a string + * from the info data without translation + * \param theContext context of the message (Feature Id) + * \param theMessage a message which dave to be translated + * \param theParams a list of parameters (can be empty) + */ + static CONFIG_EXPORT std::string translate(const std::string& theContext, + const std::string& theMessage, + const std::list& theParams = std::list()); private: static Translator myTranslator; diff --git a/src/Events/Events_InfoMessage.h b/src/Events/Events_InfoMessage.h index 5f745a98b..bf92b3af3 100644 --- a/src/Events/Events_InfoMessage.h +++ b/src/Events/Events_InfoMessage.h @@ -11,25 +11,55 @@ #include #include +/**\class Events_InfoMessage + * \ingroup EventsLoop + * \brief An event message for sending a string message which has to be translated. + */ class Events_InfoMessage: public Events_Message { public: - Events_InfoMessage(const void* theSender = 0) : - Events_Message(Events_Loop::eventByName("InfoMessage"), theSender) {} + /// Constructor + /// \param theSender a pointer on sender object + Events_InfoMessage(const void* theSender = 0):Events_Message(Events_Loop::eventByName("InfoMessage"), theSender) {} + + /// Constructor + /// \param theSender a pointer on sender object + Events_InfoMessage(const std::string& theContext, + const std::string& theMsg, const void* theSender = 0): + Events_Message(Events_Loop::eventByName("InfoMessage"), theSender), + myContext(theContext), myMessage(theMsg) {} + + /// default destructor + virtual ~Events_InfoMessage() {} + + /// Identifier of this event (one for all errors) + static Events_ID errorID() { return Events_Loop::loop()->eventByName("InfoMessage"); } + + /// Set a context string + /// \param theContext a context string void setContext(const std::string& theContext) { myContext = theContext; } + + /// Returns context string std::string context() const { return myContext; } + /// Set message string for translation + /// \param theMsg the string of message void setMessage(const std::string& theMsg) { myMessage = theMsg; } + /// Returns message std::string message() const { return myMessage; } + /// Add parameter for message string of string type + /// \param theParam the parameter void addParameter(const std::string& theParam) { myParameters.push_back(theParam); } + /// Add parameter for message string of double type + /// \param theParam the parameter void addParameter(double theParam) { char aBuf[50]; @@ -38,6 +68,8 @@ public: myParameters.push_back(aStr); } + /// Add parameter for message string of integer type + /// \param theParam the parameter void addParameter(int theParam) { char aBuf[50]; @@ -46,8 +78,26 @@ public: myParameters.push_back(aStr); } + /// Returns list of parameters std::list parameters() const { return myParameters; } + /// Add parameter for message string of string type + /// \param theParam the parameter + Events_InfoMessage& arg(const std::string& theParam) { addParameter(theParam); return *this; } + + /// Add parameter for message string of integer type + /// \param theParam the parameter + Events_InfoMessage& arg(int theParam) { addParameter(theParam); return *this; } + + /// Add parameter for message string of double type + /// \param theParam the parameter + Events_InfoMessage& arg(double theParam) { addParameter(theParam); return *this; } + + void send() { + std::shared_ptr aMsg(new Events_InfoMessage(*this)); + Events_Loop::loop()->send(aMsg); + } + private: /// Context of the messgae diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 1bbf8d2fb..93a8870b0 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -37,7 +37,7 @@ static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay"; /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage) static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched"; /// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage) -static const char * EVENT_PLUGIN_LOADED = "PliginLoaded"; +static const char * EVENT_PLUGIN_LOADED = "PluginLoaded"; // static const char * EVENT_DOCUMENT_CHANGED = "CurrentDocumentChanged"; diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index fa0395ad9..be4cc61a6 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -106,7 +107,10 @@ bool ModuleBase_IModule::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature) { - return ModelAPI_Tools::getFeatureError(theFeature).c_str(); + QString aMsg = ModelAPI_Tools::getFeatureError(theFeature).c_str(); + if (!aMsg.isEmpty()) + aMsg = Config_Translator::translate(theFeature->getKind(), aMsg.toStdString()).c_str(); + return aMsg; } void ModuleBase_IModule::grantedOperationIds(ModuleBase_Operation* theOperation, diff --git a/src/SketchPlugin/SketchPlugin_msg_en.ts b/src/SketchPlugin/SketchPlugin_msg_en.ts index bd3f891bb..8703b5879 100644 --- a/src/SketchPlugin/SketchPlugin_msg_en.ts +++ b/src/SketchPlugin/SketchPlugin_msg_en.ts @@ -5,7 +5,7 @@ SketchConstraintVertical Model_FeatureValidator: Attribute "ConstraintEntityA" is not initialized. - Line for constraint is not selected. + Select a line for the constraint definition. ModelAPI_StateInvalidArgument diff --git a/src/XGUI/XGUI_ErrorDialog.cpp b/src/XGUI/XGUI_ErrorDialog.cpp index d389e3b3f..75df20651 100644 --- a/src/XGUI/XGUI_ErrorDialog.cpp +++ b/src/XGUI/XGUI_ErrorDialog.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -56,9 +57,10 @@ void XGUI_ErrorDialog::clear() QDialog::reject(); } -void XGUI_ErrorDialog::addError(const QString& theError) +void XGUI_ErrorDialog::addError(std::shared_ptr theMsg) { - myErrors.append(theError); + std::string aError = Config_Translator::translate(theMsg); + myErrors.append(aError.c_str()); refresh(); if (!isVisible()) { show(); diff --git a/src/XGUI/XGUI_ErrorDialog.h b/src/XGUI/XGUI_ErrorDialog.h index b6f53e6bc..3e3bb325a 100644 --- a/src/XGUI/XGUI_ErrorDialog.h +++ b/src/XGUI/XGUI_ErrorDialog.h @@ -14,6 +14,7 @@ #include class QTextEdit; +class Events_InfoMessage; /** * \ingroup GUI @@ -36,7 +37,7 @@ Q_OBJECT XGUI_EXPORT void clear(); /// Add error message - XGUI_EXPORT void addError(const QString&); + XGUI_EXPORT void addError(std::shared_ptr theMsg); /// Remove error message XGUI_EXPORT void removeError(const QString&); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 8fd52e598..9fab49052 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -31,8 +31,6 @@ XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop) { XGUI_SelectionMgr* aSelector = myWorkshop->selector(); connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); - - XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr(); } XGUI_ModuleConnector::~XGUI_ModuleConnector() diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index e51516510..61bb0e22a 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -126,6 +126,13 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) myDisplayer(0) //myViewerSelMode(TopAbs_FACE) { + mySelector = new XGUI_SelectionMgr(this); + myModuleConnector = new XGUI_ModuleConnector(this); + myOperationMgr = new XGUI_OperationMgr(this, 0); + ModuleBase_IWorkshop* aWorkshop = moduleConnector(); + // Has to be defined first in order to get errors and messages from other components + myEventsListener = new XGUI_WorkshopListener(aWorkshop); + #ifndef HAVE_SALOME myMainWindow = new AppElements_MainWindow(); @@ -147,14 +154,12 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) } myDataModelXMLReader = new Config_DataModelReader(); - myDataModelXMLReader->readAll(); + //myDataModelXMLReader->readAll(); myDisplayer = new XGUI_Displayer(this); - mySelector = new XGUI_SelectionMgr(this); connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateCommandStatus())); - myOperationMgr = new XGUI_OperationMgr(this, 0); myActionsMgr = new XGUI_ActionsMgr(this); myMenuMgr = new XGUI_MenuMgr(this); myErrorDlg = new XGUI_ErrorDialog(QApplication::desktop()); @@ -166,13 +171,9 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) //connect(myViewerProxy, SIGNAL(selectionChanged()), // myActionsMgr, SLOT(updateOnViewSelection())); - myModuleConnector = new XGUI_ModuleConnector(this); - - ModuleBase_IWorkshop* aWorkshop = moduleConnector(); myOperationMgr->setWorkshop(aWorkshop); myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop); - myEventsListener = new XGUI_WorkshopListener(aWorkshop); connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)), SLOT(onOperationStarted(ModuleBase_Operation*))); @@ -190,9 +191,8 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) onTrihedronVisibilityChanged(true); #endif - connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&))); - connect(myEventsListener, SIGNAL(errorOccurred(const QString&)), - myErrorDlg, SLOT(addError(const QString&))); + connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr)), + myErrorDlg, SLOT(addError(std::shared_ptr))); //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color", // Config_Prop::Color, "225,225,225"); @@ -224,13 +224,15 @@ XGUI_Workshop::~XGUI_Workshop(void) //****************************************************** void XGUI_Workshop::startApplication() { + //Initialize event listening + myEventsListener->initializeEventListening(); + + myDataModelXMLReader->readAll(); initMenu(); Config_PropManager::registerProp("Plugins", "default_path", "Default Path", Config_Prop::Directory, ""); - //Initialize event listening - myEventsListener->initializeEventListening(); registerValidators(); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 835816cf4..fea7600a0 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -306,9 +306,6 @@ signals: /// Emitted when selection happens in Salome viewer void salomeViewerSelection(); - /// Emitted when error in application happens - void errorOccurred(const QString&); - //! the signal about the workshop actions states are updated. void commandStatusUpdated(); diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index e9e3e3601..567ecc63a 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -82,7 +83,8 @@ void XGUI_WorkshopListener::initializeEventListening() { //Initialize event listening Events_Loop* aLoop = Events_Loop::loop(); - aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors. + //aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors. + aLoop->registerListener(this, Events_InfoMessage::errorID()); //!< Listening application errors. aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); @@ -186,9 +188,9 @@ void XGUI_WorkshopListener::processEvent(const std::shared_ptr& aDisplayer->enableUpdateViewer(true); } else { //Show error dialog if error message received. - std::shared_ptr anAppError = std::dynamic_pointer_cast(theMessage); - if (anAppError) { - emit errorOccurred(QString::fromLatin1(anAppError->description())); + std::shared_ptr anIngfoMsg = std::dynamic_pointer_cast(theMessage); + if (anIngfoMsg) { + emit errorOccurred(anIngfoMsg); } return; } diff --git a/src/XGUI/XGUI_WorkshopListener.h b/src/XGUI/XGUI_WorkshopListener.h index 5358253b5..7da355e2e 100755 --- a/src/XGUI/XGUI_WorkshopListener.h +++ b/src/XGUI/XGUI_WorkshopListener.h @@ -8,6 +8,7 @@ #include #include +#include #include @@ -19,6 +20,7 @@ class XGUI_Workshop; class ModuleBase_IWorkshop; class QString; +class Events_InfoMessage; /**\class XGUI_WorkshopListener * \ingroup GUI @@ -41,7 +43,7 @@ public: signals: /// Emitted when error in applivation happens - void errorOccurred(const QString&); + void errorOccurred(std::shared_ptr theMsg); protected: /// Procedure to process postponed events diff --git a/src/XGUI/XGUI_msg_fr.ts b/src/XGUI/XGUI_msg_fr.ts index 9f2fa3972..a47614eca 100644 --- a/src/XGUI/XGUI_msg_fr.ts +++ b/src/XGUI/XGUI_msg_fr.ts @@ -141,7 +141,7 @@ XGUI_ErrorDialog - + Application errors @@ -185,181 +185,181 @@ XGUI_Workshop - - + + Undo - - + + Undo last command - + INF_DESK_TOOLBAR_STANDARD - - + + Redo - - + + Redo last command - + Export native... - + Export the current document into a native file - + Import native... - + Import native file - - + + Save Title of the dialog which asks user if he wants to save study in existing non-empty folder - + Save the document - + Save as... - + Save the document into a file - + Open... - + Open a new document - + Preferences - + Edit preferences - + Exit - + Exit application - - + + Save current file - + The document is modified, save before opening another? - + Select directory - + Warning - + Unable to open the file. - + The document is modified, save before exit? - + Select directory to save files... - + Directories (*) - + The directory already contains some files, save anyway? - + Information about module "%1" doesn't exist. - + Object browser - + Unused features are the following: %1. These features will be deleted. Would you like to continue? - + All features are relevant, there is nothing to be deleted - + Find results - + Results not found