X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftranslation.cpp;h=8bbaee0a36acc9e9e0aef0746e2cae575a96192f;hb=664800b2adda44039a85c3566b4ed958abff8b95;hp=e8582f3286e3481ede2df829726488b5a92be73b;hpb=b24e6433df3c3b2926568aff9c0173459e3e8eab;p=minetest.git diff --git a/src/translation.cpp b/src/translation.cpp index e8582f328..8bbaee0a3 100644 --- a/src/translation.cpp +++ b/src/translation.cpp @@ -20,9 +20,18 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "translation.h" #include "log.h" #include "util/string.h" +#include -static Translations main_translations; -Translations *g_translations = &main_translations; + +#ifndef SERVER +// Client translations +Translations client_translations; +Translations *g_client_translations = &client_translations; +#endif + +// Per language server translations +std::unordered_map server_translations; +std::unordered_map *g_server_translations = &server_translations; Translations::~Translations() { @@ -40,8 +49,8 @@ const std::wstring &Translations::getTranslation( std::wstring key = textdomain + L"|" + s; try { return m_translations.at(key); - } catch (std::out_of_range) { - warningstream << "Translations: can't find translation for string \"" + } catch (const std::out_of_range &) { + verbosestream << "Translations: can't find translation for string \"" << wide_to_utf8(s) << "\" in textdomain \"" << wide_to_utf8(textdomain) << "\"" << std::endl; // Silence that warning in the future @@ -58,6 +67,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])); } @@ -80,6 +93,8 @@ void Translations::loadTranslation(const std::string &data) if (i + 1 < wline.length()) { if (wline[i + 1] == L'=') { word1.put(L'='); + } else if (wline[i + 1] == L'n') { + word1.put(L'\n'); } else { word1.put(L'@'); word1.put(wline[i + 1]); @@ -113,6 +128,8 @@ void Translations::loadTranslation(const std::string &data) if (i + 1 < wline.length()) { if (wline[i + 1] == L'=') { word2.put(L'='); + } else if (wline[i + 1] == L'n') { + word2.put(L'\n'); } else { word2.put(L'@'); word2.put(wline[i + 1]); @@ -141,6 +158,8 @@ void Translations::loadTranslation(const std::string &data) << wide_to_utf8(oword1) << "\"" << std::endl; } - m_translations[textdomain + L"|" + oword1] = oword2; + std::wstring translation_index = textdomain + L"|"; + translation_index.append(oword1); + m_translations[translation_index] = oword2; } -} \ No newline at end of file +}