-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: Config_Translator.cpp
-// Created: 31 May 2016
-// Author: Vitaly SMETANNIKOV
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
#include "Config_Translator.h"
#include "Config_XMLReader.h"
{
std::string aContext = theInfo.context();
std::string aMessage = theInfo.messageString();
- return translate(aContext, aMessage);
+ std::list<std::string> aParameters = theInfo.parameters();
+ return translate(aContext, aMessage, aParameters);
+}
+
+std::string insertParameters(const std::string& theString, const std::list<std::string>& theParams)
+{
+ std::string aResult = theString;
+ std::list<std::string>::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<std::string>& 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;
}
return (myCodecs.count(theContext) > 0)? myCodecs[theContext] : "UTF-8";
}
+std::string Config_Translator::codec(const Events_InfoMessage& theInfo)
+{
+ return codec(theInfo.context());
+}
#ifdef _DEBUG
#ifdef MISSED_TRANSLATION
std::ofstream oFStream;
// Delete old file
- int aa = remove(aFile.c_str());
+ remove(aFile.c_str());
oFStream.open(aFile, std::ofstream::out | std::ofstream::app);
if (oFStream.is_open()) {