From: vsv Date: Mon, 6 Jun 2016 16:32:37 +0000 (+0300) Subject: Translate strings with corresponded codec X-Git-Tag: V_2.4.0~139^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1caca4db4cda17236f7a9f50fc9c620f6a426372;p=modules%2Fshaper.git Translate strings with corresponded codec --- diff --git a/src/Config/Config_Translator.cpp b/src/Config/Config_Translator.cpp index f21e8f648..9a03118fe 100644 --- a/src/Config/Config_Translator.cpp +++ b/src/Config/Config_Translator.cpp @@ -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() diff --git a/src/Config/Config_Translator.h b/src/Config/Config_Translator.h index 9f989f9d0..72a305ec9 100644 --- a/src/Config/Config_Translator.h +++ b/src/Config/Config_Translator.h @@ -56,6 +56,13 @@ public: const std::string& theMessage, const std::list& theParams = std::list()); + + /** + * 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; diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index bdfaa583a..1dab4ac3d 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -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 diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index 62173af31..851ff1b28 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -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. diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index be4cc61a6..997c41348 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -31,6 +31,7 @@ #include #include #include +#include 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; } diff --git a/src/XGUI/XGUI_ErrorDialog.cpp b/src/XGUI/XGUI_ErrorDialog.cpp index 75df20651..04a3f5316 100644 --- a/src/XGUI/XGUI_ErrorDialog.cpp +++ b/src/XGUI/XGUI_ErrorDialog.cpp @@ -16,6 +16,7 @@ #include #include #include +#include XGUI_ErrorDialog::XGUI_ErrorDialog(QWidget* parent) : QDialog(parent) @@ -60,7 +61,9 @@ void XGUI_ErrorDialog::clear() void XGUI_ErrorDialog::addError(std::shared_ptr 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(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d7f38883a..881029252 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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); diff --git a/src/XGUI/XGUI_msg_fr.ts b/src/XGUI/XGUI_msg_fr.ts index 070700a9a..d0a8feced 100644 --- a/src/XGUI/XGUI_msg_fr.ts +++ b/src/XGUI/XGUI_msg_fr.ts @@ -141,7 +141,7 @@ XGUI_ErrorDialog - + Application errors @@ -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