/ SDKs / Unreal
SDKs
Chat SDKs Unreal v3
Chat SDKs Unreal
Chat SDKs
Unreal
Version 3

Message auto-translation

Copy link

It's possible for text messages to be sent in different languages through Sendbird's auto-translation feature. When sending a text message, pass in a List of language codes to the SendUserMessage() to request translated messages in the corresponding languages.

Note: Message auto-translation is powered by Google Cloud Translation API recognition engine. Find language codes supported by the engine in the Languages supported for translation page or visit the Language Support page in Google Cloud Translation.

std::vector<std::wstring> targetLanguages;
targetLanguages.push_back(L"es");
targetLanguages.push_back(L"ko");

SBDUserMessageParams params = SBDUserMessageParams()
        .SetMessage(TEXT_MESSAGE)
        .SetTargetLanguages(targetLanguages);

channel->SendUserMessage(params, [](SBDUserMessage* userMessage, SBDError* error) {
    if (error != nullptr) {
        // Handle error.
        return;
    }
});

You can retrieve translations of a message through the Translations property. This will return a Map containing the language codes and translations.

class MyChannelHandler : public SBDChannelHandler {
    void MessageReceived(SBDBaseChannel* channel, SBDBaseMessage* message) {
        if (message->message_type == SBDMessageType::User) {
            SBDUserMessage* userMessage = dynamic_cast<SBDUserMessage*>(message);
            std::wstring esTranslatedMessage = userMessage->translations[L"es"];
            std::wstring koTranslatedMessage = userMessage->translations[L"ko"];

            // Display translations in UI.
        }
    }
});

SBDMain::AddChannelHandler(UNIQUE_HANDLER_ID, new MyChannelHandler());