summaryrefslogtreecommitdiff
path: root/src/utils/translation/poparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/translation/poparser.cpp')
-rw-r--r--src/utils/translation/poparser.cpp32
1 files changed, 26 insertions, 6 deletions
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 <string.h>
@@ -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<char*>(resman->loadFile(getFileName(mLang), size));
+ char *buf = static_cast<char*>(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, "\\\\", "\\");
+}