Push Localization
For receiving localized push notification titles and body messages, there are two different ways:
- Server side Localization: The 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 simply pushes texts to the device without first receiving a request. Thus, it is challenging 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 the server side does not know the current locale of the current smartphone, e.g., when a user has multiple devices with different locales.
- App side Localization: The 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 on the app side.
We recommend localizing push notifications on the app side.
Look here for more information about push content.
Server side Localization
SetLocales event flow-diagram
This diagram shows the internal workings of setting the locales for push functionality.
We recommend calling the SetLocalesEvent after you receive the SetPushTokenResultEvent.
iOS/Swift
This shows how to set locales on the server.
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
fun triggerSetLocalesEvent(){
val setLocales = SetLocalesEvent(listOf("de","en"))
synchronousEventHandler?.postEvent(setLocales)?.then {
logDebug("received Result: $it", "triggerSetLocales")
}
}
App side Localization
To localize 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 string resource files.
iOS/Swift
These are the referenced keys from which the values are 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
These are the referenced keys from which the values are used:
- title-loc-key
- message