Sundeep Saluja
Sundeep Saluja

Reputation: 1249

How to handle iOS Push Notifications in Different language

I am working on an app in which, I have implemented Push Notifications. Now I have to give support for Multiple language for Push notifications. Please suggest whether, Localization for push notifications should be on App side or Server side. And How to handle the language of push displayed on Banner when app is not running?

Thanks In Advance

Upvotes: 1

Views: 2740

Answers (2)

Simpa
Simpa

Reputation: 558

This is an old question but it deserves a new answer.

Localized push notifications can be solved either server side or in the app.

To send localized notifications server side requires that the server knows the users language preference and like aronspring suggested, a good time to do that is when registering the push token.

To do it locally on the phone you need to supply all possible notifications and their translations in the app bundle Localizable.strings file. The server would then instead of sending the text to be displayed, send the key to the corresponding translation in Localizable.strings.

Example aps payload:

"aps" : {
    "alert" : {
        "loc-key" : "SOME_MESSAGE"
    }
}

For a better explanation read more here: Local and Remote Notification Programming Guide

Upvotes: 3

aronspring
aronspring

Reputation: 276

Like you've just pointed out, in the scenario when your app is not running the OS will receive the notification and not run any code within your app to translate them, and will display them as they are received. So they will need to be translated server side before being sent. The app shouldn't have to worry about what language they are sent in - no code needs to be written app side for this.

It might be an idea to store the device locale when you register the push token to known what language the device is set to.

Upvotes: 2

Related Questions