summaryrefslogtreecommitdiff
path: root/src/utils/translation
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-10-10 22:14:45 +0300
committerAndrei Karas <akaras@inbox.ru>2017-10-10 22:15:57 +0300
commitaa3f63fd497558a02feb3ddbc44f31eac091f39b (patch)
tree0e28b9b1f0501dd8be9e1a38db4ec1777fa3fbfa /src/utils/translation
parent7c10a6b61e9d06a4ae9cc9f942dfacb6fcfd9d3d (diff)
downloadplus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.gz
plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.bz2
plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.xz
plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.zip
Remove most unused files.
Diffstat (limited to 'src/utils/translation')
-rw-r--r--src/utils/translation/podict.cpp61
-rw-r--r--src/utils/translation/podict.h73
-rw-r--r--src/utils/translation/poparser.cpp286
-rw-r--r--src/utils/translation/poparser.h87
-rw-r--r--src/utils/translation/translationmanager.cpp154
-rw-r--r--src/utils/translation/translationmanager.h58
6 files changed, 0 insertions, 719 deletions
diff --git a/src/utils/translation/podict.cpp b/src/utils/translation/podict.cpp
deleted file mode 100644
index cd374319f..000000000
--- a/src/utils/translation/podict.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "utils/translation/podict.h"
-
-#include "debug.h"
-
-std::string empty;
-
-PoDict *translator = nullptr;
-PoDict *dictionary = nullptr;
-PoDict *reverseDictionary = nullptr;
-#ifdef ENABLE_CUSTOMNLS
-PoDict *mainTranslator = nullptr;
-#endif // ENABLE_CUSTOMNLS
-
-PoDict::PoDict(const std::string &lang) :
- mPoLines(),
- mLang(lang)
-{
-}
-
-PoDict::~PoDict()
-{
-}
-
-const std::string PoDict::getStr(const std::string &str)
-{
- if (mPoLines.find(str) == mPoLines.end())
- return str;
- return mPoLines[str];
-}
-
-const char *PoDict::getChar(const char *const str)
-{
- if (mPoLines.find(str) == mPoLines.end())
- return str;
- return mPoLines[str].c_str();
-}
-
-bool PoDict::haveStr(const std::string &str) const
-{
- return mPoLines.find(str) != mPoLines.end();
-}
diff --git a/src/utils/translation/podict.h b/src/utils/translation/podict.h
deleted file mode 100644
index d8f47b896..000000000
--- a/src/utils/translation/podict.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UTILS_TRANSLATION_PODICT_H
-#define UTILS_TRANSLATION_PODICT_H
-
-#include <map>
-#include <string>
-
-#include "localconsts.h"
-
-typedef std::map <std::string, std::string> PoMap;
-
-class PoDict final
-{
- public:
- explicit PoDict(const std::string &lang);
-
- A_DELETE_COPY(PoDict)
-
- ~PoDict();
-
- const std::string getStr(const std::string &str);
-
- const char *getChar(const char *const str);
-
- bool haveStr(const std::string &str) const;
-
-#ifndef UNITTESTS
- protected:
-#endif // UNITTESTS
- friend class PoParser;
- friend class TranslationManager;
-
- PoMap *getMap()
- { return &mPoLines; }
-
- void set(const std::string &key, const std::string &value)
- { mPoLines[key] = value; }
-
- void setLang(const std::string &lang)
- { mLang = lang; }
-
- private:
- PoMap mPoLines;
- std::string mLang;
-};
-
-extern PoDict *translator;
-extern PoDict *dictionary;
-extern PoDict *reverseDictionary;
-#ifdef ENABLE_CUSTOMNLS
-extern PoDict *mainTranslator;
-#endif // ENABLE_CUSTOMNLS
-
-#endif // UTILS_TRANSLATION_PODICT_H
diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp
deleted file mode 100644
index 399980a21..000000000
--- a/src/utils/translation/poparser.cpp
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "utils/translation/poparser.h"
-
-#include "fs/virtfs/fs.h"
-
-#include "utils/stringutils.h"
-
-#include "utils/translation/podict.h"
-
-#include "logger.h"
-
-#include "debug.h"
-
-PoParser::PoParser() :
- mLang(),
- mFile(),
- mLine(),
- mMsgId(),
- mMsgStr(),
- mDict(nullptr),
- mReadingId(false),
- mReadingStr(false),
- mSkipId(false)
-{
-}
-
-void PoParser::openFile(const std::string &name)
-{
- int size;
- const char *buf = VirtFs::loadFile(getFileName(name), size);
-
- if (buf != nullptr)
- {
- mFile.str(std::string(buf, size));
- delete [] buf;
- }
- else
- {
- mFile.clear();
- }
-}
-
-PoDict *PoParser::load(const std::string &restrict lang,
- const std::string &restrict fileName,
- PoDict *restrict const dict)
-{
- logger->log("loading lang: %s, file: %s", lang.c_str(), fileName.c_str());
-
- setLang(lang);
- if (dict == nullptr)
- mDict = getDict();
- else
- mDict = dict;
-
- if (fileName.empty())
- openFile(mLang);
- else
- openFile(fileName);
-
- mMsgId.clear();
- mMsgStr.clear();
-
- // cycle by msgid+msgstr
- while (readLine())
- {
- // reading msgid
- while (readMsgId())
- {
- if (!readLine())
- break;
- }
-
- if (!mMsgId.empty())
- {
- // if we got msgid then reading msgstr
- while (readMsgStr())
- {
- if (!readLine())
- break;
- }
- }
-
- if (!mMsgId.empty() && !mMsgStr.empty())
- {
-// logger->log("add key: " + mMsgId);
-// logger->log("add value: " + mMsgStr);
-
- convertStr(mMsgId);
- convertStr(mMsgStr);
- // store key and value
- mDict->set(mMsgId, mMsgStr);
- }
-
- mMsgId.clear();
- mMsgStr.clear();
- }
-
- return mDict;
-}
-
-bool PoParser::readLine()
-{
- char line[1001];
- if (!mFile.getline(line, 1000))
- return false;
- // skip plurals msgid if present
- if (strStartWith(line, "msgid_plural \""))
- {
- if (!mFile.getline(line, 1000))
- return false;
- }
- mLine = line;
- return true;
-}
-
-bool PoParser::readMsgId()
-{
- // if we reading msgstr then stop here
- if (mReadingStr)
- return false;
-
- const std::string msgId1("msgid \"");
-
- // check if in reading process
- if (mReadingId)
- {
- // if we get empty line in file then stop reading
- if (mLine.empty())
- {
- mReadingId = false;
- return false;
- }
- else if (checkLine())
- {
- // reading text from: "text"
- mMsgId.append(mLine.substr(1, mLine.size() - 2));
- mLine.clear();
- return true;
- }
- // stop reading in other case
- mReadingId = false;
- return false;
- }
-
- // check line start from msgid "
- if (strStartWith(mLine, msgId1))
- {
- if (!mSkipId)
- { // translation not fuzzed and can be processed
- mReadingId = true;
- const size_t msgId1Size = msgId1.size();
- // reading text from: msgid "text"
- mMsgId.append(mLine.substr(msgId1Size,
- mLine.size() - 1 - msgId1Size));
- }
- else
- { // skipped fuzzed translation. reset skip flag
- mSkipId = false;
- }
- mLine.clear();
- return true;
- }
- else if (mLine == "#, fuzzy")
- { // check for fuzzy translation
- mSkipId = true;
- mLine.clear();
- return true;
- }
- // stop reading if we don't read msgid before
- return mMsgId.empty();
-}
-
-bool PoParser::readMsgStr()
-{
- // normal msgstr
- const std::string msgStr1("msgstr \"");
- // plurals first msgstr
- const std::string msgStr2("msgstr[0] \"");
-
- // check if in reading process
- if (mReadingStr)
- {
- // if we get empty line in file then stop reading
- if (mLine.empty())
- {
- mReadingStr = false;
- return false;
- }
- if (checkLine())
- {
- // reading text from: "text"
- mMsgStr.append(mLine.substr(1, mLine.size() - 2));
- mLine.clear();
- return true;
- }
- // stop reading in other case
- mReadingStr = false;
- }
- else
- {
- // check line start from msgstr "
- if (strStartWith(mLine, msgStr1))
- {
- mReadingStr = true;
- const size_t msgStr1Size = msgStr1.size();
- // reading text from: msgstr "text"
- mMsgStr.append(mLine.substr(msgStr1Size,
- mLine.size() - 1 - msgStr1Size));
- mLine.clear();
- return true;
- }
- // checl list start from msgstr[0] "
- else if (strStartWith(mLine, msgStr2))
- {
- mReadingStr = true;
- const size_t msgStr2Size = msgStr2.size();
- // reading text from: msgstr[0] "text"
- mMsgStr.append(mLine.substr(msgStr2Size,
- mLine.size() - 1 - msgStr2Size));
- mLine.clear();
- return true;
- }
- }
-
- // stop reading in other case
- return false;
-}
-
-bool PoParser::checkLine() const
-{
- const size_t sz = mLine.size();
- // check is line in format: "text"
- return sz > 2 && mLine[0] == '\"' && mLine[sz - 1] == '\"';
-}
-
-PoDict *PoParser::getEmptyDict()
-{
- return new PoDict("");
-}
-
-bool PoParser::checkLang(const std::string &lang)
-{
- // check is po file exists
- return VirtFs::exists(getFileName(lang));
-}
-
-std::string PoParser::getFileName(const std::string &lang)
-{
- // get po file name from lang name
-// logger->log("getFileName: translations/%s.po", lang.c_str());
- return strprintf("translations/%s.po", lang.c_str());
-}
-
-PoDict *PoParser::getDict() const
-{
- return new PoDict(mLang);
-}
-
-void PoParser::convertStr(std::string &str)
-{
- if (str.empty())
- return;
-
- replaceAll(str, "\\n", "\n");
- replaceAll(str, "\\\"", "\"");
- replaceAll(str, "\\\\", "\\");
-}
diff --git a/src/utils/translation/poparser.h b/src/utils/translation/poparser.h
deleted file mode 100644
index 9f6fd7d35..000000000
--- a/src/utils/translation/poparser.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UTILS_TRANSLATION_POPARSER_H
-#define UTILS_TRANSLATION_POPARSER_H
-
-#include "localconsts.h"
-
-#include <sstream>
-
-class PoDict;
-
-class PoParser final
-{
- public:
- PoParser();
-
- A_DELETE_COPY(PoParser)
-
- PoDict *load(const std::string &restrict lang,
- const std::string &restrict fileName = "",
- PoDict *restrict const dict = nullptr);
-
- static bool checkLang(const std::string &lang);
-
- static PoDict *getEmptyDict();
-
- private:
- void setLang(const std::string &lang)
- { mLang = lang; }
-
- void openFile(const std::string &name);
-
- bool readLine();
-
- bool readMsgId();
-
- bool readMsgStr();
-
- bool checkLine() const;
-
- static std::string getFileName(const std::string &lang);
-
- PoDict *getDict() const RETURNS_NONNULL A_WARN_UNUSED;
-
- static void convertStr(std::string &str);
-
- // current lang
- std::string mLang;
-
- // po file object
- std::istringstream mFile;
-
- // current line from po file
- std::string mLine;
-
- std::string mMsgId;
-
- std::string mMsgStr;
-
- PoDict *mDict;
-
- bool mReadingId;
-
- bool mReadingStr;
-
- bool mSkipId;
-};
-
-#endif // UTILS_TRANSLATION_POPARSER_H
diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp
deleted file mode 100644
index d02ff2c02..000000000
--- a/src/utils/translation/translationmanager.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "utils/translation/translationmanager.h"
-
-#include "fs/virtfs/fs.h"
-
-#include "utils/delete2.h"
-#include "utils/stringutils.h"
-
-#include "utils/foreach.h"
-
-#include "utils/translation/podict.h"
-#include "utils/translation/poparser.h"
-
-#include "logger.h"
-
-#include "debug.h"
-
-void TranslationManager::init()
-{
- delete translator;
- translator = PoParser::getEmptyDict();
-}
-
-void TranslationManager::loadCurrentLang()
-{
- delete translator;
- translator = loadLang(getLang(), "");
- translator = loadLang(getLang(), "help/", translator);
-}
-
-void TranslationManager::loadDictionaryLang()
-{
- delete dictionary;
- delete reverseDictionary;
- dictionary = loadLang(getServerLang(), "dict/");
- reverseDictionary = reverseLang(dictionary);
-}
-
-#ifdef ENABLE_CUSTOMNLS
-void TranslationManager::loadGettextLang()
-{
- delete mainTranslator;
- mainTranslator = loadLang(getLang(), "manaplus/");
-}
-#endif // ENABLE_CUSTOMNLS
-
-void TranslationManager::close()
-{
- delete2(translator);
- delete2(dictionary);
- delete2(reverseDictionary);
-}
-
-PoDict *TranslationManager::loadLang(const LangVect &lang,
- const std::string &subName,
- PoDict *const dict)
-{
- std::string name;
- PoParser parser;
-
- FOR_EACH (LangIter, it, lang)
- {
- if (*it == "C")
- continue;
-
-// logger->log("check file: " + subName + *it);
- if (PoParser::checkLang(subName + *it))
- {
- name = *it;
- break;
- }
- }
- if (!name.empty())
- return parser.load(name, subName + name, dict);
- logger->log("can't find client data translation");
- if (dict != nullptr)
- return dict;
- return PoParser::getEmptyDict();
-}
-
-bool TranslationManager::translateFile(const std::string &fileName,
- PoDict *const dict,
- StringVect &lines)
-{
- if ((dict == nullptr) || fileName.empty())
- return false;
-
- int contentsLength;
- const char *fileContents = VirtFs::loadFile(fileName,
- contentsLength);
-
- if (fileContents == nullptr)
- {
- logger->log("Couldn't load file: %s", fileName.c_str());
- return false;
- }
- std::string str = std::string(fileContents, contentsLength);
-
- size_t oldPos1 = std::string::npos;
- size_t pos1;
-
- while ((pos1 = str.find("<<")) != std::string::npos)
- {
- if (pos1 == oldPos1)
- break; // detected infinite loop
- const size_t pos2 = str.find(">>", pos1 + 2);
- if (pos2 == std::string::npos)
- break;
- const std::string key(str.substr(pos1 + 2, pos2 - pos1 - 2));
- const std::string key2("<<" + str.substr(
- pos1 + 2, pos2 - pos1 - 2) + ">>");
- const std::string val(dict->getStr(key));
- replaceAll(str, key2, val);
- oldPos1 = pos1;
- }
-
- std::istringstream iss(str);
- std::string line;
-
- while (getline(iss, line))
- lines.push_back(line);
-
- delete [] fileContents;
- return true;
-}
-
-PoDict *TranslationManager::reverseLang(const PoDict *const dict)
-{
- PoDict *const revDict = new PoDict(dict->mLang);
- FOR_EACH (PoMap::const_iterator, it, dict->mPoLines)
- {
- revDict->set((*it).second, (*it).first);
- }
- return revDict;
-}
diff --git a/src/utils/translation/translationmanager.h b/src/utils/translation/translationmanager.h
deleted file mode 100644
index 088d97449..000000000
--- a/src/utils/translation/translationmanager.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UTILS_TRANSLATION_TRANSLATIONMANAGER_H
-#define UTILS_TRANSLATION_TRANSLATIONMANAGER_H
-
-#include "localconsts.h"
-
-#include "utils/langs.h"
-#include "utils/stringvector.h"
-
-class PoDict;
-
-class TranslationManager final
-{
- public:
- A_DELETE_COPY(TranslationManager)
-
- static PoDict *loadLang(const LangVect &lang,
- const std::string &subName,
- PoDict *const dict = nullptr);
-
- static void init();
-
- static void close();
-
- static void loadCurrentLang();
-
- static void loadDictionaryLang();
-
-#ifdef ENABLE_CUSTOMNLS
- static void loadGettextLang();
-#endif // ENABLE_CUSTOMNLS
-
- static bool translateFile(const std::string &fileName,
- PoDict *const dict,
- StringVect &lines);
- static PoDict *reverseLang(const PoDict *const dict);
-};
-
-#endif // UTILS_TRANSLATION_TRANSLATIONMANAGER_H