From fd4be023d5427dae291f75f9181398b335ae9aa5 Mon Sep 17 00:00:00 2001 From: Benau Date: Wed, 9 Sep 2020 14:46:29 +0800 Subject: [PATCH] Make tinygettext use stk logging --- .../include/tinygettext/log_stream.hpp | 2 +- src/utils/translation.cpp | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/tinygettext/include/tinygettext/log_stream.hpp b/lib/tinygettext/include/tinygettext/log_stream.hpp index 6ca9b3c28..3350b4bf1 100644 --- a/lib/tinygettext/include/tinygettext/log_stream.hpp +++ b/lib/tinygettext/include/tinygettext/log_stream.hpp @@ -27,7 +27,7 @@ namespace tinygettext { // FIXME: very bad to have such things in the API #define log_error if (!Log::log_error_callback); else (Log(Log::log_error_callback)).get() #define log_warning if (!Log::log_warning_callback); else (Log(Log::log_warning_callback)).get() -#define log_info if (!Log::log_info_callback); else (Log(Log::log_warning_callback)).get() +#define log_info if (!Log::log_info_callback); else (Log(Log::log_info_callback)).get() } // namespace tinygettext diff --git a/src/utils/translation.cpp b/src/utils/translation.cpp index 18167090a..a7267f644 100644 --- a/src/utils/translation.cpp +++ b/src/utils/translation.cpp @@ -62,6 +62,7 @@ Translations* translations = NULL; #ifndef SERVER_ONLY #include "tinygettext/file_system.hpp" +#include "tinygettext/log.hpp" std::map Translations::m_localized_name; std::map > @@ -78,7 +79,6 @@ constexpr bool isThaiCP(char32_t c) // ============================================================================ const bool REMOVE_BOM = false; -using namespace tinygettext; /** The list of available languages; this is global so that it is cached (and remains even if the translations object is deleted and re-created) */ typedef std::vector LanguageList; @@ -115,7 +115,14 @@ Translations::Translations() //: m_dictionary_manager("UTF-16") FileUtils::getPortableReadingPath(filename))); } }; - m_dictionary_manager.set_filesystem(std::unique_ptr( + // Hide log info because it warns about untranslated message + tinygettext::Log::set_log_info_callback([](const std::string& str) {}); + tinygettext::Log::set_log_warning_callback([](const std::string& str) + { Log::warn("tinygettext", "%s", str.c_str()); }); + tinygettext::Log::set_log_error_callback([](const std::string& str) + { Log::error("tinygettext", "%s", str.c_str()); }); + + m_dictionary_manager.set_filesystem(std::unique_ptr( new StkFileSystem())); m_dictionary_manager.add_directory( @@ -123,12 +130,12 @@ Translations::Translations() //: m_dictionary_manager("UTF-16") if (g_language_list.size() == 0) { - std::set languages = m_dictionary_manager.get_languages(); + std::set languages = m_dictionary_manager.get_languages(); // English is always there but may be not found on file system g_language_list.push_back("en"); - for (const Language& language : languages) + for (const tinygettext::Language& language : languages) { if (language.str() == "en") continue; @@ -416,11 +423,11 @@ Translations::Translations() //: m_dictionary_manager("UTF-16") if (language.find(":") != std::string::npos) { std::vector langs = StringUtils::split(language, ':'); - Language l; + tinygettext::Language l; for (unsigned int curr=0; curr