Salome HOME
updated copyright message
[modules/shaper.git] / src / Config / Config_Translator.cpp
index 9a03118fef50c818e2a5b952e9ef8eb31d151a07..e9764a5be99aada81a9204e743568a74996d9248 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        Config_Translator.cpp
-// Created:     31 May 2016
-// Author:      Vitaly SMETANNIKOV
+// Copyright (C) 2014-2023  CEA, EDF
+//
+// 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
+//
 
 #include "Config_Translator.h"
 #include "Config_XMLReader.h"
 #include <fstream>
 #include <ostream>
 
+#ifdef WIN32
+#pragma warning(disable : 4996) // for sprintf
+#endif
+
+// LCOV_EXCL_START
+/**
+ * \class Config_TSReader
+ * \ingroup Config
+ * \brief Class for reading translations from TS files (an XML format).
+ */
 class Config_TSReader : public Config_XMLReader
 {
 public:
+  /// Constructor
+  /// \param theTSFile name of TS file
   Config_TSReader(const std::string& theTSFile) : Config_XMLReader(theTSFile) {}
 
+  /// Returns content of TS file
   const Config_Translator::Translator& translator() const { return myTranslator; }
+
+  /// Returns codecs defined in TS files
   const Config_Translator::Dictionary& codecs() const { return myCodecs; }
 
 protected:
@@ -90,16 +118,16 @@ bool Config_Translator::load(const std::string& theFileName)
   }
   return true;
 }
+// LCOV_EXCL_STOP
 
-std::string Config_Translator::translate(std::shared_ptr<Events_InfoMessage> theInfo)
+std::string Config_Translator::translate(const Events_InfoMessage& theInfo)
 {
-  std::string aContext = theInfo->context();
-  std::string aMessage = theInfo->message();
-  std::list<std::string> aParameters = theInfo->parameters();
+  std::string aContext = theInfo.context();
+  std::string aMessage = theInfo.messageString();
+  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;
@@ -109,7 +137,7 @@ std::string insertParameters(const std::string& theString, const std::list<std::
   std::string aParam;
   for (i=1, aIt = theParams.cbegin(); aIt != theParams.cend(); aIt++, i++) {
     aParam = (*aIt);
-    sprintf_s(aBuf, "%d", i);
+    sprintf(aBuf, "%d", i);
     std::string aCode = std::string("%") + std::string(aBuf);
     size_t aPos = aResult.find(aCode);
     if (aPos != std::string::npos) {
@@ -122,7 +150,7 @@ std::string insertParameters(const std::string& theString, const std::list<std::
 }
 
 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) {
@@ -131,7 +159,8 @@ std::string Config_Translator::translate(const std::string& theContext,
       if (theParams.size() > 0) {
         aTranslation = insertParameters(aTranslation, theParams);
       }
-      return aTranslation;
+      if (aTranslation.size() > 0)
+        return aTranslation;
     }
   }
   std::string aMsg = theMessage;
@@ -146,12 +175,17 @@ std::string Config_Translator::translate(const std::string& theContext,
   return aMsg;
 }
 
-
+// LCOV_EXCL_START
 std::string Config_Translator::codec(const std::string& theContext)
-{ 
-  return (myCodecs.count(theContext) > 0)? myCodecs[theContext] : "UTF-8"; 
+{
+  return (myCodecs.count(theContext) > 0)? myCodecs[theContext] : "UTF-8";
 }
 
+std::string Config_Translator::codec(const Events_InfoMessage& theInfo)
+{
+  return codec(theInfo.context());
+}
+// LCOV_EXCL_STOP
 
 #ifdef _DEBUG
 #ifdef MISSED_TRANSLATION
@@ -169,7 +203,7 @@ void Config_Translator::saveMissedTranslations()
   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()) {