From: vsv Date: Thu, 2 Jun 2016 12:46:21 +0000 (+0300) Subject: Read translations X-Git-Tag: V_2.4.0~139^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3aa818c0a5abf4c46afa2d91cad46340efc4bd5f;p=modules%2Fshaper.git Read translations --- diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index 8952f1756..9d8218942 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -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 diff --git a/src/Config/Config_Common.cpp b/src/Config/Config_Common.cpp index ce096355a..aaf1ed9cb 100644 --- a/src/Config/Config_Common.cpp +++ b/src/Config/Config_Common.cpp @@ -225,10 +225,11 @@ bool BothAreSpaces(char lhs, char rhs) { return (lhs == rhs) && (lhs == ' '); } std::string getProperty(xmlNodePtr theNode, const char* thePropName) { std::string result = ""; - char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST thePropName); + xmlChar* aPropChars = xmlGetProp(theNode, BAD_CAST thePropName); if (!aPropChars || aPropChars[0] == 0) return result; - result = std::string(aPropChars); + result = std::string((char*)aPropChars); + xmlFree(aPropChars); std::string::iterator new_end = std::unique(result.begin(), result.end(), BothAreSpaces); result.erase(new_end, result.end()); @@ -236,6 +237,17 @@ std::string getProperty(xmlNodePtr theNode, const char* thePropName) return result; } +std::string getContent(xmlNodePtr theNode) +{ + std::string result = ""; + xmlChar* aContent = xmlNodeGetContent(theNode); + if (!aContent || aContent[0] == 0) + return result; + result = std::string((char*)aContent); + xmlFree(aContent); + return result; +} + std::string getNormalizedProperty(xmlNodePtr theNode, const char* thePropName) { return normalize(getProperty(theNode, thePropName)); diff --git a/src/Config/Config_Common.h b/src/Config/Config_Common.h index 52776d764..0998a6b73 100644 --- a/src/Config/Config_Common.h +++ b/src/Config/Config_Common.h @@ -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. */ diff --git a/src/Config/Config_Translator.cpp b/src/Config/Config_Translator.cpp index 9b03dc798..38bbf8bdd 100644 --- a/src/Config/Config_Translator.cpp +++ b/src/Config/Config_Translator.cpp @@ -5,7 +5,8 @@ // Author: Vitaly SMETANNIKOV #include "Config_Translator.h" -#include +#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 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::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 ""; } diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 184fcdf61..1fcc90652 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -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(); } diff --git a/src/Events/CMakeLists.txt b/src/Events/CMakeLists.txt index 5c5d99a08..a747fd872 100644 --- a/src/Events/CMakeLists.txt +++ b/src/Events/CMakeLists.txt @@ -13,6 +13,7 @@ SET(PROJECT_HEADERS Events_Loop.h Events_Error.h Events_LongOp.h + Events_InfoMessage.h ) SET(PROJECT_SOURCES diff --git a/src/Events/Events_InfoMessage.h b/src/Events/Events_InfoMessage.h index a38bec124..5f745a98b 100644 --- a/src/Events/Events_InfoMessage.h +++ b/src/Events/Events_InfoMessage.h @@ -11,13 +11,13 @@ #include #include -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); } diff --git a/src/ParametersPlugin/ParametersPlugin_msg_ru.ts b/src/ParametersPlugin/ParametersPlugin_msg_ru.ts index ab1c74b8f..c1e212c69 100644 --- a/src/ParametersPlugin/ParametersPlugin_msg_ru.ts +++ b/src/ParametersPlugin/ParametersPlugin_msg_ru.ts @@ -24,8 +24,9 @@ Коментарий + Parameters - Параметры + Параметры @@ -62,9 +63,8 @@ QObject - Parameters - Параметры + Параметры diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 944181bf5..3e3924954 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -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 diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 442133564..e51516510 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -78,6 +78,7 @@ #include #include #include +#include #include @@ -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(); diff --git a/src/XGUI/XGUI_msg_fr.ts b/src/XGUI/XGUI_msg_fr.ts index a543dd3da..9f2fa3972 100644 --- a/src/XGUI/XGUI_msg_fr.ts +++ b/src/XGUI/XGUI_msg_fr.ts @@ -19,7 +19,7 @@ - + Move to the end @@ -185,181 +185,181 @@ XGUI_Workshop - - + + Undo - - + + Undo last command - + INF_DESK_TOOLBAR_STANDARD - - + + Redo - - + + Redo last command - + Export native... - + Export the current document into a native file - + Import native... - + Import native file - - + + Save Title of the dialog which asks user if he wants to save study in existing non-empty folder - + Save the document - + Save as... - + Save the document into a file - + Open... - + Open a new document - + Preferences - + Edit preferences - + Exit - + Exit application - - + + Save current file - + The document is modified, save before opening another? - + Select directory - + Warning - + Unable to open the file. - + The document is modified, save before exit? - + Select directory to save files... - + Directories (*) - + The directory already contains some files, save anyway? - + Information about module "%1" doesn't exist. - + Object browser - + Unused features are the following: %1. These features will be deleted. Would you like to continue? - + All features are relevant, there is nothing to be deleted - + Find results - + Results not found