ios - Change language of alert in banner of Push Notification -


i facing problem change language of alert in banner when push comes. working on app works in 2 language. 1 english , second norwegian. push receiving web server end , string has in alert key displayed in banner when push comes , outside of app. requirement want if change language setting english norwegian when push comes it's banner's alert string change norwegian. possible @ end or have change server whenever change language.

any suggestion helpful.

thanks

there 2 ways display localized text in push notification in ios:

localize message in server

in case, must send device language server. code need add ios app similar following:

nsstring *preferredlanguage = [[nslocale preferredlanguages] objectatindex:0]; const char *langstr = [preferredlanguage utf8string]; [self sendcurrentlanguage:langstr]; // method communicates server 

then can send notification message in appropriate language using alert key in notification json payload.

send localization string notification payload

you can send localized string in payload. alert key accepts child loc-key key can use send localized string:

"alert" : {      "loc-key" : "my localized string",     ... } 

and then, in localizable.strings file inside correspondent language identifier, add following:

"my localized string" = "the localized string in language want."; 

if need pass arguments build final localized string, can pass loc-args json array in notification payload, too:

"alert" : {          "loc-key" : "my localized string",         "loc-args" : [ "first argument", "second argument" ],         ...     } 

and, in localizable.strings:

 "my localized string" = "the localized string first argument %@, , second argument %@." 

or, if need change positions:

 "my localized string" = "the localized string second argument %2$@, , first argument %1$@."; 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -