Reduce translations log spam

This commit is contained in:
sfan5 2024-03-04 23:59:29 +01:00
parent bf52d1e624
commit d88f0866b7
2 changed files with 9 additions and 18 deletions

View File

@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef SERVER #ifndef SERVER
// Client translations // Client translations
Translations client_translations; static Translations client_translations;
Translations *g_client_translations = &client_translations; Translations *g_client_translations = &client_translations;
#endif #endif
@ -36,19 +36,13 @@ void Translations::clear()
} }
const std::wstring &Translations::getTranslation( const std::wstring &Translations::getTranslation(
const std::wstring &textdomain, const std::wstring &s) const std::wstring &textdomain, const std::wstring &s) const
{ {
std::wstring key = textdomain + L"|" + s; std::wstring key = textdomain + L"|" + s;
try { auto it = m_translations.find(key);
return m_translations.at(key); if (it != m_translations.end())
} catch (const std::out_of_range &) { return it->second;
verbosestream << "Translations: can't find translation for string \"" return s;
<< wide_to_utf8(s) << "\" in textdomain \""
<< wide_to_utf8(textdomain) << "\"" << std::endl;
// Silence that warning in the future
m_translations[key] = s;
return s;
}
} }
void Translations::loadTranslation(const std::string &data) void Translations::loadTranslation(const std::string &data)
@ -155,10 +149,7 @@ void Translations::loadTranslation(const std::string &data)
if (!oword2.empty()) { if (!oword2.empty()) {
std::wstring translation_index = textdomain + L"|"; std::wstring translation_index = textdomain + L"|";
translation_index.append(oword1); translation_index.append(oword1);
m_translations[translation_index] = oword2; m_translations.emplace(std::move(translation_index), std::move(oword2));
} else {
infostream << "Ignoring empty translation for \""
<< wide_to_utf8(oword1) << "\"" << std::endl;
} }
} }
} }

View File

@ -32,8 +32,8 @@ class Translations
public: public:
void loadTranslation(const std::string &data); void loadTranslation(const std::string &data);
void clear(); void clear();
const std::wstring &getTranslation( const std::wstring &getTranslation(const std::wstring &textdomain,
const std::wstring &textdomain, const std::wstring &s); const std::wstring &s) const;
private: private:
std::unordered_map<std::wstring, std::wstring> m_translations; std::unordered_map<std::wstring, std::wstring> m_translations;