/ SDKs / iOS
SDKs
Chat SDKs iOS v4
Chat SDKs iOS
Chat SDKs
iOS
Version 4

Translate messages on-demand

Copy link

You can add a feature to your app to translate select messages into other languages. Using the translateUserMessage(_:targetLanguages:completionHandler:) 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. You can also visit the language support page in Google Cloud Translation.

let targetLanguages = ["es", "de"]

// The USER_MESSAGE argument below indicates a UserMessage object
// which represents an already sent or received text message.
channel.translateUserMessage(USER_MESSAGE, targetLanguages: targetLanguages) { userMessage, error in
    guard error == nil else {
        // Handle error.
        return
    }

    let translations = userMessage?.translations
    let esTranslatedMessage = translations?["es"]    // Spanish
    let deTranslatedMessage = translations?["de"]    // German

    // Show translations in UI.
}