From: dbv Date: Mon, 21 Nov 2016 08:15:24 +0000 (+0300) Subject: Revert "Issue #1843: Set parameters to message on request of the message string" X-Git-Tag: V_2.6.0~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f396e787993889d837917065a7752e3326194361;p=modules%2Fshaper.git Revert "Issue #1843: Set parameters to message on request of the message string" This reverts commit ed9f679c423679977166e719ff1f8eafb394174a. --- diff --git a/src/Config/Config_Translator.cpp b/src/Config/Config_Translator.cpp index 3760faca3..420319988 100644 --- a/src/Config/Config_Translator.cpp +++ b/src/Config/Config_Translator.cpp @@ -109,25 +109,55 @@ std::string Config_Translator::translate(const Events_InfoMessage& theInfo) { std::string aContext = theInfo.context(); std::string aMessage = theInfo.messageString(); - return translate(aContext, aMessage); + 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; } std::string Config_Translator::translate(const std::string& theContext, - const std::string& theMessage) + 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); + } 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 theMessage; + return aMsg; } diff --git a/src/Config/Config_Translator.h b/src/Config/Config_Translator.h index 6a07ffcda..158091be3 100644 --- a/src/Config/Config_Translator.h +++ b/src/Config/Config_Translator.h @@ -55,7 +55,8 @@ 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::string& theMessage, + const std::list& theParams = std::list()); /** diff --git a/src/Events/Events_InfoMessage.cpp b/src/Events/Events_InfoMessage.cpp index 54324c1ec..38190e4e2 100644 --- a/src/Events/Events_InfoMessage.cpp +++ b/src/Events/Events_InfoMessage.cpp @@ -31,30 +31,3 @@ 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 1bfd9a232..715c00e59 100644 --- a/src/Events/Events_InfoMessage.h +++ b/src/Events/Events_InfoMessage.h @@ -53,7 +53,7 @@ public: void setMessageString(const std::string& theMsg) { myMessage = theMsg; } /// Returns message - EVENTS_EXPORT std::string messageString() const; + std::string messageString() const { return myMessage; } Events_InfoMessage& operator=(const std::string& theMsg) { setMessageString(theMsg);