From: vsv Date: Wed, 9 Nov 2016 09:20:05 +0000 (+0300) Subject: Issue #1843: Set parameters to message on request of the message string X-Git-Tag: V_2.6.0~108 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ed9f679c423679977166e719ff1f8eafb394174a;p=modules%2Fshaper.git Issue #1843: Set parameters to message on request of the message string --- diff --git a/src/Config/Config_Translator.cpp b/src/Config/Config_Translator.cpp index cbc1a2776..c292159bd 100644 --- a/src/Config/Config_Translator.cpp +++ b/src/Config/Config_Translator.cpp @@ -109,55 +109,25 @@ std::string Config_Translator::translate(const Events_InfoMessage& theInfo) { std::string aContext = theInfo.context(); std::string aMessage = theInfo.messageString(); - 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(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; + return translate(aContext, aMessage); } std::string Config_Translator::translate(const std::string& theContext, - const std::string& theMessage, - const std::list& theParams) + const std::string& theMessage) { 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); - } if (aTranslation.size() > 0) return aTranslation; } } - std::string aMsg = theMessage; - if (theParams.size() > 0) { - aMsg = insertParameters(aMsg, theParams); - } #ifdef _DEBUG #ifdef MISSED_TRANSLATION myMissed[theContext][theMessage] = ""; #endif #endif - return aMsg; + return theMessage; } diff --git a/src/Config/Config_Translator.h b/src/Config/Config_Translator.h index 158091be3..6a07ffcda 100644 --- a/src/Config/Config_Translator.h +++ b/src/Config/Config_Translator.h @@ -55,8 +55,7 @@ public: * \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()); + const std::string& theMessage); /** diff --git a/src/Events/Events_InfoMessage.cpp b/src/Events/Events_InfoMessage.cpp index e2a4d9882..92e4c7c25 100644 --- a/src/Events/Events_InfoMessage.cpp +++ b/src/Events/Events_InfoMessage.cpp @@ -31,3 +31,30 @@ void Events_InfoMessage::send() std::shared_ptr aMsg(new Events_InfoMessage(*this)); Events_Loop::loop()->send(aMsg); } + + +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(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 Events_InfoMessage::messageString() const +{ + return insertParameters(myMessage, myParameters); +} diff --git a/src/Events/Events_InfoMessage.h b/src/Events/Events_InfoMessage.h index 2924df181..77ebdb1c4 100644 --- a/src/Events/Events_InfoMessage.h +++ b/src/Events/Events_InfoMessage.h @@ -52,7 +52,7 @@ public: void setMessageString(const std::string& theMsg) { myMessage = theMsg; } /// Returns message - std::string messageString() const { return myMessage; } + EVENTS_EXPORT std::string messageString() const; Events_InfoMessage& operator=(const std::string& theMsg) { setMessageString(theMsg);