From f99ee017f2ac6b03a6bc6122cb78923a9b4f6a5f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 18 Mar 2012 23:05:10 +0300 Subject: Add help po translation. Combine help and client data translations. --- src/utils/translation/poparser.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/utils/translation/poparser.cpp') diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp index 521774592..d0f79a28c 100644 --- a/src/utils/translation/poparser.cpp +++ b/src/utils/translation/poparser.cpp @@ -24,7 +24,6 @@ #include "utils/stringutils.h" -#include "localconsts.h" #include "logger.h" #include @@ -39,22 +38,30 @@ PoParser::PoParser() : { } -void PoParser::openFile() +void PoParser::openFile(std::string name) { ResourceManager *resman = ResourceManager::getInstance(); int size; - char *buf = static_cast(resman->loadFile(getFileName(mLang), size)); + char *buf = static_cast(resman->loadFile(getFileName(name), size)); mFile.str(std::string(buf, size)); free(buf); } -PoDict *PoParser::load(std::string lang) +PoDict *PoParser::load(std::string lang, std::string fileName, PoDict *dict) { + logger->log("loading lang: %s, file: %s", lang.c_str(), fileName.c_str()); + setLang(lang); - mDict = getDict(); + if (!dict) + mDict = getDict(); + else + mDict = dict; - openFile(); + if (fileName.empty()) + openFile(mLang); + else + openFile(fileName); mMsgId = ""; mMsgStr = ""; @@ -84,6 +91,8 @@ PoDict *PoParser::load(std::string lang) // logger->log("add key: " + mMsgId); // logger->log("add value: " + mMsgStr); + convertStr(mMsgId); + convertStr(mMsgStr); // store key and value mDict->set(mMsgId, mMsgStr); } @@ -212,6 +221,7 @@ bool PoParser::checkLang(std::string lang) const std::string PoParser::getFileName(std::string lang) const { // get po file name from lang name + logger->log("getFileName: translations/%s.po", lang.c_str()); return strprintf("translations/%s.po", lang.c_str()); } @@ -219,3 +229,13 @@ PoDict *PoParser::getDict() { return new PoDict(mLang); } + +void PoParser::convertStr(std::string &str) +{ + if (str.empty()) + return; + + replaceAll(str, "\\n", "\n"); + replaceAll(str, "\\\"", "\""); + replaceAll(str, "\\\\", "\\"); +} -- cgit v1.2.3-70-g09d2