#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()
{
line.resize(line.length() - 1);
if (str_starts_with(line, "# textdomain:")) {
- textdomain = utf8_to_wide(trim(str_split(line, ':')[1]));
+ auto parts = str_split(line, ':');
+ if (parts.size() < 2) {
+ errorstream << "Invalid textdomain translation line \"" << line
+ << "\"" << std::endl;
+ continue;
+ }
+ textdomain = utf8_to_wide(trim(parts[1]));
}
if (line.empty() || line[0] == '#')
continue;
}
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;
}
-
- std::wstring translation_index = textdomain + L"|";
- translation_index.append(oword1);
- m_translations[translation_index] = oword2;
}
}