summaryrefslogtreecommitdiff
path: root/src/actions/chat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions/chat.cpp')
-rw-r--r--src/actions/chat.cpp45
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