Salome HOME
Read translations
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 2 Jun 2016 12:46:21 +0000 (15:46 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 2 Jun 2016 12:46:21 +0000 (15:46 +0300)
src/Config/CMakeLists.txt
src/Config/Config_Common.cpp
src/Config/Config_Common.h
src/Config/Config_Translator.cpp
src/Config/Config_XMLReader.cpp
src/Events/CMakeLists.txt
src/Events/Events_InfoMessage.h
src/ParametersPlugin/ParametersPlugin_msg_ru.ts
src/SketchPlugin/CMakeLists.txt
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_msg_fr.ts

index 8952f175698a41860d1d7dafc09eeaeda13020fc..9d82189428ba94308282c6bc36af3658ae0d24ed 100644 (file)
@@ -24,6 +24,7 @@ SET(PROJECT_HEADERS
   Config_SelectionFilterMessage.h
   Config_ValidatorReader.h
   Config_DataModelReader.h
+  Config_Translator.h
  )
 
 SET(PROJECT_SOURCES
@@ -42,6 +43,7 @@ SET(PROJECT_SOURCES
   Config_SelectionFilterMessage.cpp
   Config_ValidatorReader.cpp
   Config_DataModelReader.cpp
+  Config_Translator.cpp
 )
 
 SET(XML_RESOURCES
index ce096355a766652d76447cd60d0a40ee58847b82..aaf1ed9cbc1e24d641f5d55303e3eb15a48aaef8 100644 (file)
@@ -225,10 +225,11 @@ bool BothAreSpaces(char lhs, char rhs) { return (lhs == rhs) && (lhs == ' '); }
 std::string getProperty(xmlNodePtr theNode, const char* thePropName)\r
 {\r
   std::string result = "";\r
-  char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST thePropName);\r
+  xmlChar* aPropChars = xmlGetProp(theNode, BAD_CAST thePropName);\r
   if (!aPropChars || aPropChars[0] == 0)\r
     return result;\r
-  result = std::string(aPropChars);\r
+  result = std::string((char*)aPropChars);\r
+  xmlFree(aPropChars);\r
 \r
   std::string::iterator new_end = std::unique(result.begin(), result.end(), BothAreSpaces);\r
   result.erase(new_end, result.end()); \r
@@ -236,6 +237,17 @@ std::string getProperty(xmlNodePtr theNode, const char* thePropName)
   return result;\r
 }\r
 \r
+std::string getContent(xmlNodePtr theNode)\r
+{\r
+  std::string result = "";\r
+  xmlChar* aContent = xmlNodeGetContent(theNode);\r
+  if (!aContent || aContent[0] == 0)\r
+    return result;\r
+  result = std::string((char*)aContent);\r
+  xmlFree(aContent);\r
+  return result;\r
+}\r
+\r
 std::string getNormalizedProperty(xmlNodePtr theNode, const char* thePropName)\r
 {\r
   return normalize(getProperty(theNode, thePropName));\r
index 52776d764f7623c1b75ea912f176d713e68e2b91..0998a6b73d6899c269951560757ee9fb559172c0 100644 (file)
@@ -111,6 +111,11 @@ CONFIG_EXPORT std::string library(const std::string& theLibName);
  */
 CONFIG_EXPORT std::string getProperty(xmlNodePtr theNode, const char* thePropName);
 
+/*!
+ * Returns content of the node as std::string if it is exists.
+ */
+CONFIG_EXPORT std::string getContent(xmlNodePtr theNode);
+
 /*!
  * Returns normalized (lower case) named property for a given node as std::string.
  */
index 9b03dc798e98ae5481370361c330c72296340e52..38bbf8bdda45b657cfe0cd9f64e9f9056241d2fd 100644 (file)
@@ -5,7 +5,8 @@
 // Author:      Vitaly SMETANNIKOV
 
 #include "Config_Translator.h"
-#include <Config_XMLReader.h>
+#include "Config_XMLReader.h"
+#include "Config_Common.h"
 
 class Config_TSReader : public Config_XMLReader
 {
@@ -23,8 +24,29 @@ private:
 
 void Config_TSReader::processNode(xmlNodePtr theNode)
 {
+  static std::string aName;
+  static std::string aSource;
+  std::string aTranslat;
+
+  if (isNode(theNode, "context", NULL)) {
+    aName = "";
+  } else if (isNode(theNode, "name", NULL)) {
+    aName = getContent(theNode);
+  } else if (isNode(theNode, "message", NULL)) {
+    aSource = "";
+  } else if (isNode(theNode, "source", NULL)) {
+    aSource = getContent(theNode);
+  } else if (isNode(theNode, "translation", NULL)) {
+    aTranslat = getContent(theNode);
+    if ((aName.size() > 0) && (aSource.size() > 0))
+      myTranslator[aName][aSource] = aTranslat;
+  }
 }
 
+//******************************************************************************
+//******************************************************************************
+//******************************************************************************
+Config_Translator::Translator Config_Translator::myTranslator;
 
 bool Config_Translator::load(const std::string& theFileName)
 {
@@ -33,7 +55,19 @@ bool Config_Translator::load(const std::string& theFileName)
 
   const Translator& aTranslator = aReader.translator();
   Translator::const_iterator aIt;
+  std::string aContext;
+  Dictionary aDictionary;
   for (aIt = aTranslator.cbegin(); aIt != aTranslator.cend(); aIt++) {
+    aContext = (*aIt).first;
+    aDictionary = (*aIt).second;
+    if (myTranslator.count(aContext) == 0) {
+      myTranslator[aContext] = aDictionary;
+    } else {
+      Dictionary::const_iterator aDictIt;
+      for (aDictIt = aDictionary.cbegin(); aDictIt != aDictionary.cend(); aDictIt++) {
+        myTranslator[aContext][(*aDictIt).first] = (*aDictIt).second;
+      }
+    }
   }
 
   return true;
@@ -41,5 +75,31 @@ bool Config_Translator::load(const std::string& theFileName)
 
 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();
+  if (myTranslator.count(aContext) > 0) {
+    if (myTranslator[aContext].count(aMessage) > 0) {
+      std::string aTranslation = myTranslator[aContext][aMessage];
+      if (aParameters.size() > 0) {
+        std::list<std::string>::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;
+          }
+        }
+      }
+      return aTranslation;
+    }
+  }
   return "";
 }
index 184fcdf61fa1656a7b395cf0d8ed6c0095f1b82c..1fcc90652b23220458ba0f987ef1c663da101f8a 100644 (file)
@@ -51,7 +51,8 @@ Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName)
 
   myDocumentPath = prefix + FSEP + theXmlFileName;
   std::ifstream aTestFile(myDocumentPath);
-  if (!aTestFile) Events_Error::send("Unable to open " + myDocumentPath);
+  if (!aTestFile) 
+    Events_Error::send("Unable to open " + myDocumentPath);
   aTestFile.close();
 }
 
