/ SDKs / .NET
SDKs
Chat SDKs .NET v4
Chat SDKs .NET
Chat SDKs
.NET
Version 4

Auto-translate messages

Copy link

Sendbird's auto-translation feature lets you send text messages in different languages. When sending a text message, set a list of language codes to a SbUserMessageCreateParams object and then pass the object as an argument to a parameter in the SendUserMessage() method to request messages to be translated into the desired languages. With this, you can add a real-time translation feature to your app. To enable this feature, contact our sales team.

Note: Sendbird's message auto-translation feature is powered by Google Cloud Translation API recognition engine. You can find the language codes supported by the engine in the translation engine page. You can also visit the language support page in Google Cloud Translation.

SbUserMessageCreateParams userMessageCreateParams = new SbUserMessageCreateParams(TEXT_MESSAGE);
userMessageCreateParams.TranslationTargetLanguages = new List<string> { "es", "ko" }; // Spanish and Korean

channel.SendUserMessage(userMessageCreateParams, (inMessage, inError) =>
{
    if (inError != null)
        return; // Handle error.

    // Message sent successfully. 
    // Add any further logic here if needed.
});

To show the translated messages, use the Translations property which returns a Dictionary object containing the language codes and translations as shown in the code below.

SbOpenChannelHandler openChannelHandler = new SbOpenChannelHandler
{
    OnMessageReceived = (inGroupChannel, inMessage) =>
    {
        if (inMessage is SbUserMessage userMessage)
        {
            if (userMessage.Translations.ContainsKey("es"))
            {
                string esTranslatedMessage = userMessage.Translations["es"];
                // You can now use esTranslatedMessage as needed.
            }
        }
    }
};

SendbirdChat.OpenChannel.AddOpenChannelHandler(UNIQUE_HANDLER_ID, openChannelHandler);