]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/translation.cpp
Isolate library tables between sandbox and insecure env
[dragonfireclient.git] / src / translation.cpp
index 649c3b282086c7e7fe3671f500a0db7ff530461b..55c958fa28e0c75996eb37769ed184bc73f9b052 100644 (file)
@@ -20,14 +20,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "translation.h"
 #include "log.h"
 #include "util/string.h"
+#include <unordered_map>
 
-static Translations main_translations;
-Translations *g_translations = &main_translations;
 
-Translations::~Translations()
-{
-       clear();
-}
+#ifndef SERVER
+// Client translations
+Translations client_translations;
+Translations *g_client_translations = &client_translations;
+#endif
+
 
 void Translations::clear()
 {
@@ -58,6 +59,10 @@ void Translations::loadTranslation(const std::string &data)
 
        while (is.good()) {
                std::getline(is, line);
+               // Trim last character if file was using a \r\n line ending
+               if (line.length () > 0 && line[line.length() - 1] == '\r')
+                       line.resize(line.length() - 1);
+
                if (str_starts_with(line, "# textdomain:")) {
                        textdomain = utf8_to_wide(trim(str_split(line, ':')[1]));
                }
@@ -139,12 +144,13 @@ void Translations::loadTranslation(const std::string &data)
                }
 
                std::wstring oword1 = word1.str(), oword2 = word2.str();
-               if (oword2.empty()) {
-                       oword2 = oword1;
-                       errorstream << "Ignoring empty translation for \""
-                                   << wide_to_utf8(oword1) << "\"" << std::endl;
+               if (!oword2.empty()) {
+                       std::wstring translation_index = textdomain + L"|";
+                       translation_index.append(oword1);
+                       m_translations[translation_index] = oword2;
+               } else {
+                       infostream << "Ignoring empty translation for \""
+                               << wide_to_utf8(oword1) << "\"" << std::endl;
                }
-
-               m_translations[textdomain + L"|" + oword1] = oword2;
        }
 }