- if (myTranslator.count(aContext) > 0) {
- if (myTranslator[aContext].count(aMessage) > 0) {
- std::string aTranslation = myTranslator[aContext][aMessage];
- if (aParameters.size() > 0) {
- std::list<std::string>::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 translate(aContext, aMessage, aParameters);
+}
+
+std::string insertParameters(const std::string& theString, const std::list<std::string>& theParams)
+{
+ std::string aResult = theString;
+ std::list<std::string>::const_iterator aIt;
+ int i;
+ char aBuf[20];
+ std::string aParam;
+ for (i=1, aIt = theParams.cbegin(); aIt != theParams.cend(); aIt++, i++) {
+ aParam = (*aIt);
+ sprintf(aBuf, "%d", i);
+ std::string aCode = std::string("%") + std::string(aBuf);
+ size_t aPos = aResult.find(aCode);
+ if (aPos != std::string::npos) {
+ std::string aFirst = aResult.substr(0, aPos);
+ std::string aLast = aResult.substr(aPos + aCode.length(), std::string::npos);
+ aResult = aFirst + aParam + aLast;
+ }
+ }
+ return aResult;
+}
+
+std::string Config_Translator::translate(const std::string& theContext,
+ const std::string& theMessage,
+ const std::list<std::string>& theParams)
+{
+ if (myTranslator.count(theContext) > 0) {
+ if (myTranslator[theContext].count(theMessage) > 0) {
+ std::string aTranslation = myTranslator[theContext][theMessage];
+ if (theParams.size() > 0) {
+ aTranslation = insertParameters(aTranslation, theParams);
+ }
+ if (aTranslation.size() > 0)
+ return aTranslation;
+ }
+ }
+ std::string aMsg = theMessage;
+ if (theParams.size() > 0) {
+ aMsg = insertParameters(aMsg, theParams);
+ }
+#ifdef _DEBUG
+#ifdef MISSED_TRANSLATION
+ myMissed[theContext][theMessage] = "";
+#endif
+#endif
+ return aMsg;
+}
+
+// LCOV_EXCL_START
+std::string Config_Translator::codec(const std::string& theContext)
+{
+ return (myCodecs.count(theContext) > 0)? myCodecs[theContext] : "UTF-8";
+}
+
+std::string Config_Translator::codec(const Events_InfoMessage& theInfo)
+{
+ return codec(theInfo.context());
+}
+// LCOV_EXCL_STOP
+
+#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
+ 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;