/ SDKs / Android
SDKs
Chat SDKs Android v4
Chat SDKs Android
Chat SDKs
Android
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 List of language codes to a UserMessageCreateParams 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.

KotlinKTX
val targetLanguages = listOf(
    "es",   // Spanish
    "ko"    // Korean
)

val params = UserMessageCreateParams(TEXT_MESSAGE).apply {
    translationTargetLanguages = targetLanguages
}

channel.sendUserMessage(params) { message, e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

To show the translated messages, use the userMessage.translations method which returns a Map object containing the language codes and translations as shown in the code below.

Open channel

Copy link
SendbirdChat.addChannelHandler(
    UNIQUE_HANDLER_ID,
    object : OpenChannelHandler() {
        override fun onMessageReceived(channel: BaseChannel, message: BaseMessage) {
            if (message is UserMessage) {
                val map = message.translations
                val esTranslatedMessage = map["es"] // Spanish

                // Display translation in the UI.
            }
        }
    }
)

Group channel

Copy link
SendbirdChat.addChannelHandler(
    UNIQUE_HANDLER_ID,
    object : GroupChannelHandler() {
        override fun onMessageReceived(channel: BaseChannel, message: BaseMessage) {
            if (message is UserMessage) {
                val map = message.translations
                val esTranslatedMessage = map["es"] // Spanish

                // Display translation in the UI.
            }
        }
    }
)