This is the new Docs for Chat SDK v4 for iOS. To see the previous Docs, click here.
Auto-translate messages
Sendbird's auto-translation feature lets you send text messages in different languages. When sending a text message, set Array of language codes to a UserMessageCreateParams object and then pass the object as an argument to a parameter in the sendUserMessage(params:completionHandler:) method to request messages to be translated into the desired languages. With this, you can add a real-time translation feature to your app.
let params = UserMessageCreateParams(message: MESSAGE_TEXT)
params.translationTargetLanguages = ["es", "ko"] // Spanish and Korean
channel.sendUserMessage(params: params) { userMessage, error in
guard error == nil else {
// Handle error.
return
}
}
As shown in the code below, you can retrieve the translations of a text message using the translations property of a UserMessage object, which has an Array object containing the language codes and translations.
func channel(_ channel: BaseChannel, didReceive message: BaseMessage) {
if let message = message as? UserMessage {
let esTranslatedMessage = message.translations["es"] // Spanish
// Show translations in UI.
}
}