index 5c5d99a083ae2547cbb8e5a31df90b34d050cc70..a747fd8724ca5899f65eeec86c765c3cc3d1d5b8 100644 (file)
@@ -13,6 +13,7 @@ SET(PROJECT_HEADERS
     Events_Loop.h
     Events_Error.h
     Events_LongOp.h
+       Events_InfoMessage.h
 )
 
 SET(PROJECT_SOURCES
index a38bec12487aba93f887b46fbe0b78333d4fed5c..5f745a98b7e51ecaed8af8a6e6fc24ef993e19e9 100644 (file)
 #include <Events_Message.h>
 #include <Events_Loop.h>
 
-class EVENTS_EXPORT Events_InfoMessage: public Events_Message
+class Events_InfoMessage: public Events_Message
 {
 public:
   Events_InfoMessage(const void* theSender = 0) : 
       Events_Message(Events_Loop::eventByName("InfoMessage"), theSender) {}
 
-  void setContext(const std::string& theContext) { myContext = theContext; } 
+  void  setContext(const std::string& theContext) { myContext = theContext; } 
 
   std::string context() const { return myContext; }
 
@@ -33,7 +33,7 @@ public:
   void addParameter(double theParam) 
   { 
     char aBuf[50];
-    int n = sprintf(aBuf, "%g", theParam);
+    int n = sprintf_s(aBuf, "%g", theParam);
     std::string aStr(aBuf);
     myParameters.push_back(aStr); 
   }
@@ -41,7 +41,7 @@ public:
   void addParameter(int theParam) 
   { 
     char aBuf[50];
-    int n = sprintf(aBuf, "%d", theParam);
+    int n = sprintf_s(aBuf, "%d", theParam);
     std::string aStr(aBuf);
     myParameters.push_back(aStr); 
   }
index ab1c74b8fdb648481809bb116f63f899ffa4afda..c1e212c698acac744243a5321a4911c14547e950 100644 (file)
@@ -24,8 +24,9 @@
         <translation>Коментарий</translation>
     </message>
     <message>
+        <location filename="ParametersPlugin_WidgetParamsMgr.cpp" line="188"/>
         <source>Parameters</source>
-        <translation type="obsolete">Параметры</translation>
+        <translation type="unfinished">Параметры</translation>
     </message>
     <message>
         <location filename="ParametersPlugin_WidgetParamsMgr.cpp" line="194"/>
@@ -62,9 +63,8 @@
 <context>
     <name>QObject</name>
     <message>
-        <location filename="ParametersPlugin_WidgetParamsMgr.cpp" line="188"/>
         <source>Parameters</source>
-        <translation type="unfinished">Параметры</translation>
+        <translation type="obsolete">Параметры</translation>
     </message>
 </context>
 </TS>
index 944181bf545293cd4a633adaaf7955a086510ca8..3e3924954c2e6fab50a4bb4492bc0f487f404b04 100644 (file)
@@ -89,8 +89,14 @@ SET(XML_RESOURCES
   plugin-Sketch.xml
 )
 
+SET(TEXT_RESOURCES
+       SketchPlugin_msg_en.ts
+)
+
+SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES})
+
 ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS)
-ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
+ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES} ${TEXT_RESOURCES})
 TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES})
 
 INCLUDE_DIRECTORIES(
@@ -106,6 +112,7 @@ INCLUDE_DIRECTORIES(
 INSTALL(TARGETS SketchPlugin DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES})
 INSTALL(FILES ${XML_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
 INSTALL(DIRECTORY icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Sketch)
+INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES})
 
 ADD_UNIT_TESTS(TestSketchPointLine.py
                TestSketchArcCircle.py
index 4421335641fc49ee9dfa88287449bfd0583fee93..e51516510f8e31a1b469b0b316ed38eb7f4d3c85 100755 (executable)
@@ -78,6 +78,7 @@
 #include <Config_PropManager.h>
 #include <Config_SelectionFilterMessage.h>
 #include <Config_DataModelReader.h>
+#include <Config_Translator.h>
 
 #include <SUIT_ResourceMgr.h>
 
@@ -135,6 +136,15 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   else 
     QLocale::setDefault( QLocale::system() );
 #endif
+  QString aPath = Config_XMLReader::pluginConfigFile().c_str();
+  QDir aDir(aPath);
+
+  QStringList aFilters;
+  aFilters << "*_en.ts";
+  QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
+  foreach(QString aFileName, aTsFiles) {
+    Config_Translator::load(aFileName.toStdString());
+  }
 
   myDataModelXMLReader = new Config_DataModelReader();
   myDataModelXMLReader->readAll();
index a543dd3da65c2b6b98e04ed073402416f207c5aa..9f2fa39723004a00f2898651c8189905f63e20b2 100644 (file)
@@ -19,7 +19,7 @@
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="112"/>
+        <location filename="XGUI_Workshop.cpp" line="113"/>
         <source>Move to the end</source>
         <translation type="unfinished"></translation>
     </message>
 <context>
     <name>XGUI_Workshop</name>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="290"/>
-        <location filename="XGUI_Workshop.cpp" line="344"/>
+        <location filename="XGUI_Workshop.cpp" line="300"/>
+        <location filename="XGUI_Workshop.cpp" line="354"/>
         <source>Undo</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="291"/>
-        <location filename="XGUI_Workshop.cpp" line="344"/>
+        <location filename="XGUI_Workshop.cpp" line="301"/>
+        <location filename="XGUI_Workshop.cpp" line="354"/>
         <source>Undo last command</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="294"/>
+        <location filename="XGUI_Workshop.cpp" line="304"/>
         <source>INF_DESK_TOOLBAR_STANDARD</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="300"/>
-        <location filename="XGUI_Workshop.cpp" line="353"/>
+        <location filename="XGUI_Workshop.cpp" line="310"/>
+        <location filename="XGUI_Workshop.cpp" line="363"/>
         <source>Redo</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="300"/>
-        <location filename="XGUI_Workshop.cpp" line="353"/>
+        <location filename="XGUI_Workshop.cpp" line="310"/>
+        <location filename="XGUI_Workshop.cpp" line="363"/>
         <source>Redo last command</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="317"/>
+        <location filename="XGUI_Workshop.cpp" line="327"/>
         <source>Export native...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="317"/>
+        <location filename="XGUI_Workshop.cpp" line="327"/>
         <source>Export the current document into a native file</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="322"/>
+        <location filename="XGUI_Workshop.cpp" line="332"/>
         <source>Import native...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="322"/>
+        <location filename="XGUI_Workshop.cpp" line="332"/>
         <source>Import native file</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="334"/>
-        <location filename="XGUI_Workshop.cpp" line="823"/>
+        <location filename="XGUI_Workshop.cpp" line="344"/>
+        <location filename="XGUI_Workshop.cpp" line="833"/>
         <source>Save</source>
         <extracomment>Title of the dialog which asks user if he wants to save study in existing non-empty folder</extracomment>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="334"/>
+        <location filename="XGUI_Workshop.cpp" line="344"/>
         <source>Save the document</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="339"/>
+        <location filename="XGUI_Workshop.cpp" line="349"/>
         <source>Save as...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="339"/>
+        <location filename="XGUI_Workshop.cpp" line="349"/>
         <source>Save the document into a file</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="367"/>
+        <location filename="XGUI_Workshop.cpp" line="377"/>
         <source>Open...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="367"/>
+        <location filename="XGUI_Workshop.cpp" line="377"/>
         <source>Open a new document</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="371"/>
+        <location filename="XGUI_Workshop.cpp" line="381"/>
         <source>Preferences</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="371"/>
+        <location filename="XGUI_Workshop.cpp" line="381"/>
         <source>Edit preferences</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="375"/>
+        <location filename="XGUI_Workshop.cpp" line="385"/>
         <source>Exit</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="375"/>
+        <location filename="XGUI_Workshop.cpp" line="385"/>
         <source>Exit application</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="685"/>
-        <location filename="XGUI_Workshop.cpp" line="741"/>
+        <location filename="XGUI_Workshop.cpp" line="695"/>
+        <location filename="XGUI_Workshop.cpp" line="751"/>
         <source>Save current file</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="686"/>
+        <location filename="XGUI_Workshop.cpp" line="696"/>
         <source>The document is modified, save before opening another?</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="697"/>
+        <location filename="XGUI_Workshop.cpp" line="707"/>
         <source>Select directory</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="702"/>
+        <location filename="XGUI_Workshop.cpp" line="712"/>
         <source>Warning</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="702"/>
+        <location filename="XGUI_Workshop.cpp" line="712"/>
         <source>Unable to open the file.</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="741"/>
+        <location filename="XGUI_Workshop.cpp" line="751"/>
         <source>The document is modified, save before exit?</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="807"/>
+        <location filename="XGUI_Workshop.cpp" line="817"/>
         <source>Select directory to save files...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="809"/>
+        <location filename="XGUI_Workshop.cpp" line="819"/>
         <source>Directories (*)</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="824"/>
+        <location filename="XGUI_Workshop.cpp" line="834"/>
         <source>The directory already contains some files, save anyway?</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="957"/>
+        <location filename="XGUI_Workshop.cpp" line="967"/>
         <source>Information about module &quot;%1&quot; doesn&apos;t exist.</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="1088"/>
+        <location filename="XGUI_Workshop.cpp" line="1098"/>
         <source>Object browser</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="1420"/>
+        <location filename="XGUI_Workshop.cpp" line="1430"/>
         <source>Unused features are the following: %1.
 These features will be deleted.
 Would you like to continue?</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="1458"/>
+        <location filename="XGUI_Workshop.cpp" line="1468"/>
         <source>All features are relevant, there is nothing to be deleted</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="1958"/>
+        <location filename="XGUI_Workshop.cpp" line="1968"/>
         <source>Find results</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="1959"/>
+        <location filename="XGUI_Workshop.cpp" line="1969"/>
         <source>Results not found</source>
         <translation type="unfinished"></translation>
     </message>