]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1005: To improve user-friendship of error-messages for features and attributes
authordbv <dbv@opencascade.com>
Mon, 5 Dec 2016 13:19:44 +0000 (16:19 +0300)
committerdbv <dbv@opencascade.com>
Mon, 5 Dec 2016 13:20:00 +0000 (16:20 +0300)
Improved translation mechanism.

src/Config/Config_FeatureReader.cpp
src/Config/Config_Translator.h
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_msg_en.ts
src/FeaturesPlugin/FeaturesPlugin_msg_ru.ts [new file with mode: 0644]
src/FeaturesPlugin/boolean_widget.xml
src/FeaturesPlugin/plugin-Features.xml
src/ModuleBase/ModuleBase_ActionInfo.cpp
src/ModuleBase/ModuleBase_IModule.cpp
src/XGUI/XGUI_Workshop.cpp

index 5427e7dd3aa303a985197048a435877d48bb2e5e..036631731e297d9d07f92178f22bea03b54ed713 100644 (file)
@@ -12,6 +12,7 @@
 #include <Config_FeatureMessage.h>
 #include <Config_AttributeMessage.h>
 #include <Config_FeatureReader.h>
+#include <Config_Translator.h>
 #include <Events_Message.h>
 #include <Events_Loop.h>
 
@@ -137,7 +138,8 @@ bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
 void Config_FeatureReader::fillFeature(xmlNodePtr theFeatureNode,
   const std::shared_ptr<Config_FeatureMessage>& outFeatureMessage)
 {
-  outFeatureMessage->setId(getProperty(theFeatureNode, _ID));
+  std::string anId = getProperty(theFeatureNode, _ID);
+  outFeatureMessage->setId(anId);
   outFeatureMessage->setPluginLibrary(myLibraryName);
   outFeatureMessage->setNestedFeatures(getProperty(theFeatureNode, FEATURE_NESTED));
   outFeatureMessage->setActionsWhenNested(getNormalizedProperty(theFeatureNode,
@@ -151,8 +153,10 @@ void Config_FeatureReader::fillFeature(xmlNodePtr theFeatureNode,
     return;
   }
 
-  outFeatureMessage->setText(getProperty(theFeatureNode, FEATURE_TEXT));
-  outFeatureMessage->setTooltip(getProperty(theFeatureNode, FEATURE_TOOLTIP));
+  std::string aText = Config_Translator::translate(anId, getProperty(theFeatureNode, FEATURE_TEXT));
+  outFeatureMessage->setText(aText);
+  std::string aToolTip = Config_Translator::translate(anId, getProperty(theFeatureNode, FEATURE_TOOLTIP));
+  outFeatureMessage->setTooltip(aToolTip);
   outFeatureMessage->setIcon(getProperty(theFeatureNode, FEATURE_ICON));
   outFeatureMessage->setKeysequence(getProperty(theFeatureNode, FEATURE_KEYSEQUENCE));
   outFeatureMessage->setGroupId(restoreAttribute(NODE_GROUP, _ID));
index 4fbfcb5b98441158939788a2d5988bba5ae497da..89bf4d1e1384f023e4e74367efa4e80386d7b6a4 100644 (file)
@@ -15,7 +15,7 @@
 
 
 /// The definition provides collection and writing of missed translations
-//#define MISSED_TRANSLATION
+#define MISSED_TRANSLATION
 
 /**
  * \class Config_Translator
index 637f3b578309f1741130872482cbc168e14be1cf..87ffbbd492c96e0fe64d0cf40337ad384ac43fc4 100644 (file)
@@ -80,6 +80,7 @@ SET(XML_RESOURCES
 
 SET(TEXT_RESOURCES
     FeaturesPlugin_msg_en.ts
+    FeaturesPlugin_msg_ru.ts
 )
 
 SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES})
index cb35243414dcdb2a7efd1880de6772cf626fcb95..1e7fab54dc35286a1b64cbf28a722be222dabc24 100644 (file)
     </message>
   </context>
   <context>
-    <name>Boolean:GeomValidators_BooleanArguments</name>
+    <name>Boolean</name>
     <message>
-      <source>Not enough arguments</source>
-      <translation>Not enough arguments for the operation</translation>
+      <source>Boolean</source>
+      <translation>Boolean</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:GeomValidators_BooleanArguments</name>
     <message>
-      <source>Wrong number of arguments (expected 3).</source>
-      <translation>Wrong number of validator "GeomValidators_BooleanArguments" arguments (expected 3).</translation>
+      <source>Boolean operations with objects</source>
+      <translation>Boolean operations with objects</translation>
     </message>
   </context>
   <context>
-    <name>Boolean:Model_FeatureValidator</name>
+    <name>Boolean:bool_type</name>
     <message>
-      <source>Attribute "bool_type" is not initialized.</source>
-      <translation></translation>
+      <source>Operation type</source>
+      <translation>Operation type</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:Model_FeatureValidator</name>
     <message>
-      <source>Attribute "main_objects" is not initialized.</source>
-      <translation>Objects not selected.</translation>
+      <source>Type of boolean operation</source>
+      <translation>Type of boolean operation</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:Model_FeatureValidator</name>
     <message>
-      <source>Attribute "tool_objects" is not initialized.</source>
-      <translation>Tools not selected.</translation>
+      <source>Cut</source>
+      <translation>Cut</translation>
+    </message>
+    <message>
+      <source>Fuse</source>
+      <translation>Fuse</translation>
+    </message>
+    <message>
+      <source>Common</source>
+      <translation>Common</translation>
+    </message>
+    <message>
+      <source>Fill</source>
+      <translation>Fill</translation>
+    </message>
+    <message>
+      <source>Smash</source>
+      <translation>Smash</translation>
     </message>
   </context>
   <context>
-    <name>Boolean:main_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
+    <name>Boolean:main_objects</name>
     <message>
-      <source>Error: This validator can only work with selection list attributes in \"Boolean\" feature.</source>
-      <translation></translation>
+      <source>Main objects</source>
+      <translation>Main objects</translation>
+    </message>
+    <message>
+      <source>Select objects</source>
+      <translation>Select objects</translation>
     </message>
   </context>
   <context>
     <name>Boolean:main_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Empty attribute selection.</source>
-      <translation>Objects not selected.</translation>
+      <translation>Select objects.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:main_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Empty selection context.</source>
-      <translation></translation>
+      <translation>Selected object invalid.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:main_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Result construction not allowed for selection.</source>
       <translation>Result construction not allowed for selection.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:main_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Empty shape.</source>
-      <translation></translation>
+      <translation>Selected object invalid.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:main_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Local selection not allowed.</source>
       <translation>Local selection not allowed.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:main_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Selected shape has the wrong type.</source>
       <translation>Selected shape has the wrong type.</translation>
     </message>
   </context>
   <context>
-    <name>Boolean:main_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
+    <name>Boolean:tool_objects</name>
     <message>
-      <source>Error: Selected shape has the wrong type.</source>
-      <translation>Selected shape has the wrong type.</translation>
+      <source>Tool objects</source>
+      <translation>Tool objects</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:tool_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
-      <source>Error: This validator can only work with selection list attributes in \"Boolean\" feature.</source>
-      <translation></translation>
+      <source>Select tools</source>
+      <translation>Select tools</translation>
     </message>
   </context>
   <context>
     <name>Boolean:tool_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Empty attribute selection.</source>
-      <translation>Tools not selected.</translation>
+      <translation>Select tools.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:tool_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Empty selection context.</source>
-      <translation></translation>
+      <translation>Selected tool invalid.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:tool_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Result construction not allowed for selection.</source>
       <translation>Result construction not allowed for selection.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:tool_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Empty shape.</source>
-      <translation></translation>
+      <translation>Selected tool invalid.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:tool_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Local selection not allowed.</source>
       <translation>Local selection not allowed.</translation>
     </message>
-  </context>
-  <context>
-    <name>Boolean:tool_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
     <message>
       <source>Error: Selected shape has the wrong type.</source>
       <translation>Selected shape has the wrong type.</translation>
     </message>
   </context>
   <context>
-    <name>Boolean:tool_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
+    <name>Boolean:GeomValidators_BooleanArguments</name>
     <message>
-      <source>Error: Selected shape has the wrong type.</source>
-      <translation>Selected shape has the wrong type.</translation>
+      <source>Not enough arguments</source>
+      <translation>Not enough arguments.</translation>
+    </message>
+  </context>
+  <context>
+    <name>Boolean:Model_FeatureValidator</name>
+    <message>
+      <source>Attribute "bool_type" is not initialized.</source>
+      <translation>Select operation type.</translation>
+    </message>
+    <message>
+      <source>Attribute "main_objects" is not initialized.</source>
+      <translation>Select objects.</translation>
+    </message>
+    <message>
+      <source>Attribute "tool_objects" is not initialized.</source>
+      <translation>Select tools.</translation>
     </message>
   </context>
   <context>
diff --git a/src/FeaturesPlugin/FeaturesPlugin_msg_ru.ts b/src/FeaturesPlugin/FeaturesPlugin_msg_ru.ts
new file mode 100644 (file)
index 0000000..6901086
--- /dev/null
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.0" language="ru_RU">
+  <context>
+    <name>Boolean</name>
+    <message>
+      <source>Boolean</source>
+      <translation>Булевы операции</translation>
+    </message>
+    <message>
+      <source>Perform boolean operations with objects</source>
+      <translation>Производит булевы операции с объектами</translation>
+    </message>
+  </context>
+  <context>
+    <name>Boolean:bool_type</name>
+    <message>
+      <source>Operation type</source>
+      <translation>Тип операции</translation>
+    </message>
+    <message>
+      <source>Type of boolean operation</source>
+      <translation>Тип булевой операции</translation>
+    </message>
+    <message>
+      <source>Cut</source>
+      <translation>Вырезание</translation>
+    </message>
+    <message>
+      <source>Fuse</source>
+      <translation>Объединение</translation>
+    </message>
+    <message>
+      <source>Common</source>
+      <translation>Пересечение</translation>
+    </message>
+    <message>
+      <source>Fill</source>
+      <translation>Заполнение</translation>
+    </message>
+    <message>
+      <source>Smash</source>
+      <translation>Вдавливание</translation>
+    </message>
+  </context>
+  <context>
+    <name>Boolean:main_objects</name>
+    <message>
+      <source>Main objects</source>
+      <translation>Основные объекты</translation>
+    </message>
+    <message>
+      <source>Select objects</source>
+      <translation>Выберите основные объекты</translation>
+    </message>
+  </context>
+  <context>
+    <name>Boolean:main_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
+    <message>
+      <source>Error: Empty attribute selection.</source>
+      <translation>Выберите основные объекты.</translation>
+    </message>
+    <message>
+      <source>Error: Empty selection context.</source>
+      <translation>Выбранные основные объекты невалидны.</translation>
+    </message>
+    <message>
+      <source>Error: Result construction not allowed for selection.</source>
+      <translation>Нельзя селектировать конструкции.</translation>
+    </message>
+    <message>
+      <source>Error: Empty shape.</source>
+      <translation>Выбранные основные объекты невалидны.</translation>
+    </message>
+    <message>
+      <source>Error: Local selection not allowed.</source>
+      <translation>Локальная селекция запрещена.</translation>
+    </message>
+    <message>
+      <source>Error: Selected shape has the wrong type.</source>
+      <translation>Выбраныне основные объекты имеют недопустимый тип.</translation>
+    </message>
+  </context>
+  <context>
+    <name>Boolean:tool_objects</name>
+    <message>
+      <source>Tool objects</source>
+      <translation>Вспомогательные объекты</translation>
+    </message>
+    <message>
+      <source>Select tools</source>
+      <translation>Выберите вспомогательные объекты</translation>
+    </message>
+  </context>
+  <context>
+    <name>Boolean:tool_objects:FeaturesPlugin_ValidatorBooleanSelection</name>
+    <message>
+      <source>Error: Empty attribute selection.</source>
+      <translation>Выберите вспомогательные объекты.</translation>
+    </message>
+    <message>
+      <source>Error: Empty selection context.</source>
+      <translation>Выбранные вспомогательные объекты невалидны.</translation>
+    </message>
+    <message>
+      <source>Error: Result construction not allowed for selection.</source>
+      <translation>Нельзя селектировать конструкции.</translation>
+    </message>
+    <message>
+      <source>Error: Empty shape.</source>
+      <translation>Выбранные вспомогательные объекты невалидны.</translation>
+  </message>
+    <message>
+      <source>Error: Local selection not allowed.</source>
+      <translation>Локальная селекция запрещена.</translation>
+    </message>
+    <message>
+      <source>Error: Selected shape has the wrong type.</source>
+      <translation>Выбраныне вспомогательные объекты имеют недопустимый тип.</translation>
+    </message>
+  </context>
+  <context>
+    <name>Boolean:GeomValidators_BooleanArguments</name>
+    <message>
+      <source>Not enough arguments</source>
+      <translation>Недостаточно объектов для операции.</translation>
+    </message>
+  </context>
+  <context>
+    <name>Boolean:Model_FeatureValidator</name>
+    <message>
+      <source>Attribute "bool_type" is not initialized.</source>
+      <translation>Выберите тип операции.</translation>
+    </message>
+    <message>
+      <source>Attribute "main_objects" is not initialized.</source>
+      <translation>Выберите основные объекты.</translation>
+    </message>
+    <message>
+      <source>Attribute "tool_objects" is not initialized.</source>
+      <translation>Выберите вспомогательные объекты.</translation>
+    </message>
+  </context>
+</TS>
index 262c1c97a6b2dd27c1c8493856e499a475a53e79..4b37febe876e8f3729c040097c9405d62e1a4a23 100644 (file)
@@ -14,7 +14,7 @@
   <multi_selector id="main_objects"
     label="Main objects"
     icon=""
-    tooltip="Select solid objects"
+    tooltip="Select objects"
     type_choice="solids compsolids edges faces"
     use_choice="false"
     concealment="true">
@@ -24,7 +24,7 @@
   <multi_selector id="tool_objects"
     label="Tool objects"
     icon=""
-    tooltip="Select a tool solid"
+    tooltip="Select tools"
     type_choice="solids compsolids edges faces"
     use_choice="false"
     concealment="true" >
index b7f98d6ae3ef6c3663daf4d45b790f020a153988..96a88f4dfbeda74b18756b705b7b144298c673d7 100644 (file)
@@ -30,7 +30,7 @@
       </feature>
     </group>
     <group id="Boolean">
-      <feature id="Boolean" title="Boolean" tooltip="Perform boolean operations with solids" icon="icons/Features/cut.png"
+      <feature id="Boolean" title="Boolean" tooltip="Perform boolean operations with objects" icon="icons/Features/cut.png"
                auto_preview="false">
           <source path="boolean_widget.xml"/>
       </feature>
index bf1c5a1da6908332aa4be3a9cf4adf9922204e46..0d4a3a974bb731e916dd6e3369cb09ba8c1f7c32 100644 (file)
@@ -58,8 +58,8 @@ void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theM
   if (!iconFile.isEmpty()) {
     icon = ModuleBase_IconFactory::loadIcon(iconFile);
   }
-  text = ModuleBase_Tools::translate(theMessage->id(), theMessage->text());
-  toolTip = ModuleBase_Tools::translate(theMessage->id(), theMessage->tooltip());
+  text = QString::fromUtf8(theMessage->text().c_str());
+  toolTip = QString::fromUtf8(theMessage->tooltip().c_str());
   QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
   if (!aShortcutStr.isEmpty()) {
     shortcut = QKeySequence(aShortcutStr);
index 7a90b5f2690fe43077d4c71cec1eae726841ce3c..49ade2db45e3e1bc0ef18372a33db362706ca147 100644 (file)
@@ -105,7 +105,7 @@ QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature)
 {
   // Error already translated.
   std::string aMsg = ModelAPI_Tools::getFeatureError(theFeature);
-  return aMsg.c_str();
+  return QString::fromUtf8(aMsg.c_str());
 }
 
 void ModuleBase_IModule::grantedOperationIds(ModuleBase_Operation* theOperation,
index 86265430b2666f8c9333b9b92b76239b69451fdf..47bfd5355f22f2cca530b10794ec6a0a95e1111e 100755 (executable)
@@ -137,10 +137,10 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   // Has to be defined first in order to get errors and messages from other components
   myEventsListener = new XGUI_WorkshopListener(aWorkshop);
 
+  SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
 #ifndef HAVE_SALOME
   myMainWindow = new AppElements_MainWindow();
 
-  SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
   bool aCloc = aResMgr->booleanValue("language", "locale", true);
   if (aCloc)
     QLocale::setDefault( QLocale::c() );
@@ -151,11 +151,20 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   QDir aDir(aPath);
 
   // Load translations
-  QStringList aFilters;
-  aFilters << "*_en.ts";
-  QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
-  foreach(QString aFileName, aTsFiles) {
-    Config_Translator::load(aFileName.toStdString());
+  QStringList aLangs;
+  aLangs << "*_en.ts"; // load by default eng translations
+  QString aCurrLang = aResMgr->stringValue("language", "language", "en");
+  if(aCurrLang != "en") {
+    aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files
+  }
+
+  foreach(QString aLang, aLangs) {
+    QStringList aFilters;
+    aFilters << aLang;
+    QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files);
+    foreach(QString aFileName, aTsFiles) {
+      Config_Translator::load(aFileName.toStdString());
+    }
   }
 
   myDataModelXMLReader = new Config_DataModelReader();