]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Translate strings with corresponded codec BR_internationalization
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 6 Jun 2016 16:32:37 +0000 (19:32 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 6 Jun 2016 16:32:37 +0000 (19:32 +0300)
src/Config/Config_Translator.cpp
src/Config/Config_Translator.h
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h
src/ModuleBase/ModuleBase_IModule.cpp
src/XGUI/XGUI_ErrorDialog.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_msg_fr.ts

index f21e8f6486dbe3eade7dda6ad7f9f189a649e3ad..9a03118fef50c818e2a5b952e9ef8eb31d151a07 100644 (file)
@@ -17,12 +17,14 @@ public:
   Config_TSReader(const std::string& theTSFile) : Config_XMLReader(theTSFile) {}
 
   const Config_Translator::Translator& translator() const { return myTranslator; }
+  const Config_Translator::Dictionary& codecs() const { return myCodecs; }
 
 protected:
   /// Overloaded method. Defines how to process each node
   virtual void processNode(xmlNodePtr theNode);
 private:
   Config_Translator::Translator myTranslator;
+  Config_Translator::Dictionary myCodecs;
 };
 
 void Config_TSReader::processNode(xmlNodePtr theNode)
@@ -35,6 +37,7 @@ void Config_TSReader::processNode(xmlNodePtr theNode)
     aName = "";
   } else if (isNode(theNode, "name", NULL)) {
     aName = getContent(theNode);
+    myCodecs[aName] = encoding();
   } else if (isNode(theNode, "message", NULL)) {
     aSource = "";
   } else if (isNode(theNode, "source", NULL)) {
@@ -50,6 +53,8 @@ void Config_TSReader::processNode(xmlNodePtr theNode)
 //******************************************************************************
 //******************************************************************************
 Config_Translator::Translator Config_Translator::myTranslator;
+Config_Translator::Dictionary Config_Translator::myCodecs;
+
 #ifdef _DEBUG
 #ifdef MISSED_TRANSLATION
 Config_Translator::Translator Config_Translator::myMissed;
@@ -78,6 +83,11 @@ bool Config_Translator::load(const std::string& theFileName)
     }
   }
 
+  const Dictionary aCodecs = aReader.codecs();
+  Dictionary::const_iterator aDictIt;
+  for (aDictIt = aCodecs.cbegin(); aDictIt != aCodecs.cend(); aDictIt++) {
+    myCodecs[aDictIt->first] = aDictIt->second;
+  }
   return true;
 }
 
@@ -136,6 +146,13 @@ std::string Config_Translator::translate(const std::string& theContext,
   return aMsg;
 }
 
+
+std::string Config_Translator::codec(const std::string& theContext)
+{ 
+  return (myCodecs.count(theContext) > 0)? myCodecs[theContext] : "UTF-8"; 
+}
+
+
 #ifdef _DEBUG
 #ifdef MISSED_TRANSLATION
 void Config_Translator::saveMissedTranslations()
index 9f989f9d0dac7e9caa5411e63aa1f416f8483286..72a305ec97803c1325baa2cdd3037dd6de78b084 100644 (file)
@@ -56,6 +56,13 @@ public:
     const std::string& theMessage, 
     const std::list<std::string>& theParams = std::list<std::string>());
 
+
+  /**
+  * Returns codec for the context
+  * \param theContext the context
+  */ 
+  static CONFIG_EXPORT std::string codec(const std::string& theContext);
+
 #ifdef _DEBUG
 #ifdef MISSED_TRANSLATION
   static CONFIG_EXPORT void saveMissedTranslations();
@@ -64,8 +71,12 @@ public:
 
 
 private:
+  /// A map of translations
   static Translator myTranslator;
 
+  /// aMap of codecs for contexts
+  static Dictionary myCodecs;
+
 #ifdef _DEBUG
 #ifdef MISSED_TRANSLATION
   static Translator myMissed;
index bdfaa583af7022ce135c0b4a91ad8213325f8874..1dab4ac3d46667278c11936eeba332ec55bb1b57 100644 (file)
@@ -199,3 +199,8 @@ bool Config_XMLReader::cleanupAttribute(const char* theNodeName, const char* the
   }
   return result;
 }
