Skip to main content

Push Localization

For receiving localized push notification title and body message, there are two different ways.

  1. Server side Localization: Server sends already localized values inside the push notification. While in the case of transactions our app actively fetches the text, transmitting locale information in the request, here, the server just pushes texts to the device without first receiving a request. Thus, it is a bit of a challenge to select the correct locale. To alleviate this issue, the app can store a set of preferred locales on the server side by sending a SetLocales event. Then, the service sending the push message can look up the preferred locales, check which locales it supports and select a corresponding localization. Note however, that this option may still lead to incorrect localization when server side does not know current locale of current smartphone, e.g. when a user has multiple devices with different locales.
  2. App side Localization: Server sends keys inside the push notification that the app needs to translate with its own localized files. This option concentrates all app localization resources at the app side.

We recommend to localize the push notification on app side.

Look here for more information about the push content

Server side Localization

SetLocales event flow-diagram

This diagram shows the internal workings of setting the locales for push functionality.

We recommend to call the SetLocalesEvent after you received the SetPushTokenResultEvent.

iOS/Swift

This shows how to set the locales on the server.

SetLocales

func setLocales() {

//Create event
let localesEvent = KSMSetLocalesEvent(locales: ["de","en"])
MasterControllerAdapter.sharedInstance.sendEvent2MasterController(localesEvent) { event in
guard let statusEvent = event as? KSMStatusResultEvent else {
return
}
}
}

For further documentation you can check the Apple developer documentation. https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html

Android/Kotlin

SetLocales
fun triggerSetLocalesEvent(){
logDebug("setting locales", "triggerSetLocales")
val setLocales = SetLocalesEvent(listOf("de","en"))
mcEventHandler?.postEvent(setLocales)?.then {
logDebug("received Result: $it", "triggerSetLocales")
}
}

App side Localization

To localize the push content you can use the app's normal localization. Therefore the push content contains two keys that contain the key which must be present in your localized file string resources files.

iOS/Swift

Those are the referred keys from which the value is used.

"title-loc-key": "RESOURCE_KEY_PUSH_NOTIFICATION_TITLE",
"loc-key": "RESOURCE_KEY_PUSH_NOTIFICATION_BODY"

For further documentation you can check the Apple developer documentation. https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html

Android/Kotlin

Those are the referred keys from which the value is used.

  1. title-loc-key
  2. message