Chat / Android
Chat Android v4
Chat Android
Chat
Android
Home
/
Chat
/
Android
/
Message
This is the new Docs for Chat SDK v4 for Android. To see the previous Docs, click here.

Translate messages on-demand

You can add a feature to your app to translate select messages into other languages. Using the openChannel.translateUserMessage() or the groupChannel.translateUserMessage() method, you can translate a text message already sent to a channel into the desired languages based on your own needs. To enable this feature, contact our sales team.

Note: Sendbird's on-demand message 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 or visit the language support page in Google Cloud Translation.

val targetLanguages = listOf(
    "es",   // Spanish
    "de"    // German
)

// The USER_MESSAGE argument below indicates a UserMessage object which represents an already sent or received text message.
groupChannel.translateUserMessage(USER_MESSAGE, targetLanguages) { message, e ->
    if (message != null) {
        val map = message.translations
        val esTranslatedMessage = map["es"] // Spanish
        val deTranslatedMessage = map["de"] // German
        // ...

        // Show translations in the UI.
    }
}