+
+const char* Config_XMLReader::encoding() const
+{ 
+  return (const char*) myXmlDoc->encoding; 
+}
\ No newline at end of file
index 62173af3155810e23726be7d22f34d3633e1fc87..851ff1b28c617c473dc4a830be518cfbd69d4125 100644 (file)
@@ -60,6 +60,8 @@ class Config_XMLReader
    */
   CONFIG_EXPORT xmlNodePtr findRoot();
 
+  CONFIG_EXPORT const char* encoding() const;
+
  protected:
   /*!
    * \brief Allows to customize reader's behavior for a node. Virtual.
index be4cc61a6ebd97085bc335dd34a21ff0b0f1d7f9..997c4134849595142d57bbe2c6d27cad00d83cc0 100644 (file)
@@ -31,6 +31,7 @@
 #include <QLayout>
 #include <QDialogButtonBox>
 #include <QPushButton>
+#include <QTextCodec>
 
 ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent)
   : QObject(theParent), myWorkshop(theParent) 
@@ -108,8 +109,11 @@ bool ModuleBase_IModule::canBeShaded(Handle(AIS_InteractiveObject) theAIS) const
 QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature)
 {
   QString aMsg = ModelAPI_Tools::getFeatureError(theFeature).c_str();
-  if (!aMsg.isEmpty())
-    aMsg = Config_Translator::translate(theFeature->getKind(), aMsg.toStdString()).c_str();
+  if (!aMsg.isEmpty()) {
+    std::string aStr = Config_Translator::translate(theFeature->getKind(), aMsg.toStdString()).c_str();
+    std::string aCodec = Config_Translator::codec(theFeature->getKind());
+    aMsg = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
+  }
   return aMsg;
 }
 
index 75df206519032f8ebc2100f37246b8dc0c51f0e5..04a3f5316c2f71e50b5e30cca4fc9f679d5a70d9 100644 (file)
@@ -16,6 +16,7 @@
 #include <QLabel>
 #include <QVBoxLayout>
 #include <QTextEdit>
+#include <QTextCodec>
 
 XGUI_ErrorDialog::XGUI_ErrorDialog(QWidget* parent)
     : QDialog(parent)
@@ -60,7 +61,9 @@ void XGUI_ErrorDialog::clear()
 void XGUI_ErrorDialog::addError(std::shared_ptr<Events_InfoMessage> theMsg)
 {
   std::string aError = Config_Translator::translate(theMsg);
-  myErrors.append(aError.c_str());
+  std::string aCodec = Config_Translator::codec(theMsg->context());
+  QString aMsg = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aError.c_str());
+  myErrors.append(aMsg);
   refresh();
   if (!isVisible()) {
     show();
index d7f38883ae936c3c8119f71402b5da68859a3f7f..88102925242baa5a61eff80d15f1280194679912 100755 (executable)
@@ -146,6 +146,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   QString aPath = Config_XMLReader::pluginConfigFile().c_str();
   QDir aDir(aPath);
 
+  // Load translations
   QStringList aFilters;
   aFilters << "*_en.ts";
   QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
index 070700a9ae2e3ff8f28c53736b6727c067478162..d0a8feced037cc2e309e27c06cb64d48b39227f5 100644 (file)
 <context>
     <name>XGUI_ErrorDialog</name>
     <message>
-        <location filename="XGUI_ErrorDialog.cpp" line="24"/>
+        <location filename="XGUI_ErrorDialog.cpp" line="25"/>
         <source>Application errors</source>
         <translation type="unfinished"></translation>
     </message>
 <context>
     <name>XGUI_Workshop</name>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="309"/>
-        <location filename="XGUI_Workshop.cpp" line="363"/>
+        <location filename="XGUI_Workshop.cpp" line="310"/>
+        <location filename="XGUI_Workshop.cpp" line="364"/>
         <source>Undo</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="310"/>
-        <location filename="XGUI_Workshop.cpp" line="363"/>
+        <location filename="XGUI_Workshop.cpp" line="311"/>
+        <location filename="XGUI_Workshop.cpp" line="364"/>
         <source>Undo last command</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="313"/>
+        <location filename="XGUI_Workshop.cpp" line="314"/>
         <source>INF_DESK_TOOLBAR_STANDARD</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="319"/>
-        <location filename="XGUI_Workshop.cpp" line="372"/>
+        <location filename="XGUI_Workshop.cpp" line="320"/>
+        <location filename="XGUI_Workshop.cpp" line="373"/>
         <source>Redo</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="319"/>
-        <location filename="XGUI_Workshop.cpp" line="372"/>
+        <location filename="XGUI_Workshop.cpp" line="320"/>
+        <location filename="XGUI_Workshop.cpp" line="373"/>
         <source>Redo last command</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="336"/>
+        <location filename="XGUI_Workshop.cpp" line="337"/>
         <source>Export native...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="336"/>
+        <location filename="XGUI_Workshop.cpp" line="337"/>
         <source>Export the current document into a native file</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="341"/>
+        <location filename="XGUI_Workshop.cpp" line="342"/>
         <source>Import native...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="341"/>
+        <location filename="XGUI_Workshop.cpp" line="342"/>
         <source>Import native file</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="353"/>
-        <location filename="XGUI_Workshop.cpp" line="841"/>
+        <location filename="XGUI_Workshop.cpp" line="354"/>
+        <location filename="XGUI_Workshop.cpp" line="842"/>
         <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="353"/>
+        <location filename="XGUI_Workshop.cpp" line="354"/>
         <source>Save the document</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="358"/>
+        <location filename="XGUI_Workshop.cpp" line="359"/>
         <source>Save as...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="358"/>
+        <location filename="XGUI_Workshop.cpp" line="359"/>
         <source>Save the document into a file</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="386"/>
+        <location filename="XGUI_Workshop.cpp" line="387"/>
         <source>Open...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="386"/>
+        <location filename="XGUI_Workshop.cpp" line="387"/>
         <source>Open a new document</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="390"/>
+        <location filename="XGUI_Workshop.cpp" line="391"/>
         <source>Preferences</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="390"/>
+        <location filename="XGUI_Workshop.cpp" line="391"/>
         <source>Edit preferences</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="394"/>
+        <location filename="XGUI_Workshop.cpp" line="395"/>
         <source>Exit</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="394"/>
+        <location filename="XGUI_Workshop.cpp" line="395"/>
         <source>Exit application</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="703"/>
-        <location filename="XGUI_Workshop.cpp" line="759"/>
+        <location filename="XGUI_Workshop.cpp" line="704"/>
+        <location filename="XGUI_Workshop.cpp" line="760"/>
         <source>Save current file</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="704"/>
+        <location filename="XGUI_Workshop.cpp" line="705"/>
         <source>The document is modified, save before opening another?</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="715"/>
+        <location filename="XGUI_Workshop.cpp" line="716"/>
         <source>Select directory</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="720"/>
+        <location filename="XGUI_Workshop.cpp" line="721"/>
         <source>Warning</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="720"/>
+        <location filename="XGUI_Workshop.cpp" line="721"/>
         <source>Unable to open the file.</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="759"/>
+        <location filename="XGUI_Workshop.cpp" line="760"/>
         <source>The document is modified, save before exit?</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="825"/>
+        <location filename="XGUI_Workshop.cpp" line="826"/>
         <source>Select directory to save files...</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="827"/>
+        <location filename="XGUI_Workshop.cpp" line="828"/>
         <source>Directories (*)</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="842"/>
+        <location filename="XGUI_Workshop.cpp" line="843"/>
         <source>The directory already contains some files, save anyway?</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="975"/>
+        <location filename="XGUI_Workshop.cpp" line="976"/>
         <source>Information about module &quot;%1&quot; doesn&apos;t exist.</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="1106"/>
+        <location filename="XGUI_Workshop.cpp" line="1107"/>
         <source>Object browser</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="1438"/>
+        <location filename="XGUI_Workshop.cpp" line="1439"/>
         <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="1476"/>
+        <location filename="XGUI_Workshop.cpp" line="1477"/>
         <source>All features are relevant, there is nothing to be deleted</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="1976"/>
+        <location filename="XGUI_Workshop.cpp" line="1977"/>
         <source>Find results</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="XGUI_Workshop.cpp" line="1977"/>
+        <location filename="XGUI_Workshop.cpp" line="1978"/>
         <source>Results not found</source>
         <translation type="unfinished"></translation>
     </message>