diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-04-05 19:03:59 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-04-05 19:03:59 +0300 |
commit | 3b4ffd7199d990d1cbd0e7cbe23fa41f04d38e74 (patch) | |
tree | fe7ab920632207462354714e12604e2064d059ea /src/actions/chat.cpp | |
parent | d8a530e299b4dd04c020ca3e3eeda7b12f89b69b (diff) | |
download | manaplus-3b4ffd7199d990d1cbd0e7cbe23fa41f04d38e74.tar.gz manaplus-3b4ffd7199d990d1cbd0e7cbe23fa41f04d38e74.tar.bz2 manaplus-3b4ffd7199d990d1cbd0e7cbe23fa41f04d38e74.tar.xz manaplus-3b4ffd7199d990d1cbd0e7cbe23fa41f04d38e74.zip |
Add chat command for translate message from player language to english.
Also add po field into languages.xml.
Diffstat (limited to 'src/actions/chat.cpp')
-rw-r--r-- | src/actions/chat.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/actions/chat.cpp b/src/actions/chat.cpp index 037b25942..4da242569 100644 --- a/src/actions/chat.cpp +++ b/src/actions/chat.cpp @@ -49,6 +49,8 @@ #include "utils/booleanoptions.h" #include "utils/chatutils.h" +#include "utils/translation/podict.h" + #include "debug.h" const int DEFAULT_CHAT_WINDOW_SCROLL = 7; @@ -671,4 +673,47 @@ impHandler(guildNotice) return true; } +impHandler(translate) +{ + if (reverseDictionary == nullptr || + localPlayer == nullptr || + event.args.empty()) + { + return false; + } + + ChatTab *const tab = event.tab; + if (tab == nullptr) + return false; + + std::string srcStr = event.args; + std::string enStr; + toLower(srcStr); + if (localPlayer->getLanguageId() > 0) + { + if (reverseDictionary->haveStr(srcStr)) + enStr = reverseDictionary->getStr(srcStr); + else if (dictionary->haveStr(srcStr)) + enStr = srcStr; + } + else + { + if (dictionary->haveStr(srcStr)) + enStr = srcStr; + } + + if (enStr.empty()) + { + tab->chatLog( + // TRANSLATORS: translation error message + strprintf(_("No translation found for string: %s"), + srcStr.c_str()), + ChatMsgType::BY_SERVER); + return true; + } + + tab->chatInput(enStr); + return true; +} + } // namespace Actions |