diff options
Diffstat (limited to 'src/actions')
-rw-r--r-- | src/actions/chat.cpp | 45 | ||||
-rw-r--r-- | src/actions/chat.h | 1 |
2 files changed, 46 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 diff --git a/src/actions/chat.h b/src/actions/chat.h index 0794ec9ed..ba33806a3 100644 --- a/src/actions/chat.h +++ b/src/actions/chat.h @@ -61,6 +61,7 @@ namespace Actions decHandler(hat); decHandler(chatClipboard); decHandler(guildNotice); + decHandler(translate); } // namespace Actions #undef decHandler |