#include "Config_XMLReader.h"
#include "Config_Common.h"
+#include <fstream>
+#include <ostream>
+
class Config_TSReader : public Config_XMLReader
{
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)
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)) {
//******************************************************************************
//******************************************************************************
Config_Translator::Translator Config_Translator::myTranslator;
+Config_Translator::Dictionary Config_Translator::myCodecs;
+
+#ifdef _DEBUG
+#ifdef MISSED_TRANSLATION
+Config_Translator::Translator Config_Translator::myMissed;
+#endif
+#endif
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;
}
std::string Config_Translator::translate(std::shared_ptr<Events_InfoMessage> theInfo)
{
std::string aContext = theInfo->context();
- std::string aMessage = theInfo->message();
+ std::string aMessage = theInfo->messageString();
std::list<std::string> aParameters = theInfo->parameters();
return translate(aContext, aMessage, aParameters);
}
std::string aParam;
for (i=1, aIt = theParams.cbegin(); aIt != theParams.cend(); aIt++, i++) {
aParam = (*aIt);
- sprintf_s(aBuf, "%d", i);
+ sprintf(aBuf, "%d", i);
std::string aCode = std::string("%") + std::string(aBuf);
size_t aPos = aResult.find(aCode);
if (aPos != std::string::npos) {
if (theParams.size() > 0) {
aMsg = insertParameters(aMsg, theParams);
}
+#ifdef _DEBUG
+#ifdef MISSED_TRANSLATION
+ myMissed[theContext][theMessage] = "";
+#endif
+#endif
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()
+{
+ if (myMissed.size() == 0)
+ return;
+
+ char* aPath = getenv("ROOT_DIR");
+#ifdef WIN32
+ std::string aFile = aPath + std::string("\\MissedTranslation.ts");
+#else
+ std::string aFile = aPath + std::string("/MissedTranslation.ts");
+#endif
+ std::ofstream oFStream;
+
+ // Delete old file
+ int aa = remove(aFile.c_str());
+
+ oFStream.open(aFile, std::ofstream::out | std::ofstream::app);
+ if (oFStream.is_open()) {
+ Translator::const_iterator aContIt;
+ Dictionary::const_iterator aDictIt;
+ std::string aContext;
+ std::string aSrc;
+ Dictionary aDict;
+
+ oFStream << "<TS version=\"2.0\">" << std::endl;
+ for(aContIt = myMissed.cbegin(); aContIt != myMissed.cend(); aContIt++) {
+ oFStream << "<context>" << std::endl;
+
+ aContext = aContIt->first;
+ oFStream << " <name>" << aContext << "</name>" << std::endl;
+
+ aDict = aContIt->second;
+ for(aDictIt = aDict.cbegin(); aDictIt != aDict.cend(); aDictIt++) {
+ oFStream << " <message>" << std::endl;
+ aSrc = aDictIt->first;
+
+ oFStream << " <source>" << aSrc << "</source>" << std::endl;
+ oFStream << " <translation>" << "</translation>" << std::endl;
+
+ oFStream << " </message>" << std::endl;
+ }
+ oFStream << "</context>" << std::endl;
+ }
+
+ oFStream << "</TS>" << std::endl;
+ oFStream.close();
+ }
+}
+#endif
+#endif