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

Push notification translation

Push notification translation allows your users to receive notifications in their preferred languages. Users can set up to four preferred languages. If messages are sent in one of those languages, the notifications won't be translated. If messages are sent in a language other than the preferred languages, the notifications will be translated into the user's first preferred language. In addition, the messages translated into other preferred languages will be provided in the sendbird property of a notification payload.

Note: A specific user's preferred languages can be set with our Platform API's update a user action.

The current user's preferred languages can be set by passing the UserUpdateParams() instance as an argument to a parameter in the updateCurrentUserInfo() method as shown below.

SendbirdChat.connect(userId: USER_ID) { user, error in
    guard error == nil else {
        // Handle error.
        return
    }

    guard let user = user else {
        // Handle error.
        return
    }

    let params = UserUpdateParams()
    params.preferredLanguages = ["fr", "de", "es", "kr"] // French, German, Spanish, and Korean.

    SendbirdChat.updateCurrentUserInfo(params: params, progressHandler: nil) { error in
        guard error == nil else {
            // Handle error.
            return
        }

        var isUpdatedSuccessfully = true

        // The user object below is the reference of the current user.
        if let preferredLanguages = user.preferredLanguages {
            for language in preferredLanguages {
                if !preferredLanguages.contains(language) {  // The user.preferredLanguages returns
                                                             // a list of the current user's preferred languages.
                    isUpdatedSuccessfully = false
                    break
                }
            }
        }

        if isUpdatedSuccessfully == true {
            // The current user's preferred languages have been updated successfully.
        }
    }
}

If successful, the following notification payload will be delivered to the current user's device.

{
    "aps": {
        "alert": "Bonjour comment allez vous",  // A notification is translated into the first language listed in the preferred languages.
    },
    "sendbird": {
        "category": "messaging:offline_notification",
        "type": "User",
        "message": "Hello, how are you?",


        "translations": {   // The translated messages in other preferred languages.
            "fr": "Bonjour comment allez vous",
            "de": "Hallo wie geht es dir",
            "es": "Hola como estas",
            "kr": "안녕하십니까?"
        },
    }